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

Namespace packages #22

Open
smurfix opened this issue Sep 7, 2022 · 1 comment
Open

Namespace packages #22

smurfix opened this issue Sep 7, 2022 · 1 comment

Comments

@smurfix
Copy link

smurfix commented Sep 7, 2022

I'm trying to use findimports with namespace packages (i.e. those which don't have an __init__ in their directory tree) and I'm running into some issues.

First, the directory structure:

$ tree
.
├── Makefile
├── moat
│   └── main
│       └── __init__.py
├── README.md
├── setup.cfg
└── setup.py

There's a ../util directory alongside this one which has much the same structure:

 tree ../util
../util
├── Makefile
├── moat
│   └── util
│       ├── __init__.py
│       ├── times.py
│       └── _yaml.py
├── README.rst
├── setup.cfg
└── setup.py

OK. So when I run findimports on this, I get

$ PYTHONPATH=.:../util/ findimports --ignore-stdlib 
main.__init__:
  anyio
  asyncclick
  util
setup:
  setuptools

Now this is obviously suboptimal, as there's no "util" package and the toplevel isn't "main" either. I have to do

  • touch moat.__init__.py
  • touch ../util/moat/__init__.py

to get a more reasonable output of

moat.__init__:
  
moat.main.__init__:
  anyio
  asyncclick
  moat.util
setup:
  setuptools

To fix the requirement for the first touch statement I would like an option that tells findimports that it should assume that every dictionary it finds (or that's named on the command line) might be the root of a namespace package. This way the src/whatever style of laying out your source repository would still work unchanged.

Imported modules should be recognized no matter whether they're part of a namespace, i.e. the second touch should not be necessary even if I don't use that special new option.

@mgedmin
Copy link
Owner

mgedmin commented Sep 9, 2022

Yes, currently findimports has no support for PEP 420 implicit namespace packages.

I don't know when (or if) I can find the desire/energy to work on this. Help (in the form of a pull request) would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants