[Python-checkins] distutils2: added the manifest_builders option

tarek.ziade python-checkins at python.org
Sun Nov 7 22:09:52 CET 2010


tarek.ziade pushed 3cf9c07abc11 to distutils2:

http://hg.python.org/distutils2/rev/3cf9c07abc11
changeset:   805:3cf9c07abc11
tag:         tip
user:        Tarek Ziade <tarek at ziade.org>
date:        Sun Nov 07 22:09:11 2010 +0100
summary:     added the manifest_builders option
files:       distutils2/command/sdist.py, distutils2/tests/test_command_sdist.py

diff --git a/distutils2/command/sdist.py b/distutils2/command/sdist.py
--- a/distutils2/command/sdist.py
+++ b/distutils2/command/sdist.py
@@ -17,10 +17,10 @@
 
 from distutils2.command.cmd import Command
 from distutils2.errors import (DistutilsPlatformError, DistutilsOptionError,
-                               DistutilsTemplateError)
+                               DistutilsTemplateError, DistutilsModuleError)
 from distutils2.manifest import Manifest
 from distutils2 import logger
-from distutils2.util import convert_path
+from distutils2.util import convert_path, resolve_name
 
 def show_formats():
     """Print all possible values for the 'formats' option (used by
@@ -73,6 +73,8 @@
          "Owner name used when creating a tar file [default: current user]"),
         ('group=', 'g',
          "Group name used when creating a tar file [default: current group]"),
+        ('manifest-builders=', None,
+         "manifest builders (comma-separated list)"),
         ]
 
     boolean_options = ['use-defaults', 'prune',
@@ -89,6 +91,7 @@
     default_format = {'posix': 'gztar',
                       'nt': 'zip' }
 
+
     def initialize_options(self):
         self.manifest = None
 
@@ -106,6 +109,7 @@
         self.owner = None
         self.group = None
         self.filelist = None
+        self.manifest_builders = None
 
     def _check_archive_formats(self, formats):
         supported_formats = [name for name, desc in get_archive_formats()]
@@ -138,6 +142,25 @@
         if self.filelist is None:
             self.filelist = Manifest()
 
+        if self.manifest_builders is None:
+            self.manifest_builders = []
+        else:
+            if isinstance(self.manifest_builders, str):
+                self.manifest_builders = self.manifest_builders.split(',')
+            builders = []
+            for builder in self.manifest_builders:
+                builder = builder.strip()
+                if builder == '':
+                    continue
+                try:
+                    builder = resolve_name(builder)
+                except ImportError, e:
+                    raise DistutilsModuleError(e)
+
+                builders.append(builder)
+
+            self.manifest_builders = builders
+
 
     def run(self):
         # 'filelist' contains the list of files that will make up the
@@ -178,6 +201,11 @@
         if template_exists:
             template = '\n'.join(self.distribution.extra_files)
             self.filelist.read_template(StringIO(template))
+
+        # call manifest builders, if any.
+        for builder in self.manifest_builders:
+            builder(self.filelist)
+
         if self.prune:
             self.prune_file_list()
 
diff --git a/distutils2/tests/test_command_sdist.py b/distutils2/tests/test_command_sdist.py
--- a/distutils2/tests/test_command_sdist.py
+++ b/distutils2/tests/test_command_sdist.py
@@ -56,6 +56,10 @@
 somecode%(sep)sdoc.txt
 """
 
+def builder(filelist):
+    filelist.append('bah')
+
+
 class SDistTestCase(support.TempdirManager, support.LoggingCatcher,
                     support.EnvironGuard, unittest.TestCase):
 
@@ -428,6 +432,13 @@
 
         self.assertIn('yeah', content)
 
+    def test_manifest_builder(self):
+        dist, cmd = self.get_cmd()
+        cmd.manifest_builders = 'distutils2.tests.test_command_sdist.builder'
+        cmd.ensure_finalized()
+        cmd.run()
+        self.assertIn('bah', cmd.filelist.files)
+
 
 def test_suite():
     return unittest.makeSuite(SDistTestCase)

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


More information about the Python-checkins mailing list