Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code with Black #7084

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
exclude: .patch

- repo: https://github.com/timothycrosley/isort
rev: 4.3.21
rev: 18ad293fc9d1852776afe35015a932b68d26fb14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we wait for a. release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I can update this when it's out.

hooks:
- id: isort
files: \.py$
Expand Down
85 changes: 33 additions & 52 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-2017, PyPA'
project = "pip"
copyright = "2008-2017, 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,10 +140,10 @@
# 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'
"collapsiblesidebar": True,
"externalrefs": True,
"navigation_depth": 3,
"issues_url": "https://github.com/pypa/pip/issues",
}

# Add any paths that contain custom themes here, relative to this directory.
Expand Down Expand Up @@ -171,7 +171,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 @@ -190,10 +190,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 @@ -220,7 +217,7 @@
# html_file_suffix = ''

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


# -- Options for LaTeX output -------------------------------------------------
Expand All @@ -234,13 +231,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (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")
]

# The name of an image file (relative to this directory) to place at the top of
Expand All @@ -264,28 +255,18 @@

# 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)
]

# 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 = fname[len(man_dir):-4]
outname = 'pip-' + fname_base[9:]
description = u'description of {} command'.format(
outname.replace('-', ' ')
)
fname_base = fname[len(man_dir) : -4]
outname = "pip-" + fname_base[9:]
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))
32 changes: 11 additions & 21 deletions docs/pip_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,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 @@ -33,14 +31,13 @@ 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):
if cmd_name:
bookmark_line = ".. _`%s_%s`:" % (cmd_name, option._long_opts[0])
Expand All @@ -57,7 +54,7 @@ def _format_option(self, option, cmd_name=None):
metavar = option.metavar or option.dest.lower()
line += " <%s>" % 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, "", " %s" % opt_help, ""]
Expand All @@ -80,32 +77,25 @@ 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):
def process_options(self):
self._format_options(
[o() for o in cmdoptions.index_group['options']]
)
self._format_options([o() for o in cmdoptions.index_group["options"]])


class PipCommandOptions(PipOptions):
required_arguments = 1

def process_options(self):
cmd = create_command(self.arguments[0])
self._format_options(
cmd.parser.option_groups[0].option_list,
cmd_name=cmd.name,
)
self._format_options(cmd.parser.option_groups[0].option_list, cmd_name=cmd.name)


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)
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
[build-system]
requires = ["setuptools", "wheel"]

[tool.black]
exclude = '''
/(
# Re-enable Black default
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist

# pip specific: exclude vendored
| src/pip/_vendor
)/
'''

[tool.towncrier]
package = "pip"
package_dir = "src"
Expand Down
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ known_first_party =
tests
default_section = THIRDPARTY
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
line_length = 88
ensure_newline_before_comments = true

[flake8]
exclude =
Expand All @@ -24,7 +28,8 @@ exclude =
_vendor,
data
select = E,W,F
ignore = W504
ignore = E203,W503,W504
max-line-length = 88

[mypy]
follow_imports = silent
Expand Down
Loading