diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2016-12-07 20:43:03 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-12-07 20:43:03 -0500 |
commit | 2c44848aa1e5ca1accfb425b575be66df663954a (patch) | |
tree | ca53b60fda0348908fbbbfbe1846cbca27db61e6 | |
parent | 1474cf0f7e2b973eb102aef311939228b83e31b6 (diff) | |
download | python-setuptools-git-issue250-reentry.tar.gz |
Considering re-writing the -nspkg.pth file as a call to re-enter setuptools to setup the package.issue250-reentry
-rwxr-xr-x | setuptools/namespaces.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/setuptools/namespaces.py b/setuptools/namespaces.py index cc934b7e..01c60777 100755 --- a/setuptools/namespaces.py +++ b/setuptools/namespaces.py @@ -33,36 +33,33 @@ class Installer: def _get_target(self): return self.target + @staticmethod + def init(root, pkg): + import sys, types + pep420 = sys.version_info > (3, 3) + pth = tuple(pkg.split('.')) + p = os.path.join(root, *pth) + ie = os.path.exists(os.path.join(p, '__init__.py')) + m = not ie and not pep420 and sys.modules.setdefault(pkg, + types.ModuleType(pkg)) + mp = (m or []) and m.__dict__.setdefault('__path__', []) + (p not in mp) and mp.append(p) + parent, sep, child = pkg.rpartition('.') + m and parent and setattr(sys.modules[parent], child, m) _nspkg_tmpl = ( - "import sys, types, os", - "pep420 = sys.version_info > (3, 3)", - "p = os.path.join(%(root)s, *%(pth)r)", - "ie = os.path.exists(os.path.join(p,'__init__.py'))", - "m = not ie and not pep420 and " - "sys.modules.setdefault(%(pkg)r, types.ModuleType(%(pkg)r))", - "mp = (m or []) and m.__dict__.setdefault('__path__',[])", - "(p not in mp) and mp.append(p)", + "import setuptools.namespaces", + "setuptools.namespaces.Installer.init(%(root)r, %(pkg)r)", ) "lines for the namespace installer" - _nspkg_tmpl_multi = ( - 'm and setattr(sys.modules[%(parent)r], %(child)r, m)', - ) - "additional line(s) when a parent package is indicated" - def _get_root(self): return "sys._getframe(1).f_locals['sitedir']" def _gen_nspkg_line(self, pkg): # ensure pkg is not a unicode string under Python 2.7 pkg = str(pkg) - pth = tuple(pkg.split('.')) root = self._get_root() - tmpl_lines = self._nspkg_tmpl - parent, sep, child = pkg.rpartition('.') - if parent: - tmpl_lines += self._nspkg_tmpl_multi - return ';'.join(tmpl_lines) % locals() + '\n' + return ';'.join(self._nspkg_tmpl) % locals() + '\n' def _get_all_ns_packages(self): """Return sorted list of all package namespaces""" |