[Python-checkins] r43178 - in sandbox/trunk/setuptools: EasyInstall.txt setuptools/command/easy_install.py

phillip.eby python-checkins at python.org
Tue Mar 21 00:06:24 CET 2006


Author: phillip.eby
Date: Tue Mar 21 00:06:22 2006
New Revision: 43178

Modified:
   sandbox/trunk/setuptools/EasyInstall.txt
   sandbox/trunk/setuptools/setuptools/command/easy_install.py
Log:
Use relative paths in ``.pth`` files when eggs are being installed to the
same directory as the ``.pth`` file.  This maximizes portability of the
target directory when building applications that contain eggs.


Modified: sandbox/trunk/setuptools/EasyInstall.txt
==============================================================================
--- sandbox/trunk/setuptools/EasyInstall.txt	(original)
+++ sandbox/trunk/setuptools/EasyInstall.txt	Tue Mar 21 00:06:22 2006
@@ -1089,6 +1089,10 @@
    time out or be missing a file.
 
 0.6a11
+ * Use relative paths in ``.pth`` files when eggs are being installed to the
+   same directory as the ``.pth`` file.  This maximizes portability of the
+   target directory when building applications that contain eggs.
+
  * Added ``easy_install-N.N`` script(s) for convenience when using multiple
    Python versions.
 

Modified: sandbox/trunk/setuptools/setuptools/command/easy_install.py
==============================================================================
--- sandbox/trunk/setuptools/setuptools/command/easy_install.py	(original)
+++ sandbox/trunk/setuptools/setuptools/command/easy_install.py	Tue Mar 21 00:06:22 2006
@@ -974,7 +974,7 @@
                 filename = os.path.join(self.install_dir,'setuptools.pth')
                 if os.path.islink(filename): os.unlink(filename)
                 f = open(filename, 'wt')
-                f.write(dist.location+'\n')
+                f.write(self.pth_file.make_relative(dist.location)+'\n')
                 f.close()
 
     def unpack_progress(self, src, dst):
@@ -1316,8 +1316,9 @@
     dirty = False
 
     def __init__(self, filename):
-        self.filename = filename; self._load()
-        Environment.__init__(self, [], None, None)
+        self.filename = filename
+        self.basedir = normalize_path(os.path.dirname(self.filename))
+        self._load(); Environment.__init__(self, [], None, None)
         for path in yield_lines(self.paths):
             map(self.add, find_distributions(path, True))
 
@@ -1336,7 +1337,9 @@
                     continue
                 # skip non-existent paths, in case somebody deleted a package
                 # manually, and duplicate paths as well
-                path = self.paths[-1] = normalize_path(path)
+                path = self.paths[-1] = normalize_path(
+                    os.path.join(self.basedir,path)
+                )
                 if not os.path.exists(path) or path in seen:
                     self.paths.pop()    # skip it
                     self.dirty = True   # we cleaned up, so we're dirty now :)
@@ -1345,18 +1348,15 @@
 
         if self.paths and not saw_import:
             self.dirty = True   # ensure anything we touch has import wrappers
-
         while self.paths and not self.paths[-1].strip():
             self.paths.pop()
 
-
-
     def save(self):
         """Write changed .pth file back to disk"""
         if not self.dirty:
             return
             
-        data = '\n'.join(self.paths)
+        data = '\n'.join(map(self.make_relative,self.paths))
         if data:
             log.debug("Saving %s", self.filename)
             data = (
@@ -1392,6 +1392,12 @@
         Environment.remove(self,dist)
 
 
+    def make_relative(self,path):
+        if normalize_path(os.path.dirname(path))==self.basedir:
+            return os.path.basename(path)
+        return path
+
+
 def get_script_header(script_text, executable=sys_executable):
     """Create a #! line, getting options (if any) from script_text"""
     from distutils.command.build_scripts import first_line_re
@@ -1427,12 +1433,6 @@
 
 
 
-
-
-
-
-
-
 def get_script_args(dist, executable=sys_executable):
     """Yield write_script() argument tuples for a distribution's entrypoints"""
     spec = str(dist.as_requirement())


More information about the Python-checkins mailing list