msg278543 - (view) |
Author: Douglas Greiman (dgreiman) * |
Date: 2016-10-12 23:36 |
pkg_util.get_data('mypackage', 'resourcename') returns None if 'mypackage' is a namespace package, because the package object has no __file__ attribute. A shell script is attached to reproduce this. This is either a bug to be fixed (my preference) or behavior to be documented. If there is equivalent, working functionality in the new importlib, that would also be a good to document. |
|
|
msg278629 - (view) |
Author: Xiang Zhang (xiang.zhang) *  |
Date: 2016-10-14 04:06 |
The doc says: "If the package cannot be located or loaded, or it uses a loader which does not support get_data(), then None is returned". Namespace package gets a ``None`` loader and then does not support get_data. |
|
|
msg278663 - (view) |
Author: Brett Cannon (brett.cannon) *  |
Date: 2016-10-14 20:00 |
Xiang is right about why this doesn't work. If you would like to propose a patch to update the wording of the docs, Douglas, we could then consider applying it. It could be as simple as just adding "(e.g. the load for namespace packages does not implement get_data())". And there is no equivalent feature in importlib (yet; it's on my todo list). |
|
|
msg278699 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2016-10-15 06:55 |
For 3.4/5/6, I agree this is a documentation issue, where the data files need to be given a *non*-namespaced directory to live in. However, it's worth explicitly noting that subpackages of namespace packages can themselves be regular packages, so one possible solution is to do: pkg_util.get_data('my_namespace.my_package_data', 'resourcename') rather than storing the data directly at the namespace level. |
|
|
msg282819 - (view) |
Author: Douglas Greiman (dgreiman) * |
Date: 2016-12-10 01:39 |
Patch attached. Feel free to wordsmith. |
|
|
msg282870 - (view) |
Author: Brett Cannon (brett.cannon) *  |
Date: 2016-12-10 19:55 |
Patch LGTM. |
|
|
msg282880 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2016-12-10 22:15 |
New changeset 3484933ba904 by Brett Cannon in branch '3.5': Issue #28424: Document pkgutil.get_data() doesn't work with namespace packages. https://hg.python.org/cpython/rev/3484933ba904 New changeset c17d2a37d610 by Brett Cannon in branch '3.6': Merge for issue #28424 https://hg.python.org/cpython/rev/c17d2a37d610 New changeset b396a2c97871 by Brett Cannon in branch 'default': Merge for issue #28424 https://hg.python.org/cpython/rev/b396a2c97871 |
|
|
msg282881 - (view) |
Author: Brett Cannon (brett.cannon) *  |
Date: 2016-12-10 22:15 |
Thanks for the patch, Douglas! |
|
|