[Python-checkins] distutils2: Remove --all options for pysetup actions metadata and list.

eric.araujo python-checkins at python.org
Mon Sep 19 15:12:39 CEST 2011


http://hg.python.org/distutils2/rev/534f05852780
changeset:   1162:534f05852780
user:        Éric Araujo <merwok at netwok.org>
date:        Mon Sep 19 03:18:36 2011 +0200
summary:
  Remove --all options for pysetup actions metadata and list.

When called without option (“-f field” or “--all”), “pysetup metadata”
didn’t do anything useful.  Now it prints out all metadata fields.
“pysetup list” without arguments already printed all installed
distributions found, so the option was superfluous.  Less typing, more
consistency, more happiness!

In addition, change “releases” for “projects” in the description of the
list action.  Strictly speaking, one installed distribution satisfies
the requirement for a release (i.e. version) of a project, but as
currently only one release per project can be installed at a time, the
two are somewhat equivalent, and “project” is more understandable in
help texts (which call their argument “dist”, by the way..)

Finally, all help texts have been moved near to the function they
document.

files:
  distutils2/run.py |  242 +++++++++++++++------------------
  1 files changed, 107 insertions(+), 135 deletions(-)


diff --git a/distutils2/run.py b/distutils2/run.py
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -30,119 +30,6 @@
     pysetup action --help
 """
 
-create_usage = """\
-Usage: pysetup create
-   or: pysetup create --help
-
-Create a new Python project.
-"""
-
-generate_usage = """\
-Usage: pysetup generate-setup
-   or: pysetup generate-setup --help
-
-Generate a setup.py script for backward-compatibility purposes.
-"""
-
-
-graph_usage = """\
-Usage: pysetup graph dist
-   or: pysetup graph --help
-
-Print dependency graph for the distribution.
-
-positional arguments:
-   dist  installed distribution name
-"""
-
-install_usage = """\
-Usage: pysetup install [dist]
-   or: pysetup install [archive]
-   or: pysetup install [src_dir]
-   or: pysetup install --help
-
-Install a Python distribution from the indexes, source directory, or sdist.
-
-positional arguments:
-   archive  path to source distribution (zip, tar.gz)
-   dist     distribution name to install from the indexes
-   scr_dir  path to source directory
-
-"""
-
-metadata_usage = """\
-Usage: pysetup metadata [dist] [-f field ...]
-   or: pysetup metadata [dist] [--all]
-   or: pysetup metadata --help
-
-Print metadata for the distribution.
-
-positional arguments:
-   dist  installed distribution name
-
-optional arguments:
-   -f     metadata field to print
-   --all  print all metadata fields
-"""
-
-remove_usage = """\
-Usage: pysetup remove dist [-y]
-   or: pysetup remove --help
-
-Uninstall a Python distribution.
-
-positional arguments:
-   dist  installed distribution name
-
-optional arguments:
-   -y  auto confirm distribution removal
-"""
-
-run_usage = """\
-Usage: pysetup run [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
-   or: pysetup run --help
-   or: pysetup run --list-commands
-   or: pysetup run cmd --help
-"""
-
-list_usage = """\
-Usage: pysetup list dist [dist ...]
-   or: pysetup list --help
-   or: pysetup list --all
-
-Print name, version and location for the matching installed distributions.
-
-positional arguments:
-   dist  installed distribution name
-
-optional arguments:
-   --all  list all installed distributions
-"""
-
-search_usage = """\
-Usage: pysetup search [project] [--simple [url]] [--xmlrpc [url] [--fieldname value ...] --operator or|and]
-   or: pysetup search --help
-
-Search the indexes for the matching projects.
-
-positional arguments:
-    project     the project pattern to search for
-
-optional arguments:
-    --xmlrpc [url]      wether to use the xmlrpc index or not. If an url is
-                        specified, it will be used rather than the default one.
-
-    --simple [url]      wether to use the simple index or not. If an url is
-                        specified, it will be used rather than the default one.
-
-    --fieldname value   Make a search on this field. Can only be used if
-                        --xmlrpc has been selected or is the default index.
-
-    --operator or|and   Defines what is the operator to use when doing xmlrpc
-                        searchs with multiple fieldnames. Can only be used if
-                        --xmlrpc has been selected or is the default index.
-"""
-
 global_options = [
     # The fourth entry for verbose means that it can be repeated.
     ('verbose', 'v', "run verbosely (default)", True),
@@ -205,19 +92,37 @@
         return wrapper
 
 
- at action_help(create_usage)
+ at action_help("""\
+Usage: pysetup create
+   or: pysetup create --help
+
+Create a new Python project.
+""")
 def _create(distpatcher, args, **kw):
     from distutils2.create import main
     return main()
 
 
- at action_help(generate_usage)
+ at action_help("""\
+Usage: pysetup generate-setup
+   or: pysetup generate-setup --help
+
+Generate a setup.py script for backward-compatibility purposes.
+""")
 def _generate(distpatcher, args, **kw):
     generate_setup_py()
     logger.info('The setup.py was generated')
 
 
- at action_help(graph_usage)
+ at action_help("""\
+Usage: pysetup graph dist
+   or: pysetup graph --help
+
+Print dependency graph for the distribution.
+
+positional arguments:
+   dist  installed distribution name
+""")
 def _graph(dispatcher, args, **kw):
     name = args[1]
     dist = get_distribution(name, use_egg_info=True)
@@ -230,7 +135,19 @@
         print graph.repr_node(dist)
 
 
- at action_help(install_usage)
+ at action_help("""\
+Usage: pysetup install [dist]
+   or: pysetup install [archive]
+   or: pysetup install [src_dir]
+   or: pysetup install --help
+
+Install a Python distribution from the indexes, source directory, or sdist.
+
+positional arguments:
+   archive  path to source distribution (zip, tar.gz)
+   dist     distribution name to install from the indexes
+   scr_dir  path to source directory
+""")
 def _install(dispatcher, args, **kw):
     # first check if we are in a source directory
     if len(args) < 2:
@@ -250,9 +167,21 @@
         return not install(target)
 
 
- at action_help(metadata_usage)
+ at action_help("""\
+Usage: pysetup metadata [dist]
+   or: pysetup metadata [dist] [-f field ...]
+   or: pysetup metadata --help
+
+Print metadata for the distribution.
+
+positional arguments:
+   dist  installed distribution name
+
+optional arguments:
+   -f     metadata field to print; omit to get all fields
+""")
 def _metadata(dispatcher, args, **kw):
-    opts = _parse_args(args[1:], 'f:', ['all'])
+    opts = _parse_args(args[1:], 'f:', [])
     if opts['args']:
         name = opts['args'][0]
         dist = get_distribution(name, use_egg_info=True)
@@ -269,13 +198,10 @@
 
     metadata = dist.metadata
 
-    if 'all' in opts:
+    if 'f' in opts:
+        keys = (k for k in opts['f'] if k in metadata)
+    else:
         keys = metadata.keys()
-    else:
-        if 'f' in opts:
-            keys = (k for k in opts['f'] if k in metadata)
-        else:
-            keys = ()
 
     for key in keys:
         if key in metadata:
@@ -288,7 +214,18 @@
                 print '   ', value.replace('\n', '\n    ')
 
 
- at action_help(remove_usage)
+ at action_help("""\
+Usage: pysetup remove dist [-y]
+   or: pysetup remove --help
+
+Uninstall a Python distribution.
+
+positional arguments:
+   dist  installed distribution name
+
+optional arguments:
+   -y  auto confirm distribution removal
+""")
 def _remove(distpatcher, args, **kw):
     opts = _parse_args(args[1:], 'y', [])
     if 'y' in opts:
@@ -307,7 +244,12 @@
     return retcode
 
 
- at action_help(run_usage)
+ at action_help("""\
+Usage: pysetup run [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
+   or: pysetup run --help
+   or: pysetup run --list-commands
+   or: pysetup run cmd --help
+""")
 def _run(dispatcher, args, **kw):
     parser = dispatcher.parser
     args = args[1:]
@@ -347,16 +289,24 @@
     return dist
 
 
- at action_help(list_usage)
+ at action_help("""\
+Usage: pysetup list [dist ...]
+   or: pysetup list --help
+
+Print name, version and location for the matching installed distributions.
+
+positional arguments:
+   dist  installed distribution name; omit to get all distributions
+""")
 def _list(dispatcher, args, **kw):
-    opts = _parse_args(args[1:], '', ['all'])
+    opts = _parse_args(args[1:], '', [])
     dists = get_distributions(use_egg_info=True)
-    if 'all' in opts or opts['args'] == []:
+    if opts['args']:
+        results = (d for d in dists if d.name.lower() in opts['args'])
+        listall = False
+    else:
         results = dists
         listall = True
-    else:
-        results = (d for d in dists if d.name.lower() in opts['args'])
-        listall = False
 
     number = 0
     for dist in results:
@@ -373,7 +323,29 @@
         logger.info('Found %d projects installed.', number)
 
 
- at action_help(search_usage)
+ at action_help("""\
+Usage: pysetup search [project] [--simple [url]] [--xmlrpc [url] [--fieldname value ...] --operator or|and]
+   or: pysetup search --help
+
+Search the indexes for the matching projects.
+
+positional arguments:
+    project     the project pattern to search for
+
+optional arguments:
+    --xmlrpc [url]      whether to use the xmlrpc index or not. If an url is
+                        specified, it will be used rather than the default one.
+
+    --simple [url]      whether to use the simple index or not. If an url is
+                        specified, it will be used rather than the default one.
+
+    --fieldname value   Make a search on this field. Can only be used if
+                        --xmlrpc has been selected or is the default index.
+
+    --operator or|and   Defines what is the operator to use when doing xmlrpc
+                        searchs with multiple fieldnames. Can only be used if
+                        --xmlrpc has been selected or is the default index.
+""")
 def _search(dispatcher, args, **kw):
     """The search action.
 
@@ -392,7 +364,7 @@
     ('install', 'Install a project', _install),
     ('remove', 'Remove a project', _remove),
     ('search', 'Search for a project in the indexes', _search),
-    ('list', 'List installed releases', _list),
+    ('list', 'List installed projects', _list),
     ('graph', 'Display a graph', _graph),
     ('create', 'Create a project', _create),
     ('generate-setup', 'Generate a backward-comptatible setup.py', _generate),

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


More information about the Python-checkins mailing list