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 | 9b84c915142f8906fc2ce5f254d4b7522a1658d6 (patch) | |
tree | 0d7fd588b59dc5d5d8d3c22efe11d92051b86107 | |
parent | 134bdfd93da0dcdef4c28bb85148aa7d23bc5363 (diff) | |
download | python-setuptools-bitbucket-9b84c915142f8906fc2ce5f254d4b7522a1658d6.tar.gz |
Extract method for wrapping lines
-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 = ( |