-
Notifications
You must be signed in to change notification settings - Fork 962
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
there's no documentation of how to package namespace packages #265
Comments
The best answer here is to use PEP 420 namespaces, but given those are Python 3.3+ only and most people can't/won't move to 3.3+ only then we need another solution. Unfortinately there is no slam dunk solution here, there's basically either:
|
Option 3: we ask @ericsnowcurrently to remove some of the scary warnings from the importlib2 README and actively promote it as a modernisation technique for Python 2.7 virtual environments That is, PEP 420 namespaces do work on Python 2.7 if the environment is set up to use importlib2 as its import system implementation (and you get a bunch of other nice improvements as well, like the handling of Unicode paths not being completely broken, and a significantly reduced number of stat calls for successful imports). |
I'm not opposed...just have to find the time to make sure importlib2 is in a happy place. :) |
Bump on this issue I'm happy to help on the task of updating the user guide with namespace package documentation (having to extensively figure this out for all of the |
I think that newer setuptools have fixed setuptools type namespace packages so that they work in all cases. Someone would need to go through and see if the problems in like pypa/pip#3 are fixed and such (and ideally it would use PEP 420 namespace packages where possible) but if all of that checks out I Think that is a reasonable recommendation now. |
@dstufft thanks, I'll see if I can write a suite of tests to verify. I think these are all the cases to check, but please let me know if I'm missing anything:
Repeat 3-5 with the steps reversed. |
@jonparrott Yes, I think those are the cases. Somewhere in pypa/pip#3 or one of the related issues someone had steps to reproduce the issue from scratch that might be useful. |
@dstufft thanks, stay tuned. :) |
Okay, initial results:
This is with PEP 420 packages using Python 3. Does that seem about right to you? You can see the source here: https://github.com/jonparrott/namespace-pkg-tests And you can run the tests with:
|
I think for PEP 420 packages you don't use the |
@dstufft you mean the |
Well, removing the
|
Even worse, all sessions fail on Python 2 when using PEP 420 packages and not specifying I've pushed up my latest code, if anyone wants to poke around. It seems like we could recommend namespace packages with the caveat that no one should ever install the package with |
That seems reasonable, perhaps it would make sense to open an issue with setuptools to see if there is something they can do about the |
Filed pypa/setuptools#960 @dstufft can you take a look at this package and verify that this is up-to-date with what we want to recommend? Once we're good with that, I can start writing the docs. :) |
Got confirmation from @jaraco on pypa/setuptools#960 that cross-installing isn't something we want to support, so I'll just explicitly call that out in these docs. My current working plan is to recommend the following:
@dstufft we have https://github.com/pypa/sampleproject, does it make sense to have https://github.com/pypa/sample-namespace-package-project and https://github.com/pypa/sample-pep420-namespace-package project? I'm happy to actually provide these samples, they just need a home. |
@jonparrott I'd be interested in your opinion on this: Seems like using |
@simonvanderveldt do you have a comparison of how the test matrix shakes out in the case? |
@jonparrott I've added the table and amended my commit |
@simonvanderveldt very interesting. I'm curious to see what @jaraco and others think about those results- this begs the question of if we should stop recommending |
That's an interesting finding, and encouraging. If we can deprecate use of pkg_resources and declare_namespace, that would be awesome. I'll do some experiments in my own namespace packages and see if they fail anywhere using pkgutil. |
Thanks @jaraco! Looking forward to your findings. :) @simonvanderveldt for posterity, can you open a PR against my repo to make that change? |
Done! |
The now well documented shenanigans relating to namespace package installation and It would be fantastic if there was one approach that would work across all runtimes in a sensible way. For me, that's a requirement for any replacement, not a nice-to-have, as the status quo is manageable given dependency-aware Makefile automation. (Seriously. My Makefiles will become self-aware one day.) There is the additional concern that for any sufficiently large collection of namespace contributing packages, updates to a newer mechanism may be partial. Any change that is not compatible with mixed usage would require hard pinning and fixing all contributing packages simultaneously. A potentially massive undertaking, greatly increasing friction of adoption of a new mechanism (where backwards compatibility is an issue). |
@amcgregor agreed. We're just trying to figure out the state of things right now, then figure out what to recommend. We're not an authority, so what we recommend isn't law. If the whatever method you're currently using works fine, then don't mess with it. The Google namespace packages I shepherd probably won't change. |
@jonparrott Figuring out namespaces and figuring out entry points were both aspects of Python packaging that were extremely poorly documented in the past, and in many cases required diving into the actual Any solution more elegant than > 100 lines of Makefile extracting metadata from egg-info to inform dependency graphing for a hierarchy of interdependent checked out packages would be good in my books. The possibility of the hard pinning situation, though, gives me the creeps. Direct manipulation/assignment of __path__ = __import__('pkgutil').extend_path(__path__, __name__) Edited to add links to a few of the packages, for example purposes, and link to the presentation I mentioned, which is by far the most in-depth and awesome thing I have ever seen regarding this aspect of Python. (Can remove some if too spammy. ;) |
The lack of documentation is definitely what I'm trying to fix right now. :) |
@jonparrott I don't do a whole lot with the user facing documentation side of things (I am horrible at it :( ) but that seems reasonable to me? |
Right off the bat, I find that removing the call to
Aah, right. Need to remove the |
@jaraco Right, there were two steps proposed in @simonvanderveldt's adjustment:
That approach should work in any version since 2.3 (when So if that means |
Awesome. Okay, I have one final curiosity - what happens if you mix a |
@dstufft I'm here to help with user-facing documentation :) I'll create those sample repos on my own github and then we can figure out how to get them under pypa once I write the docs for namespace packages. |
@simonvanderveldt @jaraco @amcgregor good and bad news. :) Based on the new table here. The The bad news is that this unsurprisingly doesn't play well if you mix it with the @dstufft any reservations on me moving forward with writing documentation suggesting the |
@jonparrott Awesome! Looks promising :) I wanted to add that both the Python 2 and the Python 3 docs mention this implementation in the pkgutil docs, it might be useful to reference those? Also, as already mentioned in this issue, PEP-420 defines a new and simpler way of doing namespace packages, it might be useful to suggest to use that for Python 3.3+? |
I can definitely mention pep420 for Python 3 only packages, but the table
shows that it does have some tooling issues.
…On Mon, Apr 3, 2017, 2:53 PM Simon van der Veldt ***@***.***> wrote:
@jonparrott <https://github.com/jonparrott> Awesome! Looks promising :)
I wanted to add that both the Python 2
<https://docs.python.org/2/library/pkgutil.html#pkgutil.extend_path> and
the Python 3
<https://docs.python.org/3/library/pkgutil.html#pkgutil.extend_path> docs
mention this implementation in the pkgutil docs, it might be useful to
reference those?
Also, as already mentioned in this issue, PEP-420 defines a new and
simpler way of doing namespace packages, it might be useful to suggest to
use that for Python 3.3+?
Note that pkgutil.extend_path() should be PEP-420 compatible
<https://www.python.org/dev/peps/pep-0420/#migrating-from-legacy-namespace-packages>,
but that's only to help out existing packages.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#265 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPUc6DwKBvU76TcZ65iapoi4_GRJvt2ks5rsWppgaJpZM4JrS_->
.
|
Fair point. You probably know best what to do documentation wise for the end users. |
@jaraco might have some insight into what's going on with mixing pip and setuptools with pep420 packages. The biggest concern is that installing both packages with |
Ugh. That makes it difficult for a namespace to transition. Every single package in that namespace would have to be updated and not mixed with any old versions. I can't imagine how we might transition the ecosystem under such a world-breaking scenario.
Setuptools supports installing pep420 packages, but has issues with
Well, that's because under setuptools, without any extra parameters, |
Looking at the code for the two implementations:
The two most likely culprits for cross-compatibility issues seem to be:
So what if the agreed way forward was to:
The related documentation could then be split into two sections on "Defining a new namespace package" (where the first recommendation would apply and the use of |
That is what I was afraid of. Now to ask myself, do I have the strength of willpower to claim the |
Slight thorn in this, it seems that mixing pep 420 and pkgutil doesn't work if the first package is installed via setuptools (see updated table here). @jaraco is this because of the aforementioned |
Update for those interested: I'm working on a draft of this now and hope to have a PR out on Friday. :) |
@jonparrott You have the power. |
Thanks for volunteering @jonparrott! |
People seem to really want to do this, and they resort to black magic in order to make it happen. See for example protocolbuffers/protobuf#1296. There should probably be clear documentation of how to achieve namespace package packaging in a reliable way.
I think https://setuptools.readthedocs.io/en/latest/pkg_resources.html?highlight=namespace#namespace-package-support is authoritative in this case; should it be referenced?
The text was updated successfully, but these errors were encountered: