From 1e207fd9fa6d8c6c56e7706a781652fb8b6ad109 Mon Sep 17 00:00:00 2001 From: Sylvain Th?nault Date: Mon, 17 Jun 2013 17:10:04 +0200 Subject: [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. --- modutils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 -- cgit v1.2.1