[Python-checkins] distutils2 (merge default -> default): Branch merge

eric.araujo python-checkins at python.org
Fri Feb 10 05:11:17 CET 2012


http://hg.python.org/distutils2/rev/8aca92f2fc25
changeset:   1280:8aca92f2fc25
parent:      1277:b024621a1be6
parent:      1279:0d519c01b850
user:        Éric Araujo <merwok at netwok.org>
date:        Thu Feb 09 18:45:37 2012 +0100
summary:
  Branch merge

files:
  distutils2/command/__init__.py   |  48 +++++++------------
  distutils2/run.py                |   9 +--
  distutils2/tests/test_markers.py |  10 ++-
  distutils2/tests/test_run.py     |  28 ++++++++++-
  4 files changed, 53 insertions(+), 42 deletions(-)


diff --git a/distutils2/command/__init__.py b/distutils2/command/__init__.py
--- a/distutils2/command/__init__.py
+++ b/distutils2/command/__init__.py
@@ -6,38 +6,28 @@
 __all__ = ['get_command_names', 'set_command', 'get_command_class',
            'STANDARD_COMMANDS']
 
-_COMMANDS = {
-    'check': 'distutils2.command.check.check',
-    'test': 'distutils2.command.test.test',
-    'build': 'distutils2.command.build.build',
-    'build_py': 'distutils2.command.build_py.build_py',
-    'build_ext': 'distutils2.command.build_ext.build_ext',
-    'build_clib': 'distutils2.command.build_clib.build_clib',
-    'build_scripts': 'distutils2.command.build_scripts.build_scripts',
-    'clean': 'distutils2.command.clean.clean',
-    'install_dist': 'distutils2.command.install_dist.install_dist',
-    'install_lib': 'distutils2.command.install_lib.install_lib',
-    'install_headers': 'distutils2.command.install_headers.install_headers',
-    'install_scripts': 'distutils2.command.install_scripts.install_scripts',
-    'install_data': 'distutils2.command.install_data.install_data',
-    'install_distinfo':
-        'distutils2.command.install_distinfo.install_distinfo',
-    'sdist': 'distutils2.command.sdist.sdist',
-    'bdist': 'distutils2.command.bdist.bdist',
-    'bdist_dumb': 'distutils2.command.bdist_dumb.bdist_dumb',
-    'bdist_wininst': 'distutils2.command.bdist_wininst.bdist_wininst',
-    'register': 'distutils2.command.register.register',
-    'upload': 'distutils2.command.upload.upload',
-    'upload_docs': 'distutils2.command.upload_docs.upload_docs',
-}
 
-# XXX this is crappy
+STANDARD_COMMANDS = [
+    # packaging
+    'check', 'test',
+    # building
+    'build', 'build_py', 'build_ext', 'build_clib', 'build_scripts', 'clean',
+    # installing
+    'install_dist', 'install_lib', 'install_headers', 'install_scripts',
+    'install_data', 'install_distinfo',
+    # distributing
+    'sdist', 'bdist', 'bdist_dumb', 'bdist_wininst',
+    'register', 'upload', 'upload_docs',
+    ]
+
 if os.name == 'nt':
-    _COMMANDS['bdist_msi'] = 'distutils2.command.bdist_msi.bdist_msi'
+    STANDARD_COMMANDS.insert(STANDARD_COMMANDS.index('bdist_wininst'),
+                             'bdist_msi')
 
-# XXX use OrderedDict to preserve the grouping (build-related, install-related,
-# distribution-related)
-STANDARD_COMMANDS = set(_COMMANDS)
+# XXX maybe we need more than one registry, so that --list-comands can display
+# standard, custom and overriden standard commands differently
+_COMMANDS = dict((name, 'distutils2.command.%s.%s' % (name, name))
+                 for name in STANDARD_COMMANDS)
 
 
 def get_command_names():
diff --git a/distutils2/run.py b/distutils2/run.py
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -254,16 +254,13 @@
     parser = dispatcher.parser
     args = args[1:]
 
-    commands = STANDARD_COMMANDS  # + extra commands
+    commands = STANDARD_COMMANDS  # FIXME display extra commands
 
     if args == ['--list-commands']:
         print 'List of available commands:'
-        cmds = sorted(commands)
-
-        for cmd in cmds:
+        for cmd in commands:
             cls = dispatcher.cmdclass.get(cmd) or get_command_class(cmd)
-            desc = getattr(cls, 'description',
-                            '(no description available)')
+            desc = getattr(cls, 'description', '(no description available)')
             print '  %s: %s' % (cmd, desc)
         return
 
diff --git a/distutils2/tests/test_markers.py b/distutils2/tests/test_markers.py
--- a/distutils2/tests/test_markers.py
+++ b/distutils2/tests/test_markers.py
@@ -22,8 +22,6 @@
 
         self.assertTrue(interpret("sys.platform == '%s'" % sys_platform))
         self.assertTrue(interpret(
-            "sys.platform == '%s' or python_version == '2.4'" % sys_platform))
-        self.assertTrue(interpret(
             "sys.platform == '%s' and python_full_version == '%s'" %
             (sys_platform, version)))
         self.assertTrue(interpret("'%s' == sys.platform" % sys_platform))
@@ -42,12 +40,18 @@
 
         # combined operations
         OP = 'os.name == "%s"' % os_name
+        FALSEOP = 'os.name == "buuuu"'
         AND = ' and '
         OR = ' or '
         self.assertTrue(interpret(OP + AND + OP))
         self.assertTrue(interpret(OP + AND + OP + AND + OP))
         self.assertTrue(interpret(OP + OR + OP))
-        self.assertTrue(interpret(OP + OR + OP + OR + OP))
+        self.assertTrue(interpret(OP + OR + FALSEOP))
+        self.assertTrue(interpret(OP + OR + OP + OR + FALSEOP))
+        self.assertTrue(interpret(OP + OR + FALSEOP + OR + FALSEOP))
+        self.assertTrue(interpret(FALSEOP + OR + OP))
+        self.assertFalse(interpret(FALSEOP + AND + FALSEOP))
+        self.assertFalse(interpret(FALSEOP + OR + FALSEOP))
 
         # other operators
         self.assertTrue(interpret("os.name != 'buuuu'"))
diff --git a/distutils2/tests/test_run.py b/distutils2/tests/test_run.py
--- a/distutils2/tests/test_run.py
+++ b/distutils2/tests/test_run.py
@@ -60,22 +60,42 @@
             os.chmod(install_path, old_mod)
             install.get_path = old_get_path
 
-    def test_show_help(self):
-        # smoke test, just makes sure some help is displayed
+    def get_pythonpath(self):
         pythonpath = os.environ.get('PYTHONPATH')
         d2parent = os.path.dirname(os.path.dirname(__file__))
         if pythonpath is not None:
-            pythonpath =  os.pathsep.join((pythonpath, d2parent))
+            pythonpath = os.pathsep.join((pythonpath, d2parent))
         else:
             pythonpath = d2parent
+        return pythonpath
 
+    def test_show_help(self):
+        # smoke test, just makes sure some help is displayed
         status, out, err = assert_python_ok(
             '-c', 'from distutils2.run import main; main()', '--help',
-            PYTHONPATH=pythonpath)
+            PYTHONPATH=self.get_pythonpath())
         self.assertEqual(status, 0)
         self.assertGreater(out, '')
         self.assertEqual(err, '')
 
+    def test_list_commands(self):
+        status, out, err = assert_python_ok(
+            '-c', 'from distutils2.run import main; main()', 'run',
+            '--list-commands', PYTHONPATH=self.get_pythonpath())
+        # check that something is displayed
+        self.assertEqual(status, 0)
+        self.assertGreater(out, '')
+        self.assertEqual(err, '')
+
+        # make sure the manual grouping of commands is respected
+        check_position = out.find('  check: ')
+        build_position = out.find('  build: ')
+        self.assertTrue(check_position, out)  # "out" printed as debugging aid
+        self.assertTrue(build_position, out)
+        self.assertLess(check_position, build_position, out)
+
+        # TODO test that custom commands don't break --list-commands
+
 
 def test_suite():
     return unittest.makeSuite(RunTestCase)

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


More information about the Python-checkins mailing list