Skip to content

Commit

Permalink
Blacken the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Sep 23, 2020
1 parent d500c5a commit ddc92c8
Show file tree
Hide file tree
Showing 280 changed files with 13,288 additions and 11,468 deletions.
94 changes: 40 additions & 54 deletions docs/html/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import re
import sys

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

docs_dir = os.path.dirname(os.path.dirname(__file__))
# If extensions (or modules to document with autodoc) are in another directory,
Expand All @@ -30,54 +30,54 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
# extensions = ['sphinx.ext.autodoc']
extensions = ['sphinx.ext.extlinks', 'pip_sphinxext', 'sphinx.ext.intersphinx']
extensions = ["sphinx.ext.extlinks", "pip_sphinxext", "sphinx.ext.intersphinx"]

# intersphinx
intersphinx_cache_limit = 0
intersphinx_mapping = {
'pypug': ('https://packaging.python.org/', None),
'pypa': ('https://www.pypa.io/en/latest/', None),
"pypug": ("https://packaging.python.org/", None),
"pypa": ("https://www.pypa.io/en/latest/", None),
}


# Add any paths that contain templates here, relative to this directory.
templates_path = []

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
# source_encoding = 'utf-8'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'pip'
copyright = '2008-2020, PyPA'
project = "pip"
copyright = "2008-2020, PyPA"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.

version = release = 'dev'
version = release = "dev"

# Readthedocs seems to install pip as an egg (via setup.py install) which
# is somehow resulting in "import pip" picking up an older copy of pip.
# Rather than trying to force RTD to install pip properly, we'll simply
# read the version direct from the __init__.py file. (Yes, this is
# fragile, but it works...)

pip_init = os.path.join(docs_dir, '..', 'src', 'pip', '__init__.py')
pip_init = os.path.join(docs_dir, "..", "src", "pip", "__init__.py")
with open(pip_init) as f:
for line in f:
m = re.match(r'__version__ = "(.*)"', line)
if m:
__version__ = m.group(1)
# The short X.Y version.
version = '.'.join(__version__.split('.')[:2])
version = ".".join(__version__.split(".")[:2])
# The full version, including alpha/beta/rc tags.
release = __version__
break
Expand All @@ -95,14 +95,14 @@
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
today_fmt = '%B %d, %Y'
today_fmt = "%B %d, %Y"

# List of documents that shouldn't be included in the build.
# unused_docs = []

# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_patterns = ['build/']
exclude_patterns = ["build/"]

# The reST default role (used for this markup: `text`) to use for all documents
# default_role = None
Expand All @@ -119,15 +119,15 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []

extlinks = {
'issue': ('https://github.com/pypa/pip/issues/%s', '#'),
'pull': ('https://github.com/pypa/pip/pull/%s', 'PR #'),
'pypi': ('https://pypi.org/project/%s/', ''),
"issue": ("https://github.com/pypa/pip/issues/%s", "#"),
"pull": ("https://github.com/pypa/pip/pull/%s", "PR #"),
"pypi": ("https://pypi.org/project/%s/", ""),
}

# -- Options for HTML output --------------------------------------------------
Expand All @@ -140,12 +140,12 @@
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
'collapsiblesidebar': True,
'externalrefs': True,
'navigation_depth': 3,
'issues_url': 'https://github.com/pypa/pip/issues',
'codebgcolor': '#eeffcc',
'codetextcolor': '#333333',
"collapsiblesidebar": True,
"externalrefs": True,
"navigation_depth": 3,
"issues_url": "https://github.com/pypa/pip/issues",
"codebgcolor": "#eeffcc",
"codetextcolor": "#333333",
}

# Add any paths that contain custom themes here, relative to this directory.
Expand Down Expand Up @@ -173,7 +173,7 @@

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
html_last_updated_fmt = '%b %d, %Y'
html_last_updated_fmt = "%b %d, %Y"

# If true, the Docutils Smart Quotes transform (originally based on
# SmartyPants) will be used to convert characters like quotes and dashes
Expand All @@ -192,10 +192,7 @@
smartquotes_action = "qe"

# Custom sidebar templates, maps document names to template names.
html_sidebars = {
'**': ['localtoc.html', 'relations.html'],
'index': ['localtoc.html']
}
html_sidebars = {"**": ["localtoc.html", "relations.html"], "index": ["localtoc.html"]}

# Additional templates that should be rendered to pages, maps page names to
# template names.
Expand All @@ -222,7 +219,7 @@
# html_file_suffix = ''

# Output file base name for HTML help builder.
htmlhelp_basename = 'pipdocs'
htmlhelp_basename = "pipdocs"


# -- Options for LaTeX output -------------------------------------------------
Expand All @@ -237,11 +234,11 @@
# (source start file, target name, title, author, documentclass [howto/manual])
latex_documents = [
(
'index',
'pip.tex',
u'pip Documentation',
u'pip developers',
'manual',
"index",
"pip.tex",
u"pip Documentation",
u"pip developers",
"manual",
),
]

Expand All @@ -266,37 +263,26 @@

# List of manual pages generated
man_pages = [
(
'index',
'pip',
u'package manager for Python packages',
u'pip developers',
1
)
("index", "pip", u"package manager for Python packages", u"pip developers", 1)
]


def to_document_name(path, base_dir):
"""Convert a provided path to a Sphinx "document name".
"""
"""Convert a provided path to a Sphinx "document name"."""
relative_path = os.path.relpath(path, base_dir)
root, _ = os.path.splitext(relative_path)
return root.replace(os.sep, '/')
return root.replace(os.sep, "/")


# Here, we crawl the entire man/commands/ directory and list every file with
# appropriate name and details
man_dir = os.path.join(docs_dir, 'man')
raw_subcommands = glob.glob(os.path.join(man_dir, 'commands/*.rst'))
man_dir = os.path.join(docs_dir, "man")
raw_subcommands = glob.glob(os.path.join(man_dir, "commands/*.rst"))
if not raw_subcommands:
raise FileNotFoundError(
'The individual subcommand manpages could not be found!'
)
raise FileNotFoundError("The individual subcommand manpages could not be found!")
for fname in raw_subcommands:
fname_base = to_document_name(fname, man_dir)
outname = 'pip-' + fname_base.split('/')[1]
description = u'description of {} command'.format(
outname.replace('-', ' ')
)
outname = "pip-" + fname_base.split("/")[1]
description = u"description of {} command".format(outname.replace("-", " "))

man_pages.append((fname_base, outname, description, u'pip developers', 1))
man_pages.append((fname_base, outname, description, u"pip developers", 1))
52 changes: 23 additions & 29 deletions docs/pip_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class PipCommandUsage(rst.Directive):

def run(self):
cmd = create_command(self.arguments[0])
usage = dedent(
cmd.usage.replace('%prog', 'pip {}'.format(cmd.name))
).strip()
usage = dedent(cmd.usage.replace("%prog", "pip {}".format(cmd.name))).strip()
node = nodes.literal_block(usage, usage)
return [node]

Expand All @@ -34,19 +32,18 @@ def run(self):
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 = (
".. _`{cmd_name}_{option._long_opts[0]}`:"
if cmd_name else
".. _`{option._long_opts[0]}`:"
if cmd_name
else ".. _`{option._long_opts[0]}`:"
).format(**locals())
line = ".. option:: "
if option._short_opts:
Expand All @@ -59,7 +56,7 @@ def _format_option(self, option, cmd_name=None):
metavar = option.metavar or option.dest.lower()
line += " <{}>".format(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, ""]
Expand All @@ -82,9 +79,7 @@ def run(self):

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):
Expand All @@ -93,7 +88,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,
)

Expand All @@ -110,49 +105,48 @@ def process_options(self):


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('Could not identify prefix of opt {}'.format(opt_name))
raise KeyError("Could not identify prefix of opt {}".format(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
)

0 comments on commit ddc92c8

Please sign in to comment.