aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/command/install_egg_info.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-06-22 10:26:00 -0400
committerJason R. Coombs <jaraco@jaraco.com>2014-06-22 10:26:00 -0400
commitd8192350d95f3daf8831b58c80ded4d0d3393d7c (patch)
tree65cec4d3872701d9bf844ce44c20d77b13827f11 /setuptools/command/install_egg_info.py
parent63b852dff23dc86e983fceddde1463724a9d8a07 (diff)
downloadexternal_python_setuptools-d8192350d95f3daf8831b58c80ded4d0d3393d7c.tar.gz
external_python_setuptools-d8192350d95f3daf8831b58c80ded4d0d3393d7c.tar.bz2
external_python_setuptools-d8192350d95f3daf8831b58c80ded4d0d3393d7c.zip
Extract method for generating lines for a pkg in nsp. Fixes issue in 67bdf3a726962 where only the last dat would be written.
Diffstat (limited to 'setuptools/command/install_egg_info.py')
-rwxr-xr-xsetuptools/command/install_egg_info.py49
1 files changed, 26 insertions, 23 deletions
diff --git a/setuptools/command/install_egg_info.py b/setuptools/command/install_egg_info.py
index 67e183e1..35a00e54 100755
--- a/setuptools/command/install_egg_info.py
+++ b/setuptools/command/install_egg_info.py
@@ -60,6 +60,22 @@ class install_egg_info(Command):
unpack_archive(self.source, self.target, skimmer)
+ def install_namespaces(self):
+ nsp = self._get_all_ns_packages()
+ if not nsp:
+ return
+ filename, ext = os.path.splitext(self.target)
+ filename += '-nspkg.pth'
+ self.outputs.append(filename)
+ log.info("Installing %s", filename)
+ if self.dry_run:
+ return
+
+ lines = map(self._gen_nspkg_line, nsp)
+
+ with open(filename, 'wt') as f:
+ list(map(f.write, lines))
+
_nspkg_tmpl = (
"import sys, types, os",
"p = os.path.join(sys._getframe(1).f_locals['sitedir'], *%(pth)r)",
@@ -76,29 +92,16 @@ class install_egg_info(Command):
)
"additional line(s) when a parent package is indicated"
- def install_namespaces(self):
- nsp = self._get_all_ns_packages()
- if not nsp:
- return
- filename, ext = os.path.splitext(self.target)
- filename += '-nspkg.pth'
- self.outputs.append(filename)
- log.info("Installing %s", filename)
- if self.dry_run:
- return
-
- for pkg in nsp:
- # ensure pkg is not a unicode string under Python 2.7
- pkg = str(pkg)
- pth = tuple(pkg.split('.'))
- tmpl_lines = self._nspkg_tmpl
- parent, sep, child = pkg.rpartition('.')
- if parent:
- tmpl_lines += self._nspkg_tmpl_multi
- dat = ';'.join(tmpl_lines) % locals() + '\n'
-
- with open(filename, 'wt') as f:
- f.write(dat)
+ @classmethod
+ def _gen_nspkg_line(cls, pkg):
+ # ensure pkg is not a unicode string under Python 2.7
+ pkg = str(pkg)
+ pth = tuple(pkg.split('.'))
+ tmpl_lines = cls._nspkg_tmpl
+ parent, sep, child = pkg.rpartition('.')
+ if parent:
+ tmpl_lines += cls._nspkg_tmpl_multi
+ return ';'.join(tmpl_lines) % locals() + '\n'
def _get_all_ns_packages(self):
"""Return sorted list of all package namespaces"""