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

pje at users.sourceforge.net pje at users.sourceforge.net
Sat Apr 2 04:43:23 CEST 2005


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

Modified Files:
	bdist_egg.py 
Log Message:
Rough draft of version requirement parser.  Make bdist_egg look for a
distname.egg-info directory instead of EGG-INFO.in; this will be used later
to support development of egg-distributed packages that an application
under development expects to 'require()'.  (Thanks to Fred Drake for
pointing out this use case, and Bob Ippolito for helping me figure out how
to support it, although the runtime support doesn't actually exist yet.)


Index: bdist_egg.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/bdist_egg.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- bdist_egg.py	22 Mar 2005 18:55:59 -0000	1.5
+++ bdist_egg.py	2 Apr 2005 02:43:20 -0000	1.6
@@ -3,7 +3,6 @@
 Build .egg distributions"""
 
 # This module should be kept compatible with Python 2.3
-
 import os
 from distutils.core import Command
 from distutils.util import get_platform
@@ -11,14 +10,15 @@
 from distutils.sysconfig import get_python_version
 from distutils.errors import *
 from distutils import log
+from pkg_resources import parse_requirements
 
 class bdist_egg(Command):
 
     description = "create an \"egg\" distribution"
 
-    user_options = [('egg-info=', 'e',
-                     "directory containing EGG-INFO for the distribution "
-                     "(default: EGG-INFO.in)"),
+    user_options = [('egg-base=', 'e',
+                     "directory containing .egg-info directories"
+                     "(default: top of the source tree)"),
                     ('bdist-dir=', 'd',
                      "temporary directory for creating the distribution"),
                     ('plat-name=', 'p',
@@ -40,6 +40,9 @@
 
 
     def initialize_options (self):
+        self.egg_name = None
+        self.egg_version = None
+        self.egg_base = None
         self.egg_info = None
         self.bdist_dir = None
         self.plat_name = None
@@ -47,27 +50,35 @@
         self.dist_dir = None
         self.skip_build = 0
         self.relative = 0
-        
-    # initialize_options()
 
 
     def finalize_options (self):
+        self.egg_name = self.distribution.get_name().replace('-','_')
+        self.egg_version = self.distribution.get_version().replace('-','_')
+        try:
+            list(
+                parse_requirements('%s==%s' % (self.egg_name,self.egg_version))
+            )
+        except ValueError:
+            raise DistutilsOptionError(
+                "Invalid distribution name or version syntax: %s-%s" %
+                (self.egg_name,self.egg_version)
+            )
+        if self.egg_base is None:
+            dirs = self.distribution.package_dir
+            self.egg_base = (dirs or {}).get('','.')
 
-        if self.egg_info is None and os.path.isdir('EGG-INFO.in'):
-            self.egg_info = 'EGG-INFO.in'
-
-        elif self.egg_info:
-            self.ensure_dirname('egg_info')
-
+        self.ensure_dirname('egg_base')
+        self.egg_info = os.path.join(
+            self.egg_base, self.egg_name+'.egg-info'
+        )
         if self.bdist_dir is None:
             bdist_base = self.get_finalized_command('bdist').bdist_base
             self.bdist_dir = os.path.join(bdist_base, 'egg')
-
         self.set_undefined_options('bdist',
                                    ('dist_dir', 'dist_dir'),
                                    ('plat_name', 'plat_name'))
 
-    # finalize_options()
 
     def write_stub(self, resource, pyfile):
         f = open(pyfile,'w')
@@ -84,9 +95,33 @@
         ]))
         f.close()
 
-        
-    def run (self):
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    def run(self):
         if not self.skip_build:
             self.run_command('build')
 
@@ -113,46 +148,50 @@
 
         if to_compile:
             install.byte_compile(to_compile)
-            
+
         # And make an archive relative to the root of the
         # pseudo-installation tree.
-        archive_basename = "%s-py%s" % (self.distribution.get_fullname(),
+        archive_basename = "%s-%s-py%s" % (self.egg_name, self.egg_version,
                                       get_python_version())
 
         if ext_outputs:
             archive_basename += "-" + self.plat_name
 
         # OS/2 objects to any ":" characters in a filename (such as when
-        # a timestamp is used in a version) so change them to hyphens.
+        # a timestamp is used in a version) so change them to underscores.
         if os.name == "os2":
-            archive_basename = archive_basename.replace(":", "-")
+            archive_basename = archive_basename.replace(":", "_")
 
         pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
         archive_root = self.bdist_dir
 
         # Make the EGG-INFO directory
-        log.info("creating EGG-INFO directory")
         egg_info = os.path.join(archive_root,'EGG-INFO')
         self.mkpath(egg_info)
+        self.mkpath(self.egg_info)
 
-        if self.egg_info:
-            for filename in os.listdir(self.egg_info):
-                path = os.path.join(self.egg_info,filename)
-                if os.path.isfile(path):
-                    self.copy_file(path,os.path.join(egg_info,filename))
-
-        log.info("writing EGG-INFO/PKG-INFO")
+        log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO'))
         if not self.dry_run:
-            self.distribution.metadata.write_pkg_info(egg_info)
+            self.distribution.metadata.write_pkg_info(self.egg_info)
 
+        native_libs = os.path.join(self.egg_info,"native_libs.txt")
         if ext_outputs:
-            log.info("writing EGG-INFO/native_libs.txt")
+            log.info("writing %s" % native_libs)
             if not self.dry_run:
-                libs_file = open(
-                    os.path.join(egg_info,"native_libs.txt"),'wt')
+                libs_file = open(native_libs, 'wt')
                 libs_file.write('\n'.join(ext_outputs))
                 libs_file.write('\n')
                 libs_file.close()
+        elif os.path.isfile(native_libs):
+            log.info("removing %s" % native_libs)
+            if not self.dry_run:
+                os.unlink(native_libs)
+
+        if self.egg_info:
+            for filename in os.listdir(self.egg_info):
+                path = os.path.join(self.egg_info,filename)
+                if os.path.isfile(path):
+                    self.copy_file(path,os.path.join(egg_info,filename))
 
         # Make the archive
         make_zipfile(pseudoinstall_root+'.egg',
@@ -162,10 +201,6 @@
         if not self.keep_temp:
             remove_tree(self.bdist_dir, dry_run=self.dry_run)
 
-    # run()
-
-# class bdist_egg
-
 
 
 def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0):
@@ -176,7 +211,7 @@
     raises DistutilsExecError.  Returns the name of the output zip file.
     """
     import zipfile
-        
+
     mkpath(os.path.dirname(zip_filename), dry_run=dry_run)
 
     # If zipfile module is not available, try spawning an external
@@ -203,3 +238,9 @@
 
 # make_zipfile ()
 
+
+
+
+
+
+



More information about the Python-checkins mailing list