Skip to content

Commit 189cd4e

Browse files
committed
InstalledPackageResolver: Note when a package provides no import names
Add a debug-level warning when neither _top_level_declared() nor _top_level_inferred() is unable to find any provided import names in a package. This _might_ be a symptom of a weird Python environment with missing metadata (like @layus is currently experiencing with Bazel's rules_python rule set: In the directory structure that rules_python makes available to build steps that depend on a Python package, the necessary metadata files (RECORD or top-level.txt) needed by importlib_metadata in order to determine a package's import names are not included. However, this situation might(?) also happen with any package that provides executable tools rather than importable modules (think e.g. uv, ruff, or similar). Hence we leave this as a debug-level message for now: We don't want a scary warning for something that might be legitimate, but a debug-level message can still be found by a user that is e.g. debugging a case where a declared dependency is reported as both undeclared and unused.
1 parent 3b59731 commit 189cd4e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fawltydeps/packages.py

+8
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ def _from_one_env(
260260
_top_level_declared(dist) # type: ignore[no-untyped-call]
261261
or _top_level_inferred(dist) # type: ignore[no-untyped-call]
262262
)
263+
if not imports:
264+
# We have found an installed package that provides zero import
265+
# names. This might be a legitimate tool/application that is
266+
# installed into the Python environment without providing any
267+
# importable modules, but it might also be a symptom of broken/
268+
# incomplete package metadata causing importlib_metadata to not
269+
# find any provided import names.
270+
logger.debug(" This module does not provide any import names!")
263271
yield {dist.name: imports}, str(parent_dir)
264272

265273
@cached_property

0 commit comments

Comments
 (0)