[Python-checkins] distutils2: changed name from install_dist_info to install_distinfo for consistency

tarek.ziade python-checkins at python.org
Sun Aug 8 11:50:45 CEST 2010


tarek.ziade pushed 600504efa42b to distutils2:

http://hg.python.org/distutils2/rev/600504efa42b
changeset:   427:600504efa42b
user:        Josip Djolonga
date:        Sat Jul 17 18:02:01 2010 +0200
summary:     changed name from install_dist_info to install_distinfo for consistency
files:       src/distutils2/command/install.py, src/distutils2/command/install_dist_info.py, src/distutils2/command/install_distinfo.py

diff --git a/src/distutils2/command/install.py b/src/distutils2/command/install.py
--- a/src/distutils2/command/install.py
+++ b/src/distutils2/command/install.py
@@ -79,15 +79,26 @@
 
         ('record=', None,
          "filename in which to record list of installed files"),
+         
+        # .dist-info related arguments, read by install_dist_info
+        ('no-distinfo', None, 'do not create a .dist-info directory'),
+        ('distinfo-dir=', None,
+                           'directory where the the .dist-info directory will '
+                           'be installed'),
+        ('installer=', None, 'the name of the installer'),
+        ('requested', None, 'generate a REQUESTED file'),
+        ('no-requested', None, 'do not generate a REQUESTED file'),
+        ('no-distinfo-record', None, 'do not generate a RECORD file'),
         ]
 
-    boolean_options = ['compile', 'force', 'skip-build']
+    boolean_options = ['compile', 'force', 'skip-build', 'no-dist-info',
+                       'requested', 'no-dist-record',]
 
     user_options.append(('user', None,
                         "install in user site-package '%s'" % \
                             get_path('purelib', '%s_user' % os.name)))
     boolean_options.append('user')
-    negative_opt = {'no-compile' : 'compile'}
+    negative_opt = {'no-compile' : 'compile', 'no-requested': 'requested'}
 
 
     def initialize_options(self):
@@ -159,6 +170,13 @@
         #self.install_info = None
 
         self.record = None
+        
+        # .dist-info related options
+        self.no_distinfo = None
+        self.distinfo_dir = None
+        self.installer = None
+        self.requested = None
+        self.no_distinfo_record = None
 
 
     # -- Option finalizing methods -------------------------------------
@@ -305,6 +323,9 @@
 
         # Punt on doc directories for now -- after all, we're punting on
         # documentation completely!
+        
+        if self.no_distinfo is None:
+            self.no_distinfo = False
 
     def dump_dirs(self, msg):
         """Dumps the list of user options."""
@@ -586,7 +607,7 @@
                     ('install_headers', has_headers),
                     ('install_scripts', has_scripts),
                     ('install_data',    has_data),
-                    # keep install_dist_info last, as it needs the record
+                    # keep install_distinfo last, as it needs the record
                     # with files to be completely generated
-                    ('install_dist_info', lambda self:True),
+                    ('install_distinfo', lambda self: not self.no_distinfo),
                    ]
diff --git a/src/distutils2/command/install_dist_info.py b/src/distutils2/command/install_distinfo.py
rename from src/distutils2/command/install_dist_info.py
rename to src/distutils2/command/install_distinfo.py
--- a/src/distutils2/command/install_dist_info.py
+++ b/src/distutils2/command/install_distinfo.py
@@ -1,51 +1,71 @@
 """
-distutils.command.install_dist_info
-===================================
+distutils.command.install_distinfo
+==================================
 
 :Author: Josip Djolonga
+
+This module implements the ``install_distinfo`` command that creates the
+``.dist-info`` directory for the distribution, as specified in :pep:`376`.
+Usually, you do not have to call this command directly, it gets called
+automatically by the ``install`` command.
 """
 
 from distutils2.command.cmd import Command
 from distutils2 import log
 from distutils2._backport.shutil import rmtree
 
+
 import csv
 import hashlib
 import os
 import re
 
-    
-class install_dist_info(Command):
+
+class install_distinfo(Command):
     """Install a .dist-info directory for the package"""
 
     description = 'Install a .dist-info directory for the package'
 
     user_options = [
-        ('dist-info-dir=', None, 
-                           'directory to install the .dist-info directory to'),
+        ('dist-info-dir=', None,
+                           'directory where the the .dist-info directory will '
+                           'be installed'),
         ('installer=', None, 'the name of the installer'),
-        ('no-dist-requested', None, 'do not generate a REQUESTED file'),
+        ('requested', None, 'generate a REQUESTED file'),
+        ('no-requested', None, 'do not generate a REQUESTED file'),
         ('no-dist-record', None, 'do not generate a RECORD file'),
     ]
-    
+
     boolean_options = [
-        'no-dist-requested',
+        'requested',
         'no-dist-record',
     ]
+    
+    negative_opt = {'no-requested': 'requested'}
 
     def initialize_options(self):
-        self.dist_info_dir = None
+        self.distinfo_dir = None
         self.installer = None
-        self.no_dist_requested = False
-        self.no_dist_record = False
+        self.requested = None
+        self.no_distinfo_record = None
 
     def finalize_options(self):
+        self.set_undefined_options('install',
+                                   ('distinfo_dir', 'distinfo_dir'),
+                                   ('installer', 'installer'),
+                                   ('requested', 'requested'),
+                                   ('no_distinfo_record', 'no_distinfo_record'))
+
         self.set_undefined_options('install_lib',
-                                   ('install_dir', 'dist_info_dir'))
+                                   ('install_dir', 'distinfo_dir'))
+        
+        if self.installer is None:
+            self.installer = 'distutils'
+        if self.requested is None:
+            self.requested = True
+        if self.no_distinfo_record is None:
+            self.no_distinfo_record = False
 
-        if self.installer is None:
-            self.installer = 'distribute'
-        
         metadata = self.distribution.metadata
 
         basename = "%s-%s.dist-info" % (
@@ -53,67 +73,71 @@
             to_filename(safe_version(metadata['Version'])),
         )
 
-        self.distinfo_dir = os.path.join(self.dist_info_dir, basename)
+        self.distinfo_dir = os.path.join(self.distinfo_dir, basename)
         self.outputs = []
 
     def run(self):
-        target = self.distinfo_dir
-        if os.path.isdir(target) and not os.path.islink(target) \
-           and not self.dry_run:
-           rmtree(target)
-        elif os.path.exists(target):
-            self.execute(os.unlink, (self.distinfo_dir,), "Removing " + target)
+        if not self.dry_run:
+            target = self.distinfo_dir
 
-        if not self.dry_run:
+            if os.path.isdir(target) and not os.path.islink(target):
+                rmtree(target)
+            elif os.path.exists(target):
+                self.execute(os.unlink, (self.distinfo_dir,),
+                             "Removing " + target)
+
             self.execute(os.makedirs, (target,), "Creating " + target)
 
             metadata_path = os.path.join(self.distinfo_dir, 'METADATA')
             log.info('Creating %s' % (metadata_path,))
             self.distribution.metadata.write(metadata_path)
             self.outputs.append(metadata_path)
-            
+
             installer_path = os.path.join(self.distinfo_dir, 'INSTALLER')
             log.info('Creating %s' % (installer_path,))
             f = open(installer_path, 'w')
-            f.write(self.installer)
-            f.close()
+            try:
+                f.write(self.installer)
+            finally:
+                f.close()
             self.outputs.append(installer_path)
 
-            if not self.no_dist_requested:
+            if self.requested:
                 requested_path = os.path.join(self.distinfo_dir, 'REQUESTED')
                 log.info('Creating %s' % (requested_path,))
                 f = open(requested_path, 'w')
                 f.close()
                 self.outputs.append(requested_path)
 
-            if not self.no_dist_record:
+            if not self.no_distinfo_record:
                 record_path = os.path.join(self.distinfo_dir, 'RECORD')
                 log.info('Creating %s' % (record_path,))
                 f = open(record_path, 'wb')
-                writer = csv.writer(f, delimiter=',',
-                                       lineterminator=os.linesep,
-                                       quotechar='"')
-                
-                install = self.get_finalized_command('install')
-                
-                for fpath in install.get_outputs():
-                    if fpath.endswith('.pyc') or fpath.endswith('.pyo'):
-                        # do not put size and md5 hash, as in PEP-376
-                        writer.writerow((fpath, '', ''))
-                    else:
-                        size = os.path.getsize(fpath)
-                        fd = open(fpath, 'r')
-                        hash = hashlib.md5()
-                        hash.update(fd.read())
-                        md5sum = hash.hexdigest()
-                        writer.writerow((fpath, md5sum, size))
-                
-                # add the RECORD file itself
-                writer.writerow((record_path, '', ''))
-                self.outputs.append(record_path)
+                try:
+                    writer = csv.writer(f, delimiter=',',
+                                           lineterminator=os.linesep,
+                                           quotechar='"')
 
-                f.close()
-                
+                    install = self.get_finalized_command('install')
+
+                    for fpath in install.get_outputs():
+                        if fpath.endswith('.pyc') or fpath.endswith('.pyo'):
+                            # do not put size and md5 hash, as in PEP-376
+                            writer.writerow((fpath, '', ''))
+                        else:
+                            size = os.path.getsize(fpath)
+                            fd = open(fpath, 'r')
+                            hash = hashlib.md5()
+                            hash.update(fd.read())
+                            md5sum = hash.hexdigest()
+                            writer.writerow((fpath, md5sum, size))
+
+                    # add the RECORD file itself
+                    writer.writerow((record_path, '', ''))
+                    self.outputs.append(record_path)
+                finally:
+                    f.close()
+
     def get_outputs(self):
         return self.outputs
 
@@ -122,6 +146,7 @@
 # can be replaced by importing them from pkg_resources once it is included
 # in the stdlib.
 
+
 def safe_name(name):
     """Convert an arbitrary string to a standard distribution name
 
@@ -136,7 +161,7 @@
     Spaces become dots, and all other non-alphanumeric characters become
     dashes, with runs of multiple dashes condensed to a single dash.
     """
-    version = version.replace(' ','.')
+    version = version.replace(' ', '.')
     return re.sub('[^A-Za-z0-9.]+', '-', version)
 
 
@@ -145,4 +170,4 @@
 
     Any '-' characters are currently replaced with '_'.
     """
-    return name.replace('-','_')
+    return name.replace('-', '_')

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list