Commit e2124f4d authored by Jason R. Coombs's avatar Jason R. Coombs

Extract a class for the behavior that rewrites the sys.path

parent 5cbb2ada
...@@ -1547,26 +1547,9 @@ class PthDistributions(Environment): ...@@ -1547,26 +1547,9 @@ class PthDistributions(Environment):
self.dirty = False self.dirty = False
@classmethod @staticmethod
def _wrap_lines(cls, lines): def _wrap_lines(lines):
yield cls.prelude return lines
for line in lines:
yield line
yield cls.postlude
_inline = lambda text: textwrap.dedent(text).strip().replace('\n', '; ')
prelude = _inline("""
import sys
sys.__plen = len(sys.path)
""")
postlude = _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)
""")
def add(self, dist): def add(self, dist):
"""Add `dist` to the distribution map""" """Add `dist` to the distribution map"""
...@@ -1605,6 +1588,33 @@ class PthDistributions(Environment): ...@@ -1605,6 +1588,33 @@ class PthDistributions(Environment):
return path return path
class RewritePthDistributions(PthDistributions):
@classmethod
def _wrap_lines(cls, lines):
yield cls.prelude
for line in lines:
yield line
yield cls.postlude
_inline = lambda text: textwrap.dedent(text).strip().replace('\n', '; ')
prelude = _inline("""
import sys
sys.__plen = len(sys.path)
""")
postlude = _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)
""")
PthDistributions = RewritePthDistributions
def _first_line_re(): def _first_line_re():
""" """
Return a regular expression based on first_line_re suitable for matching Return a regular expression based on first_line_re suitable for matching
......
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