Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the problem that transitive been reported as missing #989

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ classifiers = [
"License :: OSI Approved :: MIT License",
]
dependencies = [
"beautifulsoup4>=4.12.3",
"click>=8.0.0,<9",
"colorama>=0.4.6; sys_platform == 'win32'",
"packaging>=23.2",
Expand Down
9 changes: 9 additions & 0 deletions python/deptry/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dataclasses import dataclass, field
from importlib.metadata import PackageNotFoundError, metadata
from typing import TYPE_CHECKING
import importlib

if TYPE_CHECKING:
from deptry.dependency import Dependency
Expand Down Expand Up @@ -118,10 +119,18 @@ def _get_package_name_from_metadata(self) -> str | None:
try:
name: str = metadata(self.name)["Name"]
except PackageNotFoundError:
name = self.is_package_installed(self.name)
if name:
return name
return None
else:
return name

def is_package_installed(self, package_name: str):
if importlib.util.find_spec(package_name):
return package_name
return None

def _get_corresponding_top_levels_from(self, dependencies: list[Dependency]) -> list[str]:
"""
Not all modules have associated metadata. e.g. `mpl_toolkits` from `matplotlib` has no metadata. However, it is
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_top_level() -> None:
dependency = Dependency("beautifulsoup4", Path("pyproject.toml"))
dependency.top_levels = {"bs4"}
module = ModuleBuilder("bs4", {"foo", "bar"}, frozenset(), [dependency]).build()
assert module.package is None
assert module.package == 'bs4'
assert module.standard_library is False
assert module.local_module is False

Expand Down
37 changes: 37 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.