summaryrefslogtreecommitdiff
path: root/setuptools/command/easy_install.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/command/easy_install.py')
-rwxr-xr-xsetuptools/command/easy_install.py66
1 files changed, 50 insertions, 16 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index df1655bf..45d180bb 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -215,10 +215,19 @@ class easy_install(Command):
remover = rmtree if is_tree else os.unlink
remover(path)
+ @staticmethod
+ def _render_version():
+ """
+ Render the Setuptools version and installation details, then exit.
+ """
+ ver = sys.version[:3]
+ dist = get_distribution('setuptools')
+ tmpl = 'setuptools {dist.version} from {dist.location} (Python {ver})'
+ print(tmpl.format(**locals()))
+ raise SystemExit()
+
def finalize_options(self):
- if self.version:
- print('setuptools %s' % get_distribution('setuptools').version)
- sys.exit()
+ self.version and self._render_version()
py_version = sys.version.split()[0]
prefix, exec_prefix = get_config_vars('prefix', 'exec_prefix')
@@ -1530,23 +1539,16 @@ class PthDistributions(Environment):
if not self.dirty:
return
- data = '\n'.join(map(self.make_relative, self.paths))
- if data:
+ 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"
- ) % data
+ lines = self._wrap_lines(rel_paths)
+ data = '\n'.join(lines) + '\n'
if os.path.islink(self.filename):
os.unlink(self.filename)
- f = open(self.filename, 'wt')
- f.write(data)
- f.close()
+ with open(self.filename, 'wt') as f:
+ f.write(data)
elif os.path.exists(self.filename):
log.debug("Deleting empty %s", self.filename)
@@ -1554,6 +1556,10 @@ class PthDistributions(Environment):
self.dirty = False
+ @staticmethod
+ def _wrap_lines(lines):
+ return lines
+
def add(self, dist):
"""Add `dist` to the distribution map"""
new_path = (
@@ -1591,6 +1597,34 @@ class PthDistributions(Environment):
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)
+ """)
+
+
+if os.environ.get('SETUPTOOLS_SYS_PATH_TECHNIQUE', 'rewrite') == 'rewrite':
+ PthDistributions = RewritePthDistributions
+
+
def _first_line_re():
"""
Return a regular expression based on first_line_re suitable for matching