-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add support for namespace-packages without __init__.py (PEP420) #96
Comments
Just found the relevant issue in the project that is used for the module-graph generation: seddonym/grimp#80 |
Thanks Jonathan - as mentioned on the issue you've linked to, I see this as low priority as it's quite difficult to fix. Would welcome insight as to what you find useful about namespace packages - to me it feels like an edge case that won't bring much benefit to most users, but happy to be proved wrong! |
Simply put, there's not much value in empty |
Interesting - this surprises me! But you may have a point. My understanding of namespace packages is that they are focused specifically on "splitting a single Python package across multiple directories on disk" (from the PEP). I'm not aware of an intention to drop them except for this use case. I think it's possible that they're not really intended to be optional in regular Python packages. It's possible, for example, that not including them might have performance implications - but I don't know enough about it. I wasn't able to see anything that addressed that in the Mypy link you directed me too, but do direct me to any other discussion on the subject if you come across it. |
Exactly, that's the original motivation. However, it means that also for a single package in a single directory, one can simply omit the
It does not matter, that this was not the intended usage of the PEP, but since empty A comment from the linked thread that resonates with this (python/mypy#1645 (comment)):
From a similar thread (python/mypy#8584 (comment)):
|
PS:
Same for me! Performance implications on import speed aren't what I care about usually. But this consideration shouldn't prevent one from using static analysis tools, such as import-linter. |
Thanks for your input, it's challenging my thinking! I'll have another look at how hard this would be to do in import-linter. And of course always open to pull requests! |
We also use namespace packages. We have separate distribution packages using common root package. Another benefit: While developing cold we would use pip install -e . to install it in editable form and thus companyname.hot would be from local folder while companyname.cool would be from site-packages of python. Without namespace packages only one would be found. import-linter looked really promising for us but we need namespace packages so we cannot use it. |
For anyone in the use-case "I just don't use the file in py3" and not in the use-case "I specifically need to namespace things differently", I run this command before linting to pre-populate anything missing (but do not commit it). A bit of a hack but it solves 50% of the use-cases I'm aware of.
If you have some time to fork a bit, I found you can also just directly add the implied ancestors to the grimp use-case (for example, in If you really really want to do fancy namespace things I don't have advice for your use-case. I assume 90% of python devs just want to make a folder without an empty init file. |
I'm pleased to say there is now a PR in place which offers support for namespace packages: #127 @tozka This should now meet your needs. @jstriebel, I have a feeling this won't exactly fulfil your needs I'm afraid but you might want to take a look just in case. Comments and testing welcome. |
I'm going to close this ticket as Import Linter now supports namespace packages. |
In Python 3 modules don't require an
__init__.py
anymore, they are referred to as namespace packages then (see PEP 420 for details). It seems that those are not supported by import-linter at the moment, I'm gettingCould not find package.initless.module when scanning …. This may be due to a missing __init__.py file in the parent package
warnings andModule 'package.initless' does not exist.
errors. In my case the structure is roughly:It would be great if this could be supported.
The text was updated successfully, but these errors were encountered: