diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-06-17 17:10:04 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2013-06-17 17:10:04 +0200 |
commit | 1e207fd9fa6d8c6c56e7706a781652fb8b6ad109 (patch) | |
tree | abe23bf9629840fb15fb64724ce761f1a56f32a9 | |
parent | ef345bf9d8664d5addfd0ef627b1f6d569f311fb (diff) | |
download | logilab-common-1e207fd9fa6d8c6c56e7706a781652fb8b6ad109.tar.gz |
[modutils]?setuptools pkg_resources support. Closes #8796
NO I won't write a test. Setup is to painful to reproduce for automatic test
(require virtualenv, setuptools, python setup.py develop, etc). See description
on the ticket.
-rw-r--r-- | modutils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/modutils.py b/modutils.py index 05f0602..834b5d3 100644 --- a/modutils.py +++ b/modutils.py @@ -574,6 +574,11 @@ def _search_zip(modpath, pic): return ZIPFILE, abspath(filepath) + '/' + '/'.join(modpath), filepath raise ImportError('No module named %s' % '.'.join(modpath)) +try: + import pkg_resources +except ImportError: + pkg_resources = None + def _module_file(modpath, path=None): """get a module type / file path @@ -604,6 +609,12 @@ def _module_file(modpath, path=None): checkeggs = True except AttributeError: checkeggs = False + # pkg_resources support (aka setuptools namespace packages) + if pkg_resources is not None and modpath[0] in pkg_resources._namespace_packages and len(modpath) > 1: + # setuptools has added into sys.modules a module object with proper + # __path__, get back information from there + module = sys.modules[modpath.pop(0)] + path = module.__path__ imported = [] while modpath: # take care to changes in find_module implementation wrt builtin modules |