summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPradyun Gedam <pradyunsg@users.noreply.github.com>2021-01-18 22:24:30 +0000
committerPradyun Gedam <pradyunsg@users.noreply.github.com>2021-03-06 11:09:09 +0000
commit6b076e53d74e833776ce5740a3497dabef0ebfee (patch)
treeed061ee59a80d17611b29f5d44dc94cc34aea00c
parentd4431996db0904d8e652a38759100afca1852502 (diff)
downloadpip-6b076e53d74e833776ce5740a3497dabef0ebfee.tar.gz
Blacken pip_sphinxext.py
-rw-r--r--docs/pip_sphinxext.py54
1 files changed, 24 insertions, 30 deletions
diff --git a/docs/pip_sphinxext.py b/docs/pip_sphinxext.py
index 1ce526e0d..c054035f1 100644
--- a/docs/pip_sphinxext.py
+++ b/docs/pip_sphinxext.py
@@ -19,14 +19,12 @@ class PipCommandUsage(rst.Directive):
def run(self):
cmd = create_command(self.arguments[0])
- cmd_prefix = 'python -m pip'
+ cmd_prefix = "python -m pip"
if len(self.arguments) > 1:
cmd_prefix = " ".join(self.arguments[1:])
cmd_prefix = cmd_prefix.strip('"')
cmd_prefix = cmd_prefix.strip("'")
- usage = dedent(
- cmd.usage.replace('%prog', f'{cmd_prefix} {cmd.name}')
- ).strip()
+ usage = dedent(cmd.usage.replace("%prog", f"{cmd_prefix} {cmd.name}")).strip()
node = nodes.literal_block(usage, usage)
return [node]
@@ -40,19 +38,18 @@ class PipCommandDescription(rst.Directive):
desc = ViewList()
cmd = create_command(self.arguments[0])
description = dedent(cmd.__doc__)
- for line in description.split('\n'):
+ for line in description.split("\n"):
desc.append(line, "")
self.state.nested_parse(desc, 0, node)
return [node]
class PipOptions(rst.Directive):
-
def _format_option(self, option, cmd_name=None):
bookmark_line = (
f".. _`{cmd_name}_{option._long_opts[0]}`:"
- if cmd_name else
- f".. _`{option._long_opts[0]}`:"
+ if cmd_name
+ else f".. _`{option._long_opts[0]}`:"
)
line = ".. option:: "
if option._short_opts:
@@ -65,7 +62,7 @@ class PipOptions(rst.Directive):
metavar = option.metavar or option.dest.lower()
line += f" <{metavar.lower()}>"
# fix defaults
- opt_help = option.help.replace('%default', str(option.default))
+ opt_help = option.help.replace("%default", str(option.default))
# fix paths with sys.prefix
opt_help = opt_help.replace(sys.prefix, "<sys.prefix>")
return [bookmark_line, "", line, "", " " + opt_help, ""]
@@ -88,9 +85,7 @@ class PipOptions(rst.Directive):
class PipGeneralOptions(PipOptions):
def process_options(self):
- self._format_options(
- [o() for o in cmdoptions.general_group['options']]
- )
+ self._format_options([o() for o in cmdoptions.general_group["options"]])
class PipIndexOptions(PipOptions):
@@ -99,7 +94,7 @@ class PipIndexOptions(PipOptions):
def process_options(self):
cmd_name = self.arguments[0]
self._format_options(
- [o() for o in cmdoptions.index_group['options']],
+ [o() for o in cmdoptions.index_group["options"]],
cmd_name=cmd_name,
)
@@ -116,49 +111,48 @@ class PipCommandOptions(PipOptions):
class PipReqFileOptionsReference(PipOptions):
-
def determine_opt_prefix(self, opt_name):
for command in commands_dict:
cmd = create_command(command)
if cmd.cmd_opts.has_option(opt_name):
return command
- raise KeyError(f'Could not identify prefix of opt {opt_name}')
+ raise KeyError(f"Could not identify prefix of opt {opt_name}")
def process_options(self):
for option in SUPPORTED_OPTIONS:
- if getattr(option, 'deprecated', False):
+ if getattr(option, "deprecated", False):
continue
opt = option()
opt_name = opt._long_opts[0]
if opt._short_opts:
- short_opt_name = '{}, '.format(opt._short_opts[0])
+ short_opt_name = "{}, ".format(opt._short_opts[0])
else:
- short_opt_name = ''
+ short_opt_name = ""
- if option in cmdoptions.general_group['options']:
- prefix = ''
+ if option in cmdoptions.general_group["options"]:
+ prefix = ""
else:
- prefix = '{}_'.format(self.determine_opt_prefix(opt_name))
+ prefix = "{}_".format(self.determine_opt_prefix(opt_name))
self.view_list.append(
- '* :ref:`{short}{long}<{prefix}{opt_name}>`'.format(
+ "* :ref:`{short}{long}<{prefix}{opt_name}>`".format(
short=short_opt_name,
long=opt_name,
prefix=prefix,
- opt_name=opt_name
+ opt_name=opt_name,
),
- "\n"
+ "\n",
)
def setup(app):
- app.add_directive('pip-command-usage', PipCommandUsage)
- app.add_directive('pip-command-description', PipCommandDescription)
- app.add_directive('pip-command-options', PipCommandOptions)
- app.add_directive('pip-general-options', PipGeneralOptions)
- app.add_directive('pip-index-options', PipIndexOptions)
+ app.add_directive("pip-command-usage", PipCommandUsage)
+ app.add_directive("pip-command-description", PipCommandDescription)
+ app.add_directive("pip-command-options", PipCommandOptions)
+ app.add_directive("pip-general-options", PipGeneralOptions)
+ app.add_directive("pip-index-options", PipIndexOptions)
app.add_directive(
- 'pip-requirements-file-options-ref-list', PipReqFileOptionsReference
+ "pip-requirements-file-options-ref-list", PipReqFileOptionsReference
)