Skip to content

Commit ab90c82

Browse files
authored
Make ignoring relative paths possible (#78)
1 parent 83ecfcc commit ab90c82

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

src/docstub/_path_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ def _walk_source_package(path, *, ignore_regex):
212212
source_path : Path
213213
Either a Python file or a stub file that takes precedence.
214214
"""
215-
if ignore_regex and ignore_regex.match(str(path)):
215+
# Make sure
216+
if ignore_regex and ignore_regex.match(str(path.resolve())):
216217
logger.info("ignoring %s", path)
217218
return
218219

tests/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
7+
@pytest.fixture
8+
def tmp_path_cwd(tmp_path):
9+
"""Fixture: Create temporary directory and use it as working directory.
10+
11+
.. warning::
12+
Not written with parallelization in mind!
13+
"""
14+
previous_cwd = Path.cwd()
15+
os.chdir(tmp_path)
16+
try:
17+
yield tmp_path
18+
except:
19+
os.chdir(previous_cwd)
20+
raise

tests/test_cli.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Test command line interface."""
22

33
import logging
4-
import os
54
from pathlib import Path
65

76
import pytest
@@ -13,22 +12,6 @@
1312
PROJECT_ROOT = Path(__file__).parent.parent
1413

1514

16-
@pytest.fixture
17-
def tmp_path_cwd(tmp_path):
18-
"""Fixture: Create temporary directory and use it as working directory.
19-
20-
.. warning::
21-
Not written with parallelization in mind!
22-
"""
23-
previous_cwd = Path.cwd()
24-
os.chdir(tmp_path)
25-
try:
26-
yield tmp_path
27-
except:
28-
os.chdir(previous_cwd)
29-
raise
30-
31-
3215
class Test_run:
3316
def test_no_cache(self, tmp_path_cwd, caplog):
3417
caplog.set_level(logging.INFO)

tests/test_path_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
import pytest
24

35
from docstub._path_utils import STUB_HEADER_COMMENT, walk_source_package
@@ -122,3 +124,18 @@ def test_ignore(self, tmp_path):
122124

123125
paths = sorted(walk_source_package(tmp_path, ignore=["**/*init*"]))
124126
assert paths == [stub_in_sub_package]
127+
128+
def test_ignore_relative_path(self, tmp_path_cwd):
129+
init = tmp_path_cwd / "__init__.py"
130+
init.touch()
131+
tests_dir = tmp_path_cwd / "tests"
132+
tests_dir.mkdir()
133+
sub_init = tests_dir / "__init__.py"
134+
sub_init.touch()
135+
136+
relative_cwd = Path()
137+
138+
paths = sorted(walk_source_package(relative_cwd))
139+
assert [p.resolve() for p in paths] == [init, sub_init]
140+
paths = sorted(walk_source_package(relative_cwd, ignore=["**/tests"]))
141+
assert [p.resolve() for p in paths] == [init]

0 commit comments

Comments
 (0)