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

Use black #391

Merged
merged 2 commits into from
May 10, 2022
Merged
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
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ repos:
- id: check-toml
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.2
hooks:
Expand Down
62 changes: 33 additions & 29 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.

# for example.py
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath("."))
# project root
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))

os.environ['MPLBACKEND'] = 'Agg' # avoid tkinter import errors on rtfd.io
os.environ["MPLBACKEND"] = "Agg" # avoid tkinter import errors on rtfd.io

# -- General configuration ---------------------------------------------------

Expand All @@ -36,32 +36,32 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'numpydoc',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.imgmath',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"numpydoc",
"sphinx.ext.ifconfig",
"sphinx.ext.viewcode",
"sphinx.ext.imgmath",
]

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

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

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

# The root toctree document
master_doc = 'index' # NOTE: will be changed to `root_doc` in sphinx 4
master_doc = "index" # NOTE: will be changed to `root_doc` in sphinx 4

# General information about the project.
project = 'numpydoc'
copyright = f'2019-{date.today().year}, numpydoc maintainers'
project = "numpydoc"
copyright = f"2019-{date.today().year}, numpydoc maintainers"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -70,12 +70,13 @@
# The short X.Y version.

import numpydoc

# version = .__version__
# The full version, including alpha/beta/rc tags.
release = numpydoc.__version__
version = numpydoc.__version__
numpydoc_xref_param_type = True
numpydoc_xref_ignore = {'optional', 'type_without_description', 'BadException'}
numpydoc_xref_ignore = {"optional", "type_without_description", "BadException"}
# Run docstring validation as part of build process
numpydoc_validation_checks = {"all", "GL01", "SA04", "RT03"}

Expand All @@ -91,7 +92,7 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
exclude_patterns = ["_build"]

# The reST default role (used for this markup: `text`) to use for all
# documents.
Expand All @@ -109,7 +110,7 @@
# 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 = []
Expand All @@ -134,7 +135,7 @@
}

html_title = f"{project} v{version} Manual"
html_last_updated_fmt = '%b %d, %Y'
html_last_updated_fmt = "%b %d, %Y"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down Expand Up @@ -188,18 +189,16 @@
# html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'project-templatedoc'
htmlhelp_basename = "project-templatedoc"


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
Expand All @@ -208,8 +207,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'numpydoc.tex', 'numpydoc Documentation',
'Numpydoc maintainers', 'manual'),
(
"index",
"numpydoc.tex",
"numpydoc Documentation",
"Numpydoc maintainers",
"manual",
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -247,7 +251,7 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'python': ('https://docs.python.org/3/', None),
'numpy': ('https://numpy.org/devdocs/', None),
'sklearn': ('https://scikit-learn.org/stable/', None),
"python": ("https://docs.python.org/3/", None),
"numpy": ("https://numpy.org/devdocs/", None),
"sklearn": ("https://scikit-learn.org/stable/", None),
}
2 changes: 1 addition & 1 deletion doc/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# numpy module itself, unabbreviated.


def foo(var1, var2, *args, long_var_name='hi', only_seldom_used_keyword=0, **kwargs):
def foo(var1, var2, *args, long_var_name="hi", only_seldom_used_keyword=0, **kwargs):
r"""Summarize the function in one line.

Several sentences providing an extended description. Refer to
Expand Down
2 changes: 2 additions & 0 deletions numpydoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _verify_sphinx_jinja():
if version.parse(sphinx.__version__) <= version.parse("4.0.2"):
if version.parse(jinja2.__version__) >= version.parse("3.1"):
from sphinx.errors import VersionRequirementError

raise VersionRequirementError(
"\n\nSphinx<4.0.2 is incompatible with Jinja2>=3.1.\n"
"If you wish to continue using sphinx<4.0.2 you need to pin "
Expand All @@ -32,4 +33,5 @@ def _verify_sphinx_jinja():

def setup(app, *args, **kwargs):
from .numpydoc import setup

return setup(app, *args, **kwargs)
28 changes: 16 additions & 12 deletions numpydoc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
def render_object(import_path, config=None):
"""Test numpydoc docstring generation for a given object"""
# TODO: Move Validator._load_obj to a better place than validate
print(get_doc_object(Validator._load_obj(import_path),
config=dict(config or [])))
print(get_doc_object(Validator._load_obj(import_path), config=dict(config or [])))
return 0


Expand All @@ -22,25 +21,30 @@ def validate_object(import_path):
results = validate(import_path)
for err_code, err_desc in results["errors"]:
exit_status += 1
print(':'.join([import_path, err_code, err_desc]))
print(":".join([import_path, err_code, err_desc]))
return exit_status


if __name__ == '__main__':
if __name__ == "__main__":
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument('import_path', help='e.g. numpy.ndarray')
ap.add_argument("import_path", help="e.g. numpy.ndarray")

def _parse_config(s):
key, _, value = s.partition('=')
key, _, value = s.partition("=")
value = ast.literal_eval(value)
return key, value

ap.add_argument('-c', '--config', type=_parse_config,
action='append',
help='key=val where val will be parsed by literal_eval, '
'e.g. -c use_plots=True. Multiple -c can be used.')
ap.add_argument('--validate', action='store_true',
help='validate the object and report errors')
ap.add_argument(
"-c",
"--config",
type=_parse_config,
action="append",
help="key=val where val will be parsed by literal_eval, "
"e.g. -c use_plots=True. Multiple -c can be used.",
)
ap.add_argument(
"--validate", action="store_true", help="validate the object and report errors"
)
args = ap.parse_args()

if args.validate:
Expand Down
2 changes: 1 addition & 1 deletion numpydoc/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.2.dev0'
__version__ = "1.3.2.dev0"
Loading