diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2015-08-19 19:46:57 +0100 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-08-19 19:46:57 +0100 |
commit | 3f2ccea66a3deee1e4a4234d695dd94282ec3819 (patch) | |
tree | e3e62aabd3b4a27058fe0df05c315d6819d91659 /setuptools/command/easy_install.py | |
parent | 9dc51a56c6133f2b115bc8133236e25cd2bb0a31 (diff) | |
download | external_python_setuptools-3f2ccea66a3deee1e4a4234d695dd94282ec3819.tar.gz external_python_setuptools-3f2ccea66a3deee1e4a4234d695dd94282ec3819.tar.bz2 external_python_setuptools-3f2ccea66a3deee1e4a4234d695dd94282ec3819.zip |
Extract method for wrapping lines
Diffstat (limited to 'setuptools/command/easy_install.py')
-rwxr-xr-x | setuptools/command/easy_install.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 4688cc42..15b260dd 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1533,14 +1533,8 @@ class PthDistributions(Environment): rel_paths = list(map(self.make_relative, self.paths)) if rel_paths: log.debug("Saving %s", self.filename) - data = ( - "import sys; sys.__plen = len(sys.path)\n" - "%s\n" - "import sys; new=sys.path[sys.__plen:];" - " del sys.path[sys.__plen:];" - " p=getattr(sys,'__egginsert',0); sys.path[p:p]=new;" - " sys.__egginsert = p+len(new)\n" - ) % '\n'.join(rel_paths) + lines = self._wrap_lines(rel_paths) + data = '\n'.join(lines) + '\n' if os.path.islink(self.filename): os.unlink(self.filename) @@ -1554,6 +1548,26 @@ class PthDistributions(Environment): self.dirty = False + def _wrap_lines(self, lines): + yield self._inline(""" + import sys + sys.__plen = len(sys.path) + """) + for line in lines: + yield line + yield self._inline(""" + import sys + new = sys.path[sys.__plen:] + del sys.path[sys.__plen:] + p = getattr(sys, '__egginsert', 0) + sys.path[p:p] = new + sys.__egginsert = p + len(new) + """) + + @staticmethod + def _inline(text): + return textwrap.dedent(text).strip().replace('\n', '; ') + def add(self, dist): """Add `dist` to the distribution map""" new_path = ( |