fpgmaas / deptry

Find unused, missing and transitive dependencies in a Python project.
https://deptry.com/
MIT License
800 stars 15 forks source link

PEP420 namespaces aren't recognized #740

Open charlesnicholson opened 2 weeks ago

charlesnicholson commented 2 weeks ago

In our Python ecosystem, we use PEP420 namespace packages to prefix all of our packages with companyname to avoid package name collisions with third-party packages. For example, our directory structures might look like:

src/
  company.foo/
    company/
      foo/
        foo.py
    pyproject.toml

The pyproject.toml file is pretty vanilla:

[project]
name = "company.foo"
version = "0.0.1"
dependencies = [ ... ]

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

When running deptry . from the terminal with the current working directory set to src/company.foo, I get this error:

Assuming the corresponding module name of package 'company' is 'company'. Install the package or configure a package_module_name_map entry to override this behaviour.

This warning makes it seem like deptry can't understand these kinds of packages yet, since the package names aren't ambiguous and are, as best I can tell, conforming to https://peps.python.org/pep-0420/#nested-namespace-packages.

OS: macOS Sonoma 14.5 Language Version: Python 3.11 Poetry version: we don't use poetry. (We use python and uv, but uv plays no role in our package source layouts).

Thanks for deptry! Hopefully it will help us stop shipping broken wheel sets... :-|

mkniewallner commented 4 days ago

This should be fixed in 0.16.2, if you want to check.

charlesnicholson commented 3 days ago

Thanks for looking into it! It still seems to be happening, unfortunately. I threw together a minimal reproduction in a public repo that you can clone and investigate, if you have the appetite for it:

https://github.com/charlesnicholson/deptry-pep420-repro

Also note the commented-out line in the repro.sh, is it possible that the ROOT argument isn't working as expected? Apologies if I'm misunderstanding the intended usage.

mkniewallner commented 3 days ago

Thanks for taking the time to create a reproduction repository, really appreciate it!

I won't be able to take a look right away, but will be during the weekend. In the meantime, I'll re-open the issue as it is not yet fixed.

charlesnicholson commented 3 days ago

Happy to! I set up a manual CI trigger for it, you can see it happening on ubuntu-latest here:

https://github.com/charlesnicholson/deptry-pep420-repro/actions/runs/9810619739/job/27091137978

Screenshot 2024-07-05 at 11 35 51 AM