Commit 3d71f8b9 authored by Jason R. Coombs's avatar Jason R. Coombs

Allow the root to be overridden

parent 3617c2b2
...@@ -33,7 +33,7 @@ class Installer: ...@@ -33,7 +33,7 @@ class Installer:
_nspkg_tmpl = ( _nspkg_tmpl = (
"import sys, types, os", "import sys, types, os",
"pep420 = sys.version_info > (3, 3)", "pep420 = sys.version_info > (3, 3)",
"p = os.path.join(sys._getframe(1).f_locals['sitedir'], *%(pth)r)", "p = os.path.join(%(root)s, *%(pth)r)",
"ie = os.path.exists(os.path.join(p,'__init__.py'))", "ie = os.path.exists(os.path.join(p,'__init__.py'))",
"m = not ie and not pep420 and " "m = not ie and not pep420 and "
"sys.modules.setdefault(%(pkg)r, types.ModuleType(%(pkg)r))", "sys.modules.setdefault(%(pkg)r, types.ModuleType(%(pkg)r))",
...@@ -47,15 +47,18 @@ class Installer: ...@@ -47,15 +47,18 @@ class Installer:
) )
"additional line(s) when a parent package is indicated" "additional line(s) when a parent package is indicated"
@classmethod def _get_root(self):
def _gen_nspkg_line(cls, pkg): return "sys._getframe(1).f_locals['sitedir']"
def _gen_nspkg_line(self, pkg):
# ensure pkg is not a unicode string under Python 2.7 # ensure pkg is not a unicode string under Python 2.7
pkg = str(pkg) pkg = str(pkg)
pth = tuple(pkg.split('.')) pth = tuple(pkg.split('.'))
tmpl_lines = cls._nspkg_tmpl root = self._get_root()
tmpl_lines = self._nspkg_tmpl
parent, sep, child = pkg.rpartition('.') parent, sep, child = pkg.rpartition('.')
if parent: if parent:
tmpl_lines += cls._nspkg_tmpl_multi tmpl_lines += self._nspkg_tmpl_multi
return ';'.join(tmpl_lines) % locals() + '\n' return ';'.join(tmpl_lines) % locals() + '\n'
def _get_all_ns_packages(self): def _get_all_ns_packages(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment