[Python-checkins] python/nondist/sandbox/setuptools/setuptools/command easy_install.py, 1.5, 1.6

pje@users.sourceforge.net pje at users.sourceforge.net
Sun Jul 10 07:29:46 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4863/setuptools/command

Modified Files:
	easy_install.py 
Log Message:
EasyInstall now builds eggs in a temporary directory alongside the setup
script it's running.  This avoids it getting confused by projects with
non-standard distribution locations, and projects that may have various
eggs already sitting in their distribution directory.  It should probably
also do something like this for the build directory to ensure a clean,
fresh build, but it seems like overkill, since it only affects local
projects, not stuff that EasyInstall downloaded in the first place.


Index: easy_install.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/easy_install.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- easy_install.py	10 Jul 2005 05:06:31 -0000	1.5
+++ easy_install.py	10 Jul 2005 05:29:44 -0000	1.6
@@ -12,7 +12,7 @@
 """
 
 import sys, os.path, zipimport, shutil, tempfile, zipfile
-
+from glob import glob
 from setuptools import Command
 from setuptools.sandbox import run_setup
 from distutils import log, dir_util
@@ -412,21 +412,21 @@
         # .egg dirs or files are already built, so just return them
         if dist_filename.lower().endswith('.egg'):
             return [self.install_egg(dist_filename, True, tmpdir)]
-
-        if dist_filename.lower().endswith('.exe'):
+        elif dist_filename.lower().endswith('.exe'):
             return [self.install_exe(dist_filename, tmpdir)]
 
         # Anything else, try to extract and build
+        setup_base = tmpdir
         if os.path.isfile(dist_filename):
             unpack_archive(dist_filename, tmpdir, self.unpack_progress)
         elif os.path.isdir(dist_filename):
-            tmpdir = dist_filename  # ugh
+            setup_base = os.path.abspath(dist_filename)
 
         # Find the setup.py file
-        from glob import glob
-        setup_script = os.path.join(tmpdir, 'setup.py')
+        setup_script = os.path.join(setup_base, 'setup.py')
+
         if not os.path.exists(setup_script):
-            setups = glob(os.path.join(tmpdir, '*', 'setup.py'))
+            setups = glob(os.path.join(setup_base, '*', 'setup.py'))
             if not setups:
                 raise DistutilsError(
                     "Couldn't find a setup script in %s" % dist_filename
@@ -437,17 +437,17 @@
                 )
             setup_script = setups[0]
 
-        self.build_egg(tmpdir, setup_script)
-        dist_dir = os.path.join(os.path.dirname(setup_script),'dist')   # XXX
+        # Now run it, and return the result
+        return self.build_and_install(setup_script, setup_base, zip_ok)
+
+
+
+
+
+
 
-        eggs = []
-        for egg in glob(os.path.join(dist_dir,'*.egg')):
-            eggs.append(self.install_egg(egg, zip_ok, tmpdir))
 
-        if not eggs and not self.dry_run:
-            log.warn("No eggs found in %s (setup script problem?)", dist_dir)
 
-        return eggs
 
     def egg_distribution(self, egg_path):
         if os.path.isdir(egg_path):
@@ -695,10 +695,10 @@
 
 
 
-    def build_egg(self, tmpdir, setup_script):
+    def build_and_install(self, setup_script, setup_base, zip_ok):
         sys.modules.setdefault('distutils.command.bdist_egg', bdist_egg)
 
-        args = ['bdist_egg']
+        args = ['bdist_egg', '--dist-dir']
         if self.verbose>2:
             v = 'v' * self.verbose - 1
             args.insert(0,'-'+v)
@@ -707,33 +707,33 @@
         if self.dry_run:
             args.insert(0,'-n')
 
-        log.info("Running %s %s", setup_script[len(tmpdir)+1:], ' '.join(args))
+        dist_dir = tempfile.mkdtemp(prefix='egg-dist-tmp-', dir=setup_base)       
         try:
+            args.append(dist_dir)
+            log.info(
+                "Running %s %s", setup_script[len(setup_base)+1:],
+                ' '.join(args)
+            )
             try:
                 run_setup(setup_script, args)
             except SystemExit, v:
                 raise DistutilsError(
                     "Setup script exited with %s" % (v.args[0],)
                 )
-        finally:
-            log.set_verbosity(self.verbose) # restore our log verbosity
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 
+            eggs = []
+            for egg in glob(os.path.join(dist_dir,'*.egg')):
+                eggs.append(self.install_egg(egg, zip_ok, setup_base))
 
+            if not eggs and not self.dry_run:
+                log.warn("No eggs found in %s (setup script problem?)",
+                    dist_dir)
+               
+            return eggs
 
+        finally:
+            shutil.rmtree(dist_dir)
+            log.set_verbosity(self.verbose) # restore our log verbosity
 
 
     def update_pth(self,dist):



More information about the Python-checkins mailing list