Skip to content

Commit c4dd28e

Browse files
Merge pull request #135 from r1chardj0n3s/kword-only
Use/require keyword arguments in more function calls
2 parents 6b680fb + ed6cdcf commit c4dd28e

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

pip_check_reqs/common.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, ignore_modules_function: Callable[[str], bool]) -> None:
4747
self._modules: dict[str, FoundModule] = {}
4848
self._location: str | None = None
4949

50-
def set_location(self, location: str) -> None:
50+
def set_location(self, *, location: str) -> None:
5151
self._location = location
5252

5353
# Ignore the name error as we are overriding the method.
@@ -121,6 +121,7 @@ def pyfiles(root: Path) -> Generator[Path, None, None]:
121121

122122

123123
def find_imported_modules(
124+
*,
124125
paths: Iterable[Path],
125126
ignore_files_function: Callable[[str], bool],
126127
ignore_modules_function: Callable[[str], bool],
@@ -133,7 +134,7 @@ def find_imported_modules(
133134
continue
134135
log.debug("scanning: %s", os.path.relpath(filename))
135136
content = filename.read_text(encoding="utf-8")
136-
vis.set_location(str(filename))
137+
vis.set_location(location=str(filename))
137138
vis.visit(ast.parse(content, str(filename)))
138139
return vis.finalise()
139140

@@ -163,7 +164,7 @@ def find_required_modules(
163164

164165
if skip_incompatible:
165166
requirement_string = requirement.requirement
166-
if not has_compatible_markers(requirement_string):
167+
if not has_compatible_markers(full_requirement=requirement_string):
167168
log.debug(
168169
"ignoring requirement (incompatible environment "
169170
"marker): %s",
@@ -177,7 +178,7 @@ def find_required_modules(
177178
return explicit
178179

179180

180-
def has_compatible_markers(full_requirement: str) -> bool:
181+
def has_compatible_markers(*, full_requirement: str) -> bool:
181182
if ";" not in full_requirement:
182183
return True # No environment marker.
183184

@@ -188,7 +189,7 @@ def has_compatible_markers(full_requirement: str) -> bool:
188189
return Marker(enviroment_marker).evaluate()
189190

190191

191-
def is_package_file(path: str) -> str:
192+
def is_package_file(*, path: str) -> str:
192193
"""Determine whether the path points to a Python package sentinel file.
193194
194195
A sentinel file is the __init__.py or its compiled variants.
@@ -199,7 +200,7 @@ def is_package_file(path: str) -> str:
199200
return ""
200201

201202

202-
def ignorer(ignore_cfg: list[str]) -> Callable[..., bool]:
203+
def ignorer(*, ignore_cfg: list[str]) -> Callable[..., bool]:
203204
if not ignore_cfg:
204205
return lambda _: False
205206

pip_check_reqs/find_extra_reqs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def find_extra_reqs(
8383
Path(package_location) / package_file,
8484
)
8585
installed_files[path] = package_name
86-
package_path = common.is_package_file(path)
86+
package_path = common.is_package_file(path=path)
8787
if package_path:
8888
# we've seen a package file so add the bare package directory
8989
# to the installed list as well as we might want to look up
@@ -200,9 +200,9 @@ def main(arguments: list[str] | None = None) -> None:
200200
if not parse_result.paths:
201201
parser.error("no source files or directories specified")
202202

203-
ignore_files = common.ignorer(parse_result.ignore_files)
204-
ignore_mods = common.ignorer(parse_result.ignore_mods)
205-
ignore_reqs = common.ignorer(parse_result.ignore_reqs)
203+
ignore_files = common.ignorer(ignore_cfg=parse_result.ignore_files)
204+
ignore_mods = common.ignorer(ignore_cfg=parse_result.ignore_mods)
205+
ignore_reqs = common.ignorer(ignore_cfg=parse_result.ignore_reqs)
206206

207207
logging.basicConfig(format="%(message)s")
208208
if parse_result.debug:

pip_check_reqs/find_missing_reqs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def find_missing_reqs(
7777
str(Path(package_location) / package_file),
7878
)
7979
installed_files[path] = package_name
80-
package_path = common.is_package_file(path)
80+
package_path = common.is_package_file(path=path)
8181
if package_path:
8282
# we've seen a package file so add the bare package directory
8383
# to the installed list as well as we might want to look up
@@ -183,8 +183,8 @@ def main(arguments: list[str] | None = None) -> None:
183183
if not parse_result.paths:
184184
parser.error("no source files or directories specified")
185185

186-
ignore_files = common.ignorer(parse_result.ignore_files)
187-
ignore_mods = common.ignorer(parse_result.ignore_mods)
186+
ignore_files = common.ignorer(ignore_cfg=parse_result.ignore_files)
187+
ignore_mods = common.ignorer(ignore_cfg=parse_result.ignore_mods)
188188

189189
logging.basicConfig(format="%(message)s")
190190
if parse_result.debug:

tests/test_common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
],
2929
)
3030
def test_is_package_file(path: str, result: str) -> None:
31-
assert common.is_package_file(path) == result
31+
assert common.is_package_file(path=path) == result
3232

3333

3434
def test_found_module() -> None:
35-
found_module = common.FoundModule("spam", "ham")
35+
found_module = common.FoundModule(modname="spam", filename="ham")
3636
assert found_module.modname == "spam"
3737
assert found_module.filename == str(Path("ham").resolve())
3838
assert not found_module.locations
@@ -56,7 +56,7 @@ def test_import_visitor(stmt: str, result: list[str]) -> None:
5656
vis = common._ImportVisitor( # noqa: SLF001,E501, pylint: disable=protected-access
5757
ignore_modules_function=common.ignorer(ignore_cfg=[]),
5858
)
59-
vis.set_location("spam.py")
59+
vis.set_location(location="spam.py")
6060
vis.visit(ast.parse(stmt))
6161
finalise_result = vis.finalise()
6262
assert set(finalise_result.keys()) == set(result)
@@ -204,7 +204,7 @@ def test_ignorer(
204204
result: bool,
205205
) -> None:
206206
monkeypatch.setattr(os.path, "relpath", lambda s: s.lstrip("/"))
207-
ignorer = common.ignorer(ignore_cfg)
207+
ignorer = common.ignorer(ignore_cfg=ignore_cfg)
208208
assert ignorer(candidate) == result
209209

210210

0 commit comments

Comments
 (0)