diff options
author | ?ric Araujo <merwok@netwok.org> | 2012-05-21 15:51:11 -0400 |
---|---|---|
committer | ?ric Araujo <merwok@netwok.org> | 2012-05-21 15:51:11 -0400 |
commit | 1ed1781f2170be33392c3056f239766b1b1c6a58 (patch) | |
tree | 7f0899fd86e8f57415780fa94b32fe7a4c58383f | |
parent | ccac6d901da2334a65bfa69333796d0b350a23c4 (diff) | |
download | disutils2-1ed1781f2170be33392c3056f239766b1b1c6a58.tar.gz |
Have pysetup read setup.cfg early to find custom commands (#14733).
Independently found and fixed by me (with help from Luis Rojas) and
Janusz Lewandowski.
-rw-r--r-- | CHANGES.txt | 2 | ||||
-rw-r--r-- | CONTRIBUTORS.txt | 1 | ||||
-rw-r--r-- | distutils2/run.py | 23 | ||||
-rw-r--r-- | distutils2/tests/test_run.py | 42 |
4 files changed, 47 insertions, 21 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 77fb232..2a00895 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,6 +19,8 @@ CONTRIBUTORS.txt for full names. Bug numbers refer to http://bugs.python.org/. - #13399: Display error message instead of unhandled traceback for missing actions, commands and options [patrice] - #10374: Recreate scripts everytime build_scripts is called [pierre paul] +- #14733: Have pysetup read setup.cfg early enough to find custom commands + [éric, janusz] 1.0a4 - 2012-03-13 ------------------ diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 164c3a1..8f8e059 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -48,6 +48,7 @@ Thanks to: - Pierre Paul Lefebvre - Tshepang Lekhonkhobe - Alain Leufroy +- Janusz Lewandowski - Martin von Löwis - Hugo Lopes Tavares - Guillermo López-Anglada diff --git a/distutils2/run.py b/distutils2/run.py index 71fbe03..5721570 100644 --- a/distutils2/run.py +++ b/distutils2/run.py @@ -10,6 +10,7 @@ from distutils2 import logger from distutils2.dist import Distribution from distutils2.util import _is_archive_file, generate_setup_py from distutils2.command import get_command_class, STANDARD_COMMANDS +from distutils2.command.cmd import Command from distutils2.install import install, install_local_project, remove from distutils2.database import get_distribution, get_distributions from distutils2.depgraph import generate_graph @@ -254,6 +255,13 @@ def _run(dispatcher, args, **kw): parser = dispatcher.parser args = args[1:] + # Find and parse the config file(s): they will override options from + # the setup script, but be overridden by the command line. + # XXX call the functions from config and kill the Distribution class + # (merging it into Dispatcher) + dist = Distribution() + dist.parse_config_files() + commands = STANDARD_COMMANDS # FIXME display extra commands if args == ['--list-commands']: @@ -269,16 +277,6 @@ def _run(dispatcher, args, **kw): if args is None: return - # create the Distribution class - # need to feed setup.cfg here ! - dist = Distribution() - - # Find and parse the config file(s): they will override options from - # the setup script, but be overridden by the command line. - - # XXX still need to be extracted from Distribution - dist.parse_config_files() - for cmd in dispatcher.commands: # FIXME need to catch MetadataMissingError here (from the check command # e.g.)--or catch any exception, print an error message and exit with 1 @@ -547,9 +545,8 @@ class Dispatcher(object): def _show_help(self, parser, global_options_=True, display_options_=True, commands=[]): - # late import because of mutual dependence between these modules - from distutils2.command.cmd import Command - + # XXX want to print to stdout when help is requested (--help) but to + # stderr in case of error! print 'Usage: pysetup [options] action [action_options]' print if global_options_: diff --git a/distutils2/tests/test_run.py b/distutils2/tests/test_run.py index cc58818..eacec91 100644 --- a/distutils2/tests/test_run.py +++ b/distutils2/tests/test_run.py @@ -2,6 +2,7 @@ import os import sys +import textwrap from StringIO import StringIO from distutils2 import install @@ -31,14 +32,7 @@ class RunTestCase(support.TempdirManager, support.LoggingCatcher, unittest.TestCase): - def setUp(self): - super(RunTestCase, self).setUp() - self.old_argv = sys.argv, sys.argv[:] - - def tearDown(self): - sys.argv = self.old_argv[0] - sys.argv[:] = self.old_argv[1] - super(RunTestCase, self).tearDown() + maxDiff = None # TODO restore the tests removed six months ago and port them to pysetup @@ -127,6 +121,38 @@ class RunTestCase(support.TempdirManager, self.assertEqual(err.splitlines(), ["error: action 'invalid_action' not recognized"]) + def test_setupcfg_parsing(self): + # #14733: pysetup used to parse setup.cfg too late + project_dir = self.mkdtemp() + os.chdir(project_dir) + custompy = textwrap.dedent( + """\ + from distutils2.command.cmd import Command + + class custom(Command): + + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + print 'custom: ok' + """) + setupcfg = textwrap.dedent( + """\ + [global] + commands = custom.custom + """) + self.write_file('custom.py', custompy) + self.write_file('setup.cfg', setupcfg) + + out, err = self.call_pysetup('run', 'custom') + self.assertEqual(out.splitlines(), ['custom: ok']) + def test_suite(): return unittest.makeSuite(RunTestCase) |