Skip to content

Commit ab29a55

Browse files
committed
Make find_imported_modules take a list of Path, not str
1 parent e77c608 commit ab29a55

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

pip_check_reqs/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ def pyfiles(root: Path) -> Generator[str, None, None]:
136136

137137

138138
def find_imported_modules(
139-
paths: Iterable[str],
139+
paths: Iterable[Path],
140140
ignore_files_function: Callable[[str], bool],
141141
ignore_modules_function: Callable[[str], bool],
142142
) -> Dict[str, FoundModule]:
143143
vis = _ImportVisitor(ignore_modules_function=ignore_modules_function)
144144
for path in paths:
145-
for filename in pyfiles(Path(path)):
145+
for filename in pyfiles(path):
146146
if ignore_files_function(filename):
147147
log.info("ignoring: %s", os.path.relpath(filename))
148148
continue

pip_check_reqs/find_extra_reqs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import importlib.metadata
66
import logging
77
import os
8-
import pathlib
98
import sys
9+
from pathlib import Path
1010
from typing import Callable, Iterable, List, Optional, Union
1111

1212
from packaging.utils import canonicalize_name
@@ -21,7 +21,7 @@
2121

2222
def find_extra_reqs(
2323
requirements_filename: str,
24-
paths: Iterable[str],
24+
paths: Iterable[Path],
2525
ignore_files_function: Callable[[str], bool],
2626
ignore_modules_function: Callable[[str], bool],
2727
ignore_requirements_function: Callable[
@@ -48,8 +48,8 @@ def find_extra_reqs(
4848
package_location = package.location
4949
package_files = []
5050
for item in package.files or []:
51-
here = pathlib.Path(".").resolve()
52-
item_location_rel = pathlib.Path(package_location) / item
51+
here = Path(".").resolve()
52+
item_location_rel = Path(package_location) / item
5353
item_location = item_location_rel.resolve()
5454
try:
5555
relative_item_location = item_location.relative_to(here)
@@ -109,7 +109,7 @@ def main(arguments: Optional[List[str]] = None) -> None:
109109
"""Main entry point."""
110110
usage = "usage: %prog [options] files or directories"
111111
parser = argparse.ArgumentParser(usage)
112-
parser.add_argument("paths", nargs="*")
112+
parser.add_argument("paths", type=Path, nargs="*")
113113
parser.add_argument(
114114
"--requirements-file",
115115
dest="requirements_filename",

pip_check_reqs/find_missing_reqs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import importlib.metadata
66
import logging
77
import os
8-
import pathlib
98
import sys
9+
from pathlib import Path
1010
from typing import Callable, Iterable, List, Optional, Tuple
1111

1212
from packaging.utils import NormalizedName, canonicalize_name
@@ -23,7 +23,7 @@
2323

2424
def find_missing_reqs(
2525
requirements_filename: str,
26-
paths: Iterable[str],
26+
paths: Iterable[Path],
2727
ignore_files_function: Callable[[str], bool],
2828
ignore_modules_function: Callable[[str], bool],
2929
) -> List[Tuple[NormalizedName, List[FoundModule]]]:
@@ -46,8 +46,8 @@ def find_missing_reqs(
4646
package_location = package.location
4747
package_files = []
4848
for item in package.files or []:
49-
here = pathlib.Path(".").resolve()
50-
item_location_rel = pathlib.Path(package_location) / item
49+
here = Path(".").resolve()
50+
item_location_rel = Path(package_location) / item
5151
item_location = item_location_rel.resolve()
5252
try:
5353
relative_item_location = item_location.relative_to(here)
@@ -113,7 +113,7 @@ def find_missing_reqs(
113113
def main(arguments: Optional[List[str]] = None) -> None:
114114
usage = "usage: %prog [options] files or directories"
115115
parser = argparse.ArgumentParser(usage)
116-
parser.add_argument("paths", nargs="*")
116+
parser.add_argument("paths", type=Path, nargs="*")
117117
parser.add_argument(
118118
"--requirements-file",
119119
dest="requirements_filename",

tests/test_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def ignore_mods(module: str) -> bool:
156156
return False
157157

158158
result = common.find_imported_modules(
159-
paths=[str(root)],
159+
paths=[root],
160160
ignore_files_function=ignore_files,
161161
ignore_modules_function=ignore_mods,
162162
)
@@ -241,7 +241,7 @@ def mocked_open(*args: Any, **kwargs: Any) -> Any:
241241

242242
monkeypatch.setattr(builtins, "open", mocked_open)
243243
common.find_imported_modules(
244-
paths=[str(tmp_path)],
244+
paths=[tmp_path],
245245
ignore_files_function=common.ignorer(ignore_cfg=[]),
246246
ignore_modules_function=common.ignorer(ignore_cfg=[]),
247247
)

tests/test_find_extra_reqs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_find_extra_reqs(tmp_path: Path) -> None:
4343

4444
result = find_extra_reqs.find_extra_reqs(
4545
requirements_filename=str(fake_requirements_file),
46-
paths=[str(source_dir)],
46+
paths=[source_dir],
4747
ignore_files_function=common.ignorer(ignore_cfg=[]),
4848
ignore_modules_function=common.ignorer(ignore_cfg=[]),
4949
ignore_requirements_function=common.ignorer(ignore_cfg=[]),

tests/test_find_missing_reqs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_find_missing_reqs(tmp_path: Path) -> None:
4444

4545
result = find_missing_reqs.find_missing_reqs(
4646
requirements_filename=str(fake_requirements_file),
47-
paths=[str(source_dir)],
47+
paths=[source_dir],
4848
ignore_files_function=common.ignorer(ignore_cfg=[]),
4949
ignore_modules_function=common.ignorer(ignore_cfg=[]),
5050
)

0 commit comments

Comments
 (0)