This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年02月10日 20:53 by andrea.crotti, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| namespace.tar.gz | andrea.crotti, 2012年02月10日 20:53 | archive with an example of simple namespace packages | ||
| Messages (7) | |||
|---|---|---|---|
| msg153076 - (view) | Author: andrea crotti (andrea.crotti) | Date: 2012年02月10日 20:53 | |
I am not really sure that it is a bug, but for me it's at least not the expected behaviour.
In short supposing I have two namespace packages ab and ac (as seen in the tar file), this works perfectly:
import sys
from os import path
sys.path.append(path.abspath('ab'))
sys.path.append(path.abspath('ac'))
from a.b import api as api_ab
from a.c import api as api_ac
But this doesn't:
import sys
from os import path
sys.path.append(path.abspath('ab'))
from a.b import api as api_ab
sys.path.append(path.abspath('ac'))
from a.c import api as api_ac
And raises an ImportError
from a.c import api as api_ac
ImportError: No module named c
Which means that if you actually append all the paths containing package resources before trying to import something it works, but if you interleave the path mangling, it won't..
Is this a bug or maybe I'm doing something wrong?
|
|||
| msg153102 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2012年02月11日 05:43 | |
Are you using pure-stdlib namespace packages, i.e. things using distutils and pkgutil.extend_path, or setuptools’ notion of namespace packages? (I didn’t check your archive, in general we dislike binary files on this tracker and use text all the time.) |
|||
| msg153121 - (view) | Author: andrea crotti (andrea.crotti) | Date: 2012年02月11日 11:15 | |
There is nothing binary in the archive, just a simple example of namespace packages, which was the minimal example that I could create to make things fail.
I use the standard pkg_resources way to do things:
__import__('pkg_resources').declare_namespace(__name__)
|
|||
| msg153146 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2012年02月12日 02:49 | |
> There is nothing binary in the archive The archive is a binary file. We tend to dislike those because we need to download and process them instead of just reading them in a browser tab, and in some cases (Windows .exe files) there are also security reasons. It’s not a big deal anyway, just a small matter of convention. > I use the standard pkg_resources way to do things: setuptools is not in the standard library nor does it implements PEPs, so it’s at most a de facto standard. More importantly, it is not developed by python-dev; could you report the bug to bugs.python.org/setuptools and bitbucket.org/tarek/distribute ? If they find that the bug actually comes from distutils, then we’ll reopen this bug. Thanks! |
|||
| msg153200 - (view) | Author: andrea crotti (andrea.crotti) | Date: 2012年02月12日 11:37 | |
About the binary file, in theory I agree with you, but that archive contains 5 or 6 subdirectories with a few almost empty files. Of course I can write a script that recreates that situation, but does it make sense when I can just tar and untar it? And what should be the security threat in a tar.gz file? Anyway it doesn't matter and sure I will try to use plain text in the future.. About the bug, for what I can understand the bug comes from pkg_resources: /usr/lib/python2.7/site-packages/pkg_resources.py is owned by python2-distribute 0.6.24-1 and/or from how the import mechanism works on namespace packages, not from setuptools.. Should I still move the bug report to somewhere else? |
|||
| msg153261 - (view) | Author: andrea crotti (andrea.crotti) | Date: 2012年02月13日 12:02 | |
I reopen the ticket because I'm still not convinced.. I tried to substitute the setuptools namespace declaration with the more standard python: from pkgutil import extend_path __path__ = extend_path(__path__, __name__) It behaves exactly in the same way, which makes me think that is more a problem in the importer, that doesn't behave as it should in case of namespace packages.. |
|||
| msg153554 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2012年02月17日 15:51 | |
It's not working because when you import a.b you calculate __path__ at import time, so when you modify sys.path it won't make a difference since import will look at a.__path__ after your a.b import and simply ignore sys.path. But when you put everything on sys.path upfront and use pkgutil to extend __path__ it sees the other 'a' directory and adds it to __path__. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:26 | admin | set | github: 58199 |
| 2012年02月17日 15:51:52 | brett.cannon | set | status: open -> closed nosy: + brett.cannon messages: + msg153554 resolution: not a bug |
| 2012年02月13日 13:52:54 | andrea.crotti | set | resolution: not a bug -> (no value) |
| 2012年02月13日 12:02:32 | andrea.crotti | set | status: closed -> open messages: + msg153261 |
| 2012年02月12日 11:37:56 | andrea.crotti | set | messages: + msg153200 |
| 2012年02月12日 02:50:00 | eric.araujo | set | status: open -> closed versions: - Python 2.6, Python 3.1, Python 2.7, Python 3.2 messages: + msg153146 assignee: tarek -> eric.araujo resolution: not a bug stage: resolved |
| 2012年02月11日 11:15:26 | andrea.crotti | set | messages: + msg153121 |
| 2012年02月11日 05:43:10 | eric.araujo | set | messages: + msg153102 |
| 2012年02月10日 23:35:44 | eric.snow | set | nosy:
+ eric.snow |
| 2012年02月10日 20:53:22 | andrea.crotti | create | |