-
-
Notifications
You must be signed in to change notification settings - Fork 508
-
-
Notifications
You must be signed in to change notification settings - Fork 508
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 are not supported #122
Comments
Seriously, I have absolutely no idea what your namespace packages are. stackoverflow doesn't help me and the PEP which describes this, has been rejected: http://www.python.org/dev/peps/pep-0382/. You (or someone else) really have to help me out here.
Well, there's a pull request with exactly that idea: #109 It is my intent to get rid of I have just finished writing large parts of the "Jedi Developer" documentation. This may also help: |
Namespace packages in Python 2 are implemented through setuptools/distribute, since the language does not support them natively: http://packages.python.org/distribute/setuptools.html#namespace-packages It's used for example in They are indeed created with python code by putting a special declaration in your top-level It's the "multiple .pth links pointing to different packages trees" situation that tricks jedi when you have multiple namespace packages installed with For example if you have The fix would be to inspect It's quite a mess, but sadly it's the only "standard" that we have in Python 2. I'm willing to put some time in developing a patch but first wanted to know your feeling about it. |
You're now speaking of Python 2, how do namespaces pacakges work in Python 3?
how would you get |
Namespace packages in Python 3.3 are very different from what we have in Python 2 (though conceptually similar). They are described extensively in PEP 420. I don't personally use Python 3.3 but from what I understand the main points are they don't require special code in top-level
|
I tried my test as-is (with setuptools namespace packages) and it fails. I also tried to make python 3.3 namespace packages, and it fails too. |
To run my tests :
|
Note that under python 2.7, it fails in the same way as before (only one of the two sub-packages is found), and neither of the two sub-packages is found under python 3.3. |
@flupke However, it's highly possible that this is not working, because I never really checked if namespace packages work and haven't really understood that as well. So I'll be looking into it. |
In our company we are using "namespace packages" in an extensive way. Jedi is great tool, but in our company it has limited usage because of lack of supporting "namespace packages". I would be greate if someone add support for "namespace packakges". |
I have read a few things now about namespace packages and I think I know what they are and how I can create them. An easy case are Python3.3 implicit namespace packages, which should already work (with the import internals use of `importlib). However, namespace packages created with @flupke @marc1n (or anyone else) Could one of you tell me if this is the only way that namespace packages are being used (1): Let's assume that our namespace package is Namespace packages are always made up by at least one package in
This defines the namespace. If another namespace package is being installed, it will be in a different folder Nested namespace packages seem to be possible, but I don't get how they work. Same procedure, with subfolders? (1) If not, please tell me how they could be used differently. |
(1) I don't know if these are the only way, but at least they are the official ways: http://www.python.org/dev/peps/pep-0382/#namespace-packages-today I never used nested namespaces, and I bet their use is marginal. |
Well I could totally see the following use case: |
namespace packages should work now, please test (dev branch). |
Quickly tested and the goto function works, but omni completion does not. |
Hmm now it works... something must have confused jedi-vim (though it happens sometimes too with non-namespace packages so this may be unrelated to this issue). Great work thanks! |
Yes, I know what you mean. I'm still trying to figure out those problems. |
I'm using latest jedi-vim. It seems completion for When I use d to find the definition of
|
That's a bug,
Which looks better anyway. You can PR it, if you want. Also if easily possible add a regression test. |
Is there any plan to add support for Namespace packages? Our codebase uses Namespace packages (PEP 420) extensively and as a result jedi pulls up a blank on all of our code. For the most part, now that PEP 420 works, we now only put init.py into packages that actually have some sort of initialization to perform. Without them we have greater flexibility to compose python packages together. However, it looks like pkgutil.iter_modules will never return is_pkg=True for Namespace packages. (I'm not sure exactly how the import machinery in Python resolves them, instead, other than NamespacePath and NamespaceLoader are part of it. |
No there isn't. Sorry :-) It works like this: Whoever really needs a feature will eventually implement it. I would really like to see this, but currently I don't really have time. I would be happy if you or someone else would take the lead here.
In general, I'm not sure if this is the right way to find that information, because quite frankly I have no clue how Python finds those packages. IMO we should implement it the same way Python implements this anyway, which would mean first investigating how Python does it (even if it's C code, which I don't believe, because it's probably in |
Understood. If I were to submit a patch for the documentation for "Unsupported Features", would you prefer namespace packages to be listed in the subsection "Not yet implemented" or "Will probably never be implemented"? With namespace packages being an integral feature of Python 3, it was a surprise that a code analysis tool of this caliber doesn't support it. (Completely understandably, after reading how the code for jedi handles imports.) A lot of time could be saved if it were in the feature list. |
It's a question of priorities. I don't have the time to do it right now, but it will definitely be implemented at some point in time. Therefore it's definitely not a "Will probably never be implemented". In general there's a need for people besides me improving Jedi, this could be a good start. :) |
I'm using jedi as part of YouCompleteMe. The codebase I'm working with has a nested set of packages that looks like
When I type
Is that related to this issue, or should I file a new one? |
You probably don't need to create an issue for this, because it's very unlikely that anyone else will tackle it, also it's kind of in this issue. |
AFAIK Namespace packages are now supported. |
Support for nested namespace packages is still broken: elprans@ca10e17 |
After testing with commit m-novikov@869c72d I can validate that this is not completely working yet. |
With the help of a few pull requests everything is now working fine. Let me know if there are still issues. It's all on the master branch. @gustavovalverde It's working perfectly fine. I just checked. You just have to use the right Python version. |
Hi, I'm failing to get autocompletion working via VSCode/Jedi with a large internal namespace package. I've managed to boil it down to a small example with just Jedi. I have a namespace package called 'foo', spread across two directories, 'projecta' and 'projectb'
The foo/__init__.py file is identical across both directories:
And foo/bar/__init__.py and foo/baz/__init__.py contain a single function each:
The namespace packages work in Python as I would expect:
But autocompletion with Jedi is only working for one of the two packages, always the first to be listed in the search path. For example, here it will complete for foo.bar.bar() but not foo.baz.baz()
And with the Python Path swapped around, it will complete for foo.baz.baz() but not foo.bar.bar()
This is with Jedi 0.12.0 It's entirely possible I've done something wrong and any advice would be appreciated if that is the case. If what I've done is right, I would contend that this bug is not entirely fixed yet. Please let me know if you need any more information. |
@brokenn Can you please open a new issue? It's probably easier to track. It might not even be related to this issue. |
Sure thing, opened as #1105 |
Goto is tricked by namespace packages and fails.
I made tests to demonstrate this issue in flupke@ad95279
The problem is that
imp.find_module()
does not support namespace packages.Should
imports.ImportPath._follow_file_system()
fiddle withpkg_resources
(see http://stackoverflow.com/questions/5741362/alternatives-to-imp-find-module for a beginning of solution)? Or isimp.find_module()
something you would like to discard in the future? (maybe by usingimportlib.import_module()
, which does work with namespace packages, but has the disadvantage of actually importing the modules)The text was updated successfully, but these errors were encountered: