[Python-checkins] distutils2: now sub_commands can be configure in the .cfg files
tarek.ziade
python-checkins at python.org
Sun Nov 7 20:35:16 CET 2010
tarek.ziade pushed 920ed1cb6df2 to distutils2:
http://hg.python.org/distutils2/rev/920ed1cb6df2
changeset: 804:920ed1cb6df2
tag: tip
user: Tarek Ziade <tarek at ziade.org>
date: Sun Nov 07 20:33:48 2010 +0100
summary: now sub_commands can be configure in the .cfg files
files: distutils2/command/cmd.py, distutils2/command/install_dist.py, distutils2/command/install_scripts.py, distutils2/config.py, distutils2/tests/test_config.py
diff --git a/distutils2/command/cmd.py b/distutils2/command/cmd.py
--- a/distutils2/command/cmd.py
+++ b/distutils2/command/cmd.py
@@ -359,9 +359,13 @@
run for the current distribution. Return a list of command names.
"""
commands = []
- for (cmd_name, method) in self.sub_commands:
- if method is None or method(self):
- commands.append(cmd_name)
+ for sub_command in self.sub_commands:
+ if len(sub_command) == 2:
+ cmd_name, method = sub_command
+ if method is None or method(self):
+ commands.append(cmd_name)
+ else:
+ commands.append(sub_command)
return commands
diff --git a/distutils2/command/install_dist.py b/distutils2/command/install_dist.py
--- a/distutils2/command/install_dist.py
+++ b/distutils2/command/install_dist.py
@@ -520,6 +520,7 @@
raise DistutilsPlatformError("Can't install when "
"cross-compiling")
+
# Run all sub-commands (at least those that need to be run)
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
diff --git a/distutils2/command/install_scripts.py b/distutils2/command/install_scripts.py
--- a/distutils2/command/install_scripts.py
+++ b/distutils2/command/install_scripts.py
@@ -40,6 +40,11 @@
def run (self):
if not self.skip_build:
self.run_command('build_scripts')
+
+ if not os.path.exists(self.build_dir):
+ self.outfiles = []
+ return
+
self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
if os.name == 'posix':
# Set the executable bits (owner, group, and world) on
@@ -57,5 +62,3 @@
def get_outputs(self):
return self.outfiles or []
-
-# class install_scripts
diff --git a/distutils2/config.py b/distutils2/config.py
--- a/distutils2/config.py
+++ b/distutils2/config.py
@@ -185,6 +185,7 @@
logger.debug("Distribution.parse_config_files():")
parser = RawConfigParser()
+
for filename in filenames:
logger.debug(" reading %s" % filename)
parser.read(filename)
@@ -197,26 +198,29 @@
opt_dict = self.dist.get_option_dict(section)
for opt in options:
- if opt != '__name__':
- val = parser.get(section, opt)
- opt = opt.replace('-', '_')
+ if opt == '__name__':
+ continue
+ val = parser.get(section, opt)
+ opt = opt.replace('-', '_')
+ if opt == 'sub_commands':
+ val = self._multiline(val)
+ if isinstance(val, str):
+ val = [val]
- # XXX this is not used ...
-
- # Hooks use a suffix system to prevent being overriden
- # by a config file processed later (i.e. a hook set in
- # the user config file cannot be replaced by a hook
- # set in a project config file, unless they have the
- # same suffix).
- if (opt.startswith("pre_hook.") or
- opt.startswith("post_hook.")):
- hook_type, alias = opt.split(".")
- hook_dict = opt_dict.setdefault(hook_type,
- (filename, {}))[1]
- hook_dict[alias] = val
- else:
- opt_dict[opt] = (filename, val)
+ # Hooks use a suffix system to prevent being overriden
+ # by a config file processed later (i.e. a hook set in
+ # the user config file cannot be replaced by a hook
+ # set in a project config file, unless they have the
+ # same suffix).
+ if (opt.startswith("pre_hook.") or
+ opt.startswith("post_hook.")):
+ hook_type, alias = opt.split(".")
+ hook_dict = opt_dict.setdefault(hook_type,
+ (filename, {}))[1]
+ hook_dict[alias] = val
+ else:
+ opt_dict[opt] = filename, val
# Make the RawConfigParser forget everything (so we retain
# the original filenames that options come from)
diff --git a/distutils2/tests/test_config.py b/distutils2/tests/test_config.py
--- a/distutils2/tests/test_config.py
+++ b/distutils2/tests/test_config.py
@@ -77,6 +77,9 @@
foo = distutils2.tests.test_config.Foo
setup_hook = distutils2.tests.test_config.hook
+
+[install_dist]
+sub_commands = foo
"""
@@ -85,9 +88,17 @@
class Foo(object):
+
+ def __init__(self, dist):
+ self.distribution = dist
+
def run(self):
+ self.distribution.foo_was_here = 1
+
+ def nothing(self):
pass
- finalize_options = initialize_options = run
+
+ ensure_finalized = finalize_options = initialize_options = nothing
class ConfigTestCase(support.TempdirManager,
@@ -96,6 +107,7 @@
def setUp(self):
super(ConfigTestCase, self).setUp()
self.addCleanup(setattr, sys, 'stdout', sys.stdout)
+ self.addCleanup(setattr, sys, 'stderr', sys.stderr)
self.addCleanup(os.chdir, os.getcwd())
def test_config(self):
@@ -167,6 +179,35 @@
# did the README got loaded ?
self.assertEquals(dist.metadata['description'], 'yeah')
+ def test_sub_commands(self):
+ tempdir = self.mkdtemp()
+ os.chdir(tempdir)
+ self.write_file('setup.cfg', SETUP_CFG)
+ self.write_file('README', 'yeah')
+ self.write_file('haven.py', '#')
+ self.write_file('script1.py', '#')
+ os.mkdir('scripts')
+ self.write_file(os.path.join('scripts', 'find-coconuts'), '#')
+ os.mkdir('bin')
+ self.write_file(os.path.join('bin', 'taunt'), '#')
+
+ for pkg in ('one', 'src', 'src2'):
+ os.mkdir(pkg)
+ self.write_file(os.path.join(pkg, '__init__.py'), '#')
+
+ # try to run the install command to see if foo is called
+ sys.stdout = sys.stderr = StringIO()
+ sys.argv[:] = ['', 'install_dist']
+ old_sys = sys.argv[:]
+ try:
+ from distutils2.run import main
+ dist = main()
+ finally:
+ sys.argv[:] = old_sys
+
+ self.assertEquals(dist.foo_was_here, 1)
+
+
def test_suite():
return unittest.makeSuite(ConfigTestCase)
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list