Skip to content

Commit

Permalink
fix(dependency_getter): handle strings for setuptools dynamic depen…
Browse files Browse the repository at this point in the history
…dencies
  • Loading branch information
mkniewallner committed Nov 15, 2024
1 parent 40765df commit 88965d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
13 changes: 9 additions & 4 deletions python/deptry/dependency_getter/pep621/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ def _get_dependencies(self) -> list[Dependency]:
if self._project_uses_setuptools(pyproject_data) and "dependencies" in pyproject_data["project"].get(
"dynamic", {}
):
return get_dependencies_from_requirements_files(
pyproject_data["tool"]["setuptools"]["dynamic"]["dependencies"]["file"], self.package_module_name_map
)
dependencies_files = pyproject_data["tool"]["setuptools"]["dynamic"]["dependencies"]["file"]
if isinstance(dependencies_files, str):
dependencies_files = [dependencies_files]

Check warning on line 69 in python/deptry/dependency_getter/pep621/base.py

View check run for this annotation

Codecov / codecov/patch

python/deptry/dependency_getter/pep621/base.py#L69

Added line #L69 was not covered by tests

return get_dependencies_from_requirements_files(dependencies_files, self.package_module_name_map)

dependency_strings: list[str] = pyproject_data["project"].get("dependencies", [])
return self._extract_pep_508_dependencies(dependency_strings)
Expand All @@ -79,7 +81,10 @@ def _get_optional_dependencies(self) -> dict[str, list[Dependency]]:
"dynamic", {}
):
return {
group: get_dependencies_from_requirements_files(specification["file"], self.package_module_name_map)
group: get_dependencies_from_requirements_files(
[specification["file"]] if isinstance(specification["file"], str) else specification["file"],
self.package_module_name_map,
)
for group, specification in pyproject_data["tool"]["setuptools"]["dynamic"]
.get("optional-dependencies", {})
.items()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ dynamic = ["dependencies", "optional-dependencies"]
dependencies = { file = ["requirements.txt", "requirements-2.txt"] }

[tool.setuptools.dynamic.optional-dependencies]
cli = { file = ["cli-requirements.txt"] }
# Both strings and list of strings are accepted.
cli = { file = "cli-requirements.txt" }
dev = { file = ["dev-requirements.txt"] }

[tool.deptry]
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/dependency_getter/test_pep_621.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ def test_dependency_getter_with_setuptools_dynamic_dependencies_with_another_bui
dependencies = { file = ["requirements.txt", "requirements-2.txt"] }
[tool.setuptools.dynamic.optional-dependencies]
cli = { file = ["cli-requirements.txt"] }
# Both strings and list of strings are accepted.
cli = { file = "cli-requirements.txt" }
dev = { file = ["dev-requirements.txt"] }
"""

Expand Down

0 comments on commit 88965d5

Please sign in to comment.