[Python-checkins] distutils2: added optparse in the main script

tarek.ziade python-checkins at python.org
Sun Nov 14 00:53:17 CET 2010


tarek.ziade pushed 4d89abd0d6db to distutils2:

http://hg.python.org/distutils2/rev/4d89abd0d6db
changeset:   824:4d89abd0d6db
tag:         tip
user:        Tarek Ziade <tarek at ziade.org>
date:        Sun Nov 14 00:52:51 2010 +0100
summary:     added optparse in the main script
files:       distutils2/dist.py, distutils2/run.py, distutils2/tests/test_dist.py

diff --git a/distutils2/dist.py b/distutils2/dist.py
--- a/distutils2/dist.py
+++ b/distutils2/dist.py
@@ -389,10 +389,7 @@
         This includes options that are recognized *only* at the top
         level as well as options recognized for commands.
         """
-        return self.global_options + [
-            ("command-packages=", None,
-             "list of packages that provide distutils commands"),
-            ]
+        return self.global_options
 
     def _parse_command_opts(self, parser, args):
         """Parse the command-line options for a single command.
diff --git a/distutils2/run.py b/distutils2/run.py
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -1,10 +1,12 @@
 import os
 import sys
+from optparse import OptionParser
 
 from distutils2.util import grok_environment_error
 from distutils2.errors import (DistutilsSetupError, DistutilsArgError,
                                DistutilsError, CCompilerError)
 from distutils2.dist import Distribution
+from distutils2 import __version__
 
 # This is a barebones help message generated displayed when the user
 # runs the setup script with no arguments at all.  More useful help
@@ -23,7 +25,7 @@
     return USAGE % {'script': script}
 
 
-def main(**attrs):
+def commands_main(**attrs):
     """The gateway to the Distutils: do everything your setup script needs
     to do, in a highly flexible and user-driven way.  Briefly: create a
     Distribution instance; find and parse config files; parse the command
@@ -110,5 +112,24 @@
     return dist
 
 
+def main():
+    """Main entry point for Distutils2"""
+    parser = OptionParser()
+    parser.disable_interspersed_args()
+    parser.add_option("-v", "--version",
+                  action="store_true", dest="version", default=False,
+                  help="Prints out the version of Distutils2 and exits.")
+
+    options, args = parser.parse_args()
+    if options.version:
+        print('Distutils2 %s' % __version__)
+        sys.exit(0)
+
+    if len(args) == 0:
+        parser.print_help()
+
+    commands_main()
+    sys.exit(0)
+
 if __name__ == '__main__':
     main()
diff --git a/distutils2/tests/test_dist.py b/distutils2/tests/test_dist.py
--- a/distutils2/tests/test_dist.py
+++ b/distutils2/tests/test_dist.py
@@ -248,10 +248,7 @@
             [test_dist]
             pre-hook.test = nonexistent.dotted.name'''))
 
-        sys.argv.extend(["--command-packages",
-                         "distutils2.tests",
-                         "test_dist"])
-
+        set_command('distutils2.tests.test_dist.test_dist')
         d = create_distribution([config_file])
         cmd = d.get_command_obj("test_dist")
         cmd.ensure_finalized()

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


More information about the Python-checkins mailing list