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

Reduce the formatter's target line length to 88 #12757

Merged
merged 1 commit into from
Aug 10, 2024
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: 4 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
target-version = "py310" # Pin Ruff to Python 3.10
line-length = 95
line-length = 88
output-format = "full"

extend-exclude = [
Expand Down Expand Up @@ -427,6 +427,9 @@ select = [
"ANN", # utilities don't need annotations
]

[lint.pycodestyle]
max-line-length = 95

[lint.flake8-quotes]
inline-quotes = "single"

Expand Down
13 changes: 11 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@
epub_description = 'Sphinx documentation generator system manual'

latex_documents = [
('index', 'sphinx.tex', 'Sphinx Documentation', 'the Sphinx developers', 'manual', 1)
(
'index',
'sphinx.tex',
'Sphinx Documentation',
'the Sphinx developers',
'manual',
1,
)
]
latex_logo = '_static/sphinx.png'
latex_elements = {
Expand Down Expand Up @@ -324,7 +331,9 @@ def setup(app: Sphinx) -> None:
app.connect('autodoc-process-docstring', cut_lines(4, what=['module']))
app.connect('include-read', linkify_issues_in_changelog)
app.connect('build-finished', build_redirects)
fdesc = GroupedField('parameter', label='Parameters', names=['param'], can_collapse=True)
fdesc = GroupedField(
'parameter', label='Parameters', names=['param'], can_collapse=True
)
app.add_object_type(
'event',
'event',
Expand Down
19 changes: 17 additions & 2 deletions doc/development/tutorials/examples/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ def generate(self, docnames=None):
for ingredient, recipe_names in ingredient_recipes.items():
for recipe_name in recipe_names:
dispname, typ, docname, anchor = recipes[recipe_name]
content[ingredient].append((dispname, 0, docname, anchor, docname, '', typ))
content[ingredient].append((
dispname,
0,
docname,
anchor,
docname,
'',
typ,
))

# convert the dict to the sorted list of tuples expected
content = sorted(content.items())
Expand Down Expand Up @@ -153,7 +161,14 @@ def add_recipe(self, signature, ingredients):

self.data['recipe_ingredients'][name] = ingredients
# name, dispname, type, docname, anchor, priority
self.data['recipes'].append((name, signature, 'Recipe', self.env.docname, anchor, 0))
self.data['recipes'].append((
name,
signature,
'Recipe',
self.env.docname,
anchor,
0,
))


def setup(app: Sphinx) -> ExtensionMetadata:
Expand Down
8 changes: 6 additions & 2 deletions doc/development/tutorials/examples/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def purge_todos(app, env, docname):
if not hasattr(env, 'todo_all_todos'):
return

env.todo_all_todos = [todo for todo in env.todo_all_todos if todo['docname'] != docname]
env.todo_all_todos = [
todo for todo in env.todo_all_todos if todo['docname'] != docname
]


def merge_todos(app, env, docnames, other):
Expand Down Expand Up @@ -98,7 +100,9 @@ def process_todo_nodes(app, doctree, fromdocname):
newnode = nodes.reference('', '')
innernode = nodes.emphasis(_('here'), _('here'))
newnode['refdocname'] = todo_info['docname']
newnode['refuri'] = app.builder.get_relative_uri(fromdocname, todo_info['docname'])
newnode['refuri'] = app.builder.get_relative_uri(
fromdocname, todo_info['docname']
)
newnode['refuri'] += '#' + todo_info['target']['refid']
newnode.append(innernode)
para += newnode
Expand Down
5 changes: 4 additions & 1 deletion sphinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

warnings.filterwarnings('default', category=RemovedInNextVersionWarning)
warnings.filterwarnings(
'ignore', 'The frontend.Option class .*', DeprecationWarning, module='docutils.frontend'
'ignore',
'The frontend.Option class .*',
DeprecationWarning,
module='docutils.frontend',
)

#: Version info for better programmatic use.
Expand Down
15 changes: 13 additions & 2 deletions sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@
from sphinx.environment.adapters.asset import ImageAdapter
from sphinx.errors import SphinxError
from sphinx.locale import __
from sphinx.util import UnicodeDecodeErrorHandler, get_filetype, import_object, logging, rst
from sphinx.util import (
UnicodeDecodeErrorHandler,
get_filetype,
import_object,
logging,
rst,
)
from sphinx.util.build_phase import BuildPhase
from sphinx.util.console import bold
from sphinx.util.display import progress_message, status_iterator
from sphinx.util.docutils import sphinx_domains
from sphinx.util.i18n import CatalogInfo, CatalogRepository, docname_to_domain
from sphinx.util.osutil import SEP, canon_path, ensuredir, relative_uri, relpath
from sphinx.util.parallel import ParallelTasks, SerialTasks, make_chunks, parallel_available
from sphinx.util.parallel import (
ParallelTasks,
SerialTasks,
make_chunks,
parallel_available,
)

# side effect: registers roles and directives
from sphinx import directives # NoQA: F401 isort:skip
Expand Down
6 changes: 5 additions & 1 deletion sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
from sphinx import __display_version__, package_dir
from sphinx import version_info as sphinx_version
from sphinx.builders import Builder
from sphinx.builders.html._assets import _CascadingStyleSheet, _file_checksum, _JavaScript
from sphinx.builders.html._assets import (
_CascadingStyleSheet,
_file_checksum,
_JavaScript,
)
from sphinx.config import ENUM, Config
from sphinx.deprecation import _deprecation_warning
from sphinx.domains import Domain, Index, IndexEntry
Expand Down
6 changes: 5 additions & 1 deletion sphinx/builders/latex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import sphinx.builders.latex.nodes # NoQA: F401,E501 # Workaround: import this before writer to avoid ImportError
from sphinx import addnodes, highlighting, package_dir
from sphinx.builders import Builder
from sphinx.builders.latex.constants import ADDITIONAL_SETTINGS, DEFAULT_SETTINGS, SHORTHANDOFF
from sphinx.builders.latex.constants import (
ADDITIONAL_SETTINGS,
DEFAULT_SETTINGS,
SHORTHANDOFF,
)
from sphinx.builders.latex.theming import Theme, ThemeFactory
from sphinx.builders.latex.util import ExtBabel
from sphinx.config import ENUM, Config
Expand Down
10 changes: 8 additions & 2 deletions sphinx/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def _deprecation_warning(

# deprecated name -> (object to return, canonical path or empty string, removal version)
_DEPRECATED_OBJECTS = {
'deprecated_name': (object_to_return, 'fully_qualified_replacement_name', (9, 0)),
'deprecated_name': (
object_to_return,
'fully_qualified_replacement_name',
(9, 0),
),
}


Expand All @@ -65,7 +69,9 @@ def __getattr__(name: str) -> Any:

qualname = f'{module}.{attribute}'
if canonical_name:
message = f'The alias {qualname!r} is deprecated, use {canonical_name!r} instead.'
message = (
f'The alias {qualname!r} is deprecated, use {canonical_name!r} instead.'
)
else:
message = f'{qualname!r} is deprecated.'

Expand Down
7 changes: 6 additions & 1 deletion sphinx/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

from sphinx import addnodes
from sphinx.environment.adapters import toctree as toctree_adapters
from sphinx.errors import BuildEnvironmentError, DocumentError, ExtensionError, SphinxError
from sphinx.errors import (
BuildEnvironmentError,
DocumentError,
ExtensionError,
SphinxError,
)
from sphinx.locale import __
from sphinx.transforms import SphinxTransformer
from sphinx.util import DownloadFiles, FilenameUniqDict, logging
Expand Down
5 changes: 4 additions & 1 deletion sphinx/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class ExtensionError(SphinxError):
"""Extension error."""

def __init__(
self, message: str, orig_exc: Exception | None = None, modname: str | None = None
self,
message: str,
orig_exc: Exception | None = None,
modname: str | None = None,
) -> None:
super().__init__(message)
self.message = message
Expand Down
10 changes: 8 additions & 2 deletions sphinx/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def disconnect(self, listener_id: int) -> None:
listeners.remove(listener)

def emit(
self, name: str, *args: Any, allowed_exceptions: tuple[type[Exception], ...] = ()
self,
name: str,
*args: Any,
allowed_exceptions: tuple[type[Exception], ...] = (),
) -> list:
"""Emit a Sphinx event."""
# not every object likes to be repr()'d (think
Expand Down Expand Up @@ -120,7 +123,10 @@ def emit(
return results

def emit_firstresult(
self, name: str, *args: Any, allowed_exceptions: tuple[type[Exception], ...] = ()
self,
name: str,
*args: Any,
allowed_exceptions: tuple[type[Exception], ...] = (),
) -> Any:
"""Emit a Sphinx event and returns first result.

Expand Down
53 changes: 40 additions & 13 deletions sphinx/ext/apidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ def write_file(name: str, text: str, opts: CliOptions) -> Path:


def create_module_file(
package: str | None, basename: str, opts: CliOptions, user_template_dir: str | None = None
package: str | None,
basename: str,
opts: CliOptions,
user_template_dir: str | None = None,
) -> Path:
"""Build the text of the file and write the file."""
options = copy(OPTIONS)
Expand Down Expand Up @@ -148,7 +151,9 @@ def create_package_file(
if not is_skipped_module(Path(root, sub), opts, excludes) and not is_initpy(sub)
]
submodules = sorted(set(submodules))
submodules = [module_join(master_package, subroot, modname) for modname in submodules]
submodules = [
module_join(master_package, subroot, modname) for modname in submodules
]
options = copy(OPTIONS)
if opts.includeprivate and 'private-members' not in options:
options.append('private-members')
Expand Down Expand Up @@ -316,7 +321,9 @@ def recurse_tree(
if is_pkg or is_namespace:
# we are in a package with something to document
if subs or len(files) > 1 or not is_skipped_package(root, opts):
subpackage = root[len(rootpath) :].lstrip(path.sep).replace(path.sep, '.')
subpackage = (
root[len(rootpath) :].lstrip(path.sep).replace(path.sep, '.')
)
# if this is not a namespace or
# a namespace and there is something there to document
if not is_namespace or has_child_module(root, excludes, opts):
Expand All @@ -342,7 +349,9 @@ def recurse_tree(
if not is_skipped_module(Path(rootpath, py_file), opts, excludes):
module = py_file.split('.')[0]
written_files.append(
create_module_file(root_package, module, opts, user_template_dir)
create_module_file(
root_package, module, opts, user_template_dir
)
)
toplevels.append(module)

Expand All @@ -361,7 +370,7 @@ def is_excluded(root: str | Path, excludes: Sequence[re.Pattern[str]]) -> bool:

def get_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage='%(prog)s [OPTIONS] -o <OUTPUT_PATH> <MODULE_PATH> ' '[EXCLUDE_PATTERN, ...]',
usage='%(prog)s [OPTIONS] -o <OUTPUT_PATH> <MODULE_PATH> [EXCLUDE_PATTERN, ...]',
epilog=__('For more information, visit <https://www.sphinx-doc.org/>.'),
description=__("""
Look recursively in <MODULE_PATH> for Python modules and packages and create
Expand All @@ -384,7 +393,9 @@ def get_parser() -> argparse.ArgumentParser:
parser.add_argument(
'exclude_pattern',
nargs='*',
help=__('fnmatch-style file and/or directory patterns ' 'to exclude from generation'),
help=__(
'fnmatch-style file and/or directory patterns ' 'to exclude from generation'
),
)

parser.add_argument(
Expand All @@ -411,7 +422,11 @@ def get_parser() -> argparse.ArgumentParser:
help=__('maximum depth of submodules to show in the TOC ' '(default: 4)'),
)
parser.add_argument(
'-f', '--force', action='store_true', dest='force', help=__('overwrite existing files')
'-f',
'--force',
action='store_true',
dest='force',
help=__('overwrite existing files'),
)
parser.add_argument(
'-l',
Expand All @@ -420,7 +435,8 @@ def get_parser() -> argparse.ArgumentParser:
dest='followlinks',
default=False,
help=__(
'follow symbolic links. Powerful when combined ' 'with collective.recipe.omelette.'
'follow symbolic links. Powerful when combined '
'with collective.recipe.omelette.'
),
)
parser.add_argument(
Expand Down Expand Up @@ -481,7 +497,8 @@ def get_parser() -> argparse.ArgumentParser:
action='store_true',
dest='implicit_namespaces',
help=__(
'interpret module paths according to PEP-0420 ' 'implicit namespaces specification'
'interpret module paths according to PEP-0420 '
'implicit namespaces specification'
),
)
parser.add_argument(
Expand All @@ -497,7 +514,9 @@ def get_parser() -> argparse.ArgumentParser:
'--remove-old',
action='store_true',
dest='remove_old',
help=__('Remove existing files in the output directory that were not generated'),
help=__(
'Remove existing files in the output directory that were not generated'
),
)
exclusive_group.add_argument(
'-F',
Expand Down Expand Up @@ -539,7 +558,9 @@ def get_parser() -> argparse.ArgumentParser:
'--doc-release',
action='store',
dest='release',
help=__('project release, used when --full is given, ' 'defaults to --doc-version'),
help=__(
'project release, used when --full is given, ' 'defaults to --doc-version'
),
)

group = parser.add_argument_group(__('extension options'))
Expand Down Expand Up @@ -649,7 +670,11 @@ def main(argv: Sequence[str] = (), /) -> int:
'suffix': '.' + args.suffix,
'master': 'index',
'epub': True,
'extensions': ['sphinx.ext.autodoc', 'sphinx.ext.viewcode', 'sphinx.ext.todo'],
'extensions': [
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx.ext.todo',
],
'makefile': True,
'batchfile': True,
'make_mode': True,
Expand All @@ -670,7 +695,9 @@ def main(argv: Sequence[str] = (), /) -> int:
d['extensions'].extend(ext.split(','))

if not args.dryrun:
qs.generate(d, silent=True, overwrite=args.force, templatedir=args.templatedir)
qs.generate(
d, silent=True, overwrite=args.force, templatedir=args.templatedir
)
elif args.tocfile:
written_files.append(
create_modules_toc_file(modules, args, args.tocfile, args.templatedir)
Expand Down
Loading