Commits

Éric Araujo committed 70831fd

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.

Comments (0)

Files changed (4)

 - #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
 ------------------
 - Pierre Paul Lefebvre
 - Tshepang Lekhonkhobe
 - Alain Leufroy
+- Janusz Lewandowski
 - Martin von Löwis
 - Hugo Lopes Tavares
 - Guillermo López-Anglada

distutils2/run.py

 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
     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']:
         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
 
     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_:

distutils2/tests/test_run.py

 
 import os
 import sys
+import textwrap
 from StringIO import StringIO
 
 from distutils2 import install
                   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
 
         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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.