-
Notifications
You must be signed in to change notification settings - Fork 164
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
Correct implementation of pkgutil style namespace #215
Conversation
See corresponding PR to luma.core - rm-hull/luma.core#145 Original issue and explanation - rm-hull/luma.core#144
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before merging this I'd like to see the luma.core adjustment merged and released first (rm-hull/luma.core#145).
Agreed- I expected somewhat more discussion around this since it's a change to packaging technique and may have quite a far-reaching impact and it seems to be a heck of a rabbit hole. Incidentally the currently shipped >>> import luma.core
import luma.core # directory /usr/local/lib/python2.7/dist-packages/luma/core
# trying /usr/local/lib/python2.7/dist-packages/luma/core/__init__.arm-linux-gnueabihf.so
# trying /usr/local/lib/python2.7/dist-packages/luma/core/__init__.so
# trying /usr/local/lib/python2.7/dist-packages/luma/core/__init__module.so
# trying /usr/local/lib/python2.7/dist-packages/luma/core/__init__.py
# /usr/local/lib/python2.7/dist-packages/luma/core/__init__.pyc matches /usr/local/lib/python2.7/dist-packages/luma/core/__init__.py
import luma.core # precompiled from /usr/local/lib/python2.7/dist-packages/luma/core/__init__.pyc However when I install locally using I can only attribute this difference to the If I build the new luma.core (as of my changes) with If I do the same for luma.oled then my
And both However if I then uninstall Again, TLDR
And: Installing both packages from .whl files results in them both living in
But when I
facepalm This is with pip 9.0.1. And apparently isn't a new problem: pypa/packaging.python.org#314 This seems to suggest that a
So delving into this yields the oh-so-common-of-Python pattern for # -*- coding: utf-8 -*-
# Copyright (c) 2014-18 Richard Hull and contributors
# See LICENSE.rst for details.
try:
from pkg_resources import declare_namespace
declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__) Which results in a
Dang, that surely wont work, right!?? Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import luma.oled
>>> import luma.core
>>> Wut!? Okay let's mess with this:
!?!?
Hmm, okay, it never sees the SummaryThe working pattern seems to be to include # -*- coding: utf-8 -*-
# Copyright (c) 2014-18 Richard Hull and contributors
# See LICENSE.rst for details.
try:
from pkg_resources import declare_namespace
declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__) This prevents the namespace from being yanked away from installed packages when any namespaced package is uninstalled. The key caveat of this solution- and it appears any solution involving namespacing- is that the packages must be installed in the same manner. You can't mix and match .whl installs with .egg installs. Someone actually went to the trouble of enumerating the working install permutations here: pypa/packaging.python.org#265 (comment) And seems to have a setup for testing this in the repository I was consulting beforehand: https://github.com/pypa/sample-namespace-packages |
thanks for pointing this out, i fully agree. could you also take a look at the other luma.* libraries and check if they need to be updated as well? once a new luma.core is released it's always a little bit of fingers crossed and hope the other libraries don't break (even though we have travis builds etc). |
I think we took the decision to fully support pip-installed versioned releases from PyPi only rather than someone arbitrarily installing from a git clone (it's hard enough supporting this library as it is). This might explain why it doesn't really hang together properly when installing with
Anyway, I just pushed luma.core v1.8.0 with the package fix. |
Also: I'm not familiar enough with the nuances of python packaging to know whether it will break, so let's just push it out and fix forward. |
Honestly- despite combing through all the packaging documentation with a fine-toothed comb several times over, I'm still not sure I'm familiar enough with its nuisances. I'm all for pushing it out and fixing forward, though. If I don't see them, please tag me on any issues which may be related. |
rm-hull/luma.core#145 was released, so review comments now satisfied
See corresponding PR to luma.core - rm-hull/luma.core#145
Original issue and explanation - rm-hull/luma.core#144