summaryrefslogtreecommitdiff
path: root/distutils2
diff options
context:
space:
mode:
authorTarek Ziade <tarek@ziade.org>2010-11-14 00:52:51 +0100
committerTarek Ziade <tarek@ziade.org>2010-11-14 00:52:51 +0100
commit899d530dfa97a609a84ae81fc9dc466e54cdfa38 (patch)
treed7a77f13f6eaef93c465d2c183274b3a333834d3 /distutils2
parentda85407945c9607a7af98aa29b6da788f3028253 (diff)
downloaddisutils2-899d530dfa97a609a84ae81fc9dc466e54cdfa38.tar.gz
added optparse in the main script
Diffstat (limited to 'distutils2')
-rw-r--r--distutils2/dist.py5
-rw-r--r--distutils2/run.py23
-rw-r--r--distutils2/tests/test_dist.py5
3 files changed, 24 insertions, 9 deletions
diff --git a/distutils2/dist.py b/distutils2/dist.py
index 67b3f8f..47bf750 100644
--- a/distutils2/dist.py
+++ b/distutils2/dist.py
@@ -389,10 +389,7 @@ Common commands: (see '--help-commands' for more)
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
index 26df90b..dbe7834 100644
--- 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 @@ def gen_usage(script_name):
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 @@ def main(**attrs):
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
index c9decf0..73ea544 100644
--- a/distutils2/tests/test_dist.py
+++ b/distutils2/tests/test_dist.py
@@ -248,10 +248,7 @@ class DistributionTestCase(support.TempdirManager,
[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()