Skip to content

Commit

Permalink
merged main into feature branch
Browse files Browse the repository at this point in the history
  • Loading branch information
fpgmaas committed May 9, 2023
2 parents 22ff270 + 54cb1c3 commit 933a696
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion deptry/imports/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def get_imported_modules_for_list_of_files(list_of_files: list[Path]) -> dict[str, list[Location]]:
logging.info(f"Scanning {len(list_of_files)} files...")
logging.info(f"Scanning {len(list_of_files)} file{'s' if len(list_of_files)>1 else ''}...")

modules: dict[str, list[Location]] = defaultdict(list)

Expand Down
2 changes: 1 addition & 1 deletion deptry/issues_finder/misplaced_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def find(self) -> list[Violation]:
def _is_development_dependency(self, module: Module, corresponding_package_name: str) -> bool:
# Module can be provided both by a regular and by a development dependency.
# Only continue if module is ONLY provided by a dev dependency.
if not module.is_dev_dependency or module.is_dependency:
if not module.is_provided_by_dev_dependency or module.is_provided_by_dependency:
return False

if module.name in self.ignored_modules:
Expand Down
9 changes: 8 additions & 1 deletion deptry/issues_finder/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ def find(self) -> list[Violation]:
return missing_dependencies

def _is_missing(self, module: Module) -> bool:
if any([module.package is not None, module.is_dependency, module.is_dev_dependency, module.local_module]):
if any(
[
module.package is not None,
module.is_provided_by_dependency,
module.is_provided_by_dev_dependency,
module.local_module,
]
):
return False

if module.name in self.ignored_modules:
Expand Down
9 changes: 8 additions & 1 deletion deptry/issues_finder/transitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ def find(self) -> list[Violation]:
return transitive_dependencies

def _is_transitive(self, module: Module) -> bool:
if any([module.package is None, module.is_dependency, module.is_dev_dependency, module.local_module]):
if any(
[
module.package is None,
module.is_provided_by_dependency,
module.is_provided_by_dev_dependency,
module.local_module,
]
):
return False

if module.name in self.ignored_modules:
Expand Down
23 changes: 12 additions & 11 deletions deptry/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ class Module:
local_module: Whether the module is a local module.
package: The name of the package that contains the module.
top_levels: A list of dependencies that contain this module in their top-level module
names.
names. This can be multiple, e.g. `google-cloud-api` and `google-cloud-bigquery` both have
`google` in their top-level module names.
dev_top_levels: A list of development dependencies that contain this module in their
top-level module names.
is_dependency: Whether the module is provided by a listed dependency.
is_dev_dependency: Whether the module is provided by a listed development dependency.
top-level module names. Can be multiple, similar to the attribute `top_levels`.
is_provided_by_dependency: Whether the module is provided by a listed dependency.
is_provided_by_dev_dependency: Whether the module is provided by a listed development dependency.
"""

name: str
Expand All @@ -34,8 +35,8 @@ class Module:
package: str | None = None
top_levels: list[str] | None = None
dev_top_levels: list[str] | None = None
is_dependency: bool | None = None
is_dev_dependency: bool | None = None
is_provided_by_dependency: bool | None = None
is_provided_by_dev_dependency: bool | None = None

def __post_init__(self) -> None:
self._log()
Expand Down Expand Up @@ -75,7 +76,7 @@ def __init__(
local_modules: The list of local modules
stdlib_modules: The list of Python stdlib modules
dependencies: A list of the project's dependencies
dev-dependencies: A list of the project's development dependencies
dev_dependencies: A list of the project's development dependencies
"""
self.name = name
self.local_modules = local_modules
Expand All @@ -99,15 +100,15 @@ def build(self) -> Module:
top_levels = self._get_corresponding_top_levels_from(self.dependencies)
dev_top_levels = self._get_corresponding_top_levels_from(self.dev_dependencies)

is_dependency = self._has_matching_dependency(package, top_levels)
is_dev_dependency = self._has_matching_dev_dependency(package, dev_top_levels)
is_provided_by_dependency = self._has_matching_dependency(package, top_levels)
is_provided_by_dev_dependency = self._has_matching_dev_dependency(package, dev_top_levels)
return Module(
self.name,
package=package,
top_levels=top_levels,
dev_top_levels=dev_top_levels,
is_dependency=is_dependency,
is_dev_dependency=is_dev_dependency,
is_provided_by_dependency=is_provided_by_dependency,
is_provided_by_dev_dependency=is_provided_by_dev_dependency,
)

def _get_package_name_from_metadata(self) -> str | None:
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/issues_finder/test_misplaced_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_simple() -> None:
dependencies = [Dependency("bar", Path("pyproject.toml"))]

module_foo_locations = [Location(Path("foo.py"), 1, 2), Location(Path("bar.py"), 3, 4)]
module_foo = Module("foo", dev_top_levels=["foo"], is_dev_dependency=True)
module_foo = Module("foo", dev_top_levels=["foo"], is_provided_by_dev_dependency=True)

modules_locations = [ModuleLocations(module_foo, module_foo_locations)]

Expand All @@ -31,7 +31,9 @@ def test_regular_and_dev_dependency() -> None:
dependencies = [Dependency("foo", Path("pyproject.toml"))]

module_foo_locations = [Location(Path("foo.py"), 1, 2)]
module_foo = Module("foo", dev_top_levels=["foo"], is_dev_dependency=True, is_dependency=True)
module_foo = Module(
"foo", dev_top_levels=["foo"], is_provided_by_dev_dependency=True, is_provided_by_dependency=True
)

modules_locations = [ModuleLocations(module_foo, module_foo_locations)]

Expand Down

0 comments on commit 933a696

Please sign in to comment.