summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTarek Ziade <tarek@ziade.org>2010-11-07 22:09:11 +0100
committerTarek Ziade <tarek@ziade.org>2010-11-07 22:09:11 +0100
commitbfb821d7c29d9e883faa04b3a6b46e782e945009 (patch)
tree4dcfb9299feb0707144446deea69e38cf0f3162e
parent87d966414b6915c3724fb9a9da9c9cfaaba25202 (diff)
downloaddisutils2-bfb821d7c29d9e883faa04b3a6b46e782e945009.tar.gz
added the manifest_builders option
-rw-r--r--distutils2/command/sdist.py32
-rw-r--r--distutils2/tests/test_command_sdist.py11
2 files changed, 41 insertions, 2 deletions
diff --git a/distutils2/command/sdist.py b/distutils2/command/sdist.py
index b15f0a2..72fd6d0 100644
--- a/distutils2/command/sdist.py
+++ b/distutils2/command/sdist.py
@@ -17,10 +17,10 @@ except ImportError:
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 @@ class sdist(Command):
"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 @@ class sdist(Command):
default_format = {'posix': 'gztar',
'nt': 'zip' }
+
def initialize_options(self):
self.manifest = None
@@ -106,6 +109,7 @@ class sdist(Command):
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 @@ class sdist(Command):
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 @@ class sdist(Command):
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
index ae37cf5..29a3ec3 100644
--- a/distutils2/tests/test_command_sdist.py
+++ b/distutils2/tests/test_command_sdist.py
@@ -56,6 +56,10 @@ somecode%(sep)sdoc.dat
somecode%(sep)sdoc.txt
"""
+def builder(filelist):
+ filelist.append('bah')
+
+
class SDistTestCase(support.TempdirManager, support.LoggingCatcher,
support.EnvironGuard, unittest.TestCase):
@@ -428,6 +432,13 @@ class SDistTestCase(support.TempdirManager, support.LoggingCatcher,
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)