Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use a prettier/less verbose help formatter #465

Merged
merged 2 commits into from

2 participants

@gvalkov
  • Prevents excessive wrapping (respects $COLUMNS if set)
  • More control over the look of pip's option handling
  • -d DIR, --download=DIR becomes -d, --download <DIR>

Factored out of pull request 463 (and for this reason, might not look like it's really improving anything)

@gvalkov gvalkov Use a prettier/less verbose help formatter
 * Prevents excessive wrapping (respects $COLUMNS if set)
 * More control over the look of pip's option handling
 * '-d DIR, --download=DIR' becomes '-d, --download <DIR>'
3534ac5
@pnasrat

Docstring nit - no space at start and end sentence with period.

@pnasrat

Remove commented line.

@pnasrat

As per

http://www.python.org/dev/peps/pep-0257/#one-line-docstrings

The one-line docstring should NOT be a "signature" reiterating the function/method parameters.

@pnasrat

Inconsistent commenting layout - either place in the method as elsewhere.

@pnasrat

Ditto.

@gvalkov

The inconsistencies that you pointed out have been taken care of.

@gvalkov gvalkov referenced this pull request
Closed

Rework command handling #463

@pnasrat
Owner

Thanks for that. lgtm so merging

@pnasrat pnasrat merged commit b5e7cde into pypa:develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 1, 2012
  1. @gvalkov

    Use a prettier/less verbose help formatter

    gvalkov authored
     * Prevents excessive wrapping (respects $COLUMNS if set)
     * More control over the look of pip's option handling
     * '-d DIR, --download=DIR' becomes '-d, --download <DIR>'
Commits on May 14, 2012
  1. @gvalkov
This page is out of date. Refresh to see the latest.
Showing with 69 additions and 1 deletion.
  1. +69 −1 pip/baseparser.py
View
70 pip/baseparser.py
@@ -9,7 +9,75 @@
from pip.locations import default_config_file, default_log_file
-class UpdatingDefaultsHelpFormatter(optparse.IndentedHelpFormatter):
+class PipPrettyHelpFormatter(optparse.IndentedHelpFormatter):
+ """A prettier/less verbose help formatter for optparse."""
+
+ def __init__(self, *args, **kw):
+ kw['max_help_position'] = 23
+ kw['indent_increment'] = 1
+
+ # do as argparse does
+ try:
+ kw['width'] = int(os.environ['COLUMNS']) - 2
+ except:
+ kw['width'] = 78
+
+ optparse.IndentedHelpFormatter.__init__(self, *args, **kw)
+
+ def format_option_strings(self, option):
+ return self._format_option_strings(option, ' <%s>', ', ')
+
+ def _format_option_strings(self, option, mvarfmt=' <%s>', optsep=', '):
+ """
+ Return a comma-separated list of option strings and metavars.
+
+ :param option: tuple of (short opt, long opt), e.g: ('-f', '--format')
+ :param mvarfmt: metavar format string - evaluated as mvarfmt % metavar
+ :param optsep: separator
+ """
+
+ opts = []
+
+ if option._short_opts: opts.append(option._short_opts[0])
+ if option._long_opts: opts.append(option._long_opts[0])
+ if len(opts) > 1: opts.insert(1, optsep)
+
+ if option.takes_value():
+ metavar = option.metavar or option.dest.lower()
+ opts.append(mvarfmt % metavar)
+
+ return ''.join(opts)
+
+ def format_heading(self, heading):
+ if heading == 'Options': return ''
+ return heading + ':\n'
+
+ def format_usage(self, usage):
+ # ensure there is only one newline between usage and the first heading
+ # if there is no description
+
+ msg = 'Usage: %s' % usage
+ if self.parser.description:
+ msg += '\n'
+
+ return msg
+
+ def format_description(self, description):
+ # leave full control over description to us
+ if description:
+ return description
+ else:
+ return ''
+
+ def format_epilog(self, epilog):
+ # leave full control over epilog to us
+ if epilog:
+ return epilog
+ else:
+ return ''
+
+
+class UpdatingDefaultsHelpFormatter(PipPrettyHelpFormatter):
"""Custom help formatter for use in ConfigOptionParser that updates
the defaults before expanding them, allowing them to show up correctly
in the help listing"""
Something went wrong with that request. Please try again.