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

Support imports of namespaces in python>=3.3 (modules without __init__.py files) #842

Closed
mishas opened this issue Mar 9, 2016 · 19 comments
Assignees
Labels
Blocker 🙅 Blocks the next release

Comments

@mishas
Copy link

mishas commented Mar 9, 2016

Python 3.3 introduced "Implicit Namespace Packages" (based on PEP-420), which states the following:
"Native support for package directories that don’t require __init__.py marker files [...]".

In other words, if I have the following file structure (without any __init__.py files whatsoever):

foo/
    bar/
        baz.py
blah.py

And the content of blah.py is from foo.bar import baz; print(baz), then python3.5 ./blah.py will successfully output: <module 'foo.bar.baz' from '/tmp/foo/bar/baz.py'>.

The problem is, that pylint ./blah.py outputs:
E: 1, 0: Unable to import 'foo.bar' (import-error)

I tried to manipulate sys.path (from init-hook of my .pylintrc) in any which way, and nothing seemed to help except for adding the __init__.py files everywhere :(.

@PCManticore
Copy link
Contributor

Agree that this would be nice to have, but not sure when this will happen.

@PCManticore PCManticore added the Minor 💅 Polishing pylint is always nice label Mar 21, 2016
@srikanth-viswanathan
Copy link

This would be great to have. Is this just a minor enhancement? Out of curiosity, where would the change have to be made?

@kstrauser
Copy link

For my organization, it's not minor but a real showstopper. We use lots of namespace packages and are moving to the new implicit namespace package layout, so we can't use pylint in the mean time. Is this something a motivated would-be contributor with no prior pylint experience could reasonably fix?

@moylop260
Copy link
Contributor

@kstrauser
I had a similar issue with import check but I can use pylint with pylint... --disable=import-error
FYI You can try it to use pylint with other checks that works but disabling the checks that don't work for you

@kstrauser
Copy link

@moylop260 But I use import errors. :-/ I've temporarily switched to flake8 but I'd much prefer pylint on the CI server.

@moylop260
Copy link
Contributor

Flake8 don't have import-error is the same if you use pylint disabling it
But is a good choice too!

@moylop260
Copy link
Contributor

moylop260 commented Apr 20, 2016

A big problem with use import-error in the CI is that many times you need a speed-up result of lint checks, but for this check (and just this check) you will need install all depends, then could be slower the result of this build.

@PCManticore
Copy link
Contributor

@kstrauser, this would probably be a bit difficult, since it will require modifications through astroid as well (the inference engine of Pylint). But if you want to tackle it, I can help you with the details.

@kstrauser
Copy link

@PCManticore Thanks, after looking at it that might be outside my current resource availability. I'm going to keep that in mind as a possibility, though.

@PCManticore PCManticore self-assigned this May 4, 2016
@PCManticore PCManticore added Blocker 🙅 Blocks the next release and removed Minor 💅 Polishing pylint is always nice labels May 4, 2016
@PCManticore
Copy link
Contributor

Let's fix this before the next release. I'm assigning to me for now, but if anyone wants to chime in and help, I wouldn't mind.

@PCManticore
Copy link
Contributor

PCManticore commented May 8, 2016

For the record, I started implementing this feature. It's pretty much work in progress, but you can check these two branches https://github.com/PyCQA/pylint/commits/namespace_package and https://github.com/PyCQA/astroid/commits/namespace_package. It doesn't support Python 3.3 though, it is a bit cumbersome to support it, but if someone needs it, say it now.

@PCManticore
Copy link
Contributor

This should be fixed, you'll need the pylint's and astroid's master branch if you want to test. Please give it a go and let me know if you have problems with it.

@moylop260
Copy link
Contributor

@PCManticore
FYI the build is red of the change 38a56db
IMHO we should avoid use push directly without a pull request

@cblegare
Copy link

cblegare commented Aug 2, 2016

This is closed but I don't think it was merged. Any news ?

@PCManticore
Copy link
Contributor

This is available in the master branch. It will be released though in a
couple of months, since we have some more work to do. You can check the
milestone page to see what's blocking us so far.

On Aug 2, 2016 8:06 PM, "abstrus" [email protected] wrote:

This is closed but I don't think it was merged. Any news ?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@janosh
Copy link

janosh commented Jan 20, 2019

This is available in the master branch. It will be released though in a couple of months, ...

I'm still having this problem? Was the release ever published?

@PCManticore
Copy link
Contributor

This was already released @janosh but there might be some bugs lurking around. Please open a new issue with some reproduction examples.

@janosh
Copy link

janosh commented Jan 26, 2019

Never mind, I was specifying the imports from the wrong starting point, i.e. from package import module rather than from src.package import module. Working now.

@webknjaz
Copy link
Contributor

FTR this error pops up for me with the latest pylint under Python 3.7 but occasionally: only in Travis CI and GitHub Actions CI/CD. No errors locally. I've been trying to figure out the difference between envs but still no luck...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker 🙅 Blocks the next release
Projects
None yet
Development

No branches or pull requests

8 participants