From 3f2ccea66a3deee1e4a4234d695dd94282ec3819 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 19 Aug 2015 19:46:57 +0100 Subject: Extract method for wrapping lines --- setuptools/command/easy_install.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'setuptools/command') 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 = ( -- cgit v1.2.1