Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
TLouf committed Jan 8, 2025
1 parent 2c1e59f commit ce595dd
Show file tree
Hide file tree
Showing 35 changed files with 125 additions and 213 deletions.
2 changes: 1 addition & 1 deletion sphinx/_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _format_metavar(
def error(self, message: str) -> NoReturn:
sys.stderr.write(
__(
'{0}: error: {1}\n' "Run '{0} --help' for information" # NoQA: COM812
"{0}: error: {1}\nRun '{0} --help' for information" # NoQA: COM812
).format(self.prog, message)
)
raise SystemExit(2)
Expand Down
2 changes: 1 addition & 1 deletion sphinx/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def post_process_images(self, doctree: Node) -> None:
image_uri = images.get_original_image_uri(node['uri'])
if mimetypes:
logger.warning(
__('a suitable image for %s builder not found: ' '%s (%s)'),
__('a suitable image for %s builder not found: %s (%s)'),
self.name,
mimetypes,
image_uri,
Expand Down
5 changes: 1 addition & 4 deletions sphinx/builders/latex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ def init_document_data(self) -> None:
docname = entry[0]
if docname not in self.env.all_docs:
logger.warning(
__(
'"latex_documents" config value references unknown '
'document %s'
),
__('"latex_documents" config value references unknown document %s'),
docname,
)
continue
Expand Down
7 changes: 2 additions & 5 deletions sphinx/builders/manpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ class ManualPageBuilder(Builder):
def init(self) -> None:
if not self.config.man_pages:
logger.warning(
__(
'no "man_pages" config value found; no manual pages '
'will be written'
)
__('no "man_pages" config value found; no manual pages will be written')
)

def get_outdated_docs(self) -> str | list[str]:
Expand All @@ -73,7 +70,7 @@ def write_documents(self, _docnames: Set[str]) -> None:
docname, name, description, authors, section = info
if docname not in self.env.all_docs:
logger.warning(
__('"man_pages" config value references unknown ' 'document %s'),
__('"man_pages" config value references unknown document %s'),
docname,
)
continue
Expand Down
8 changes: 3 additions & 5 deletions sphinx/cmd/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ def get_parser() -> argparse.ArgumentParser:
'-a',
action='store_true',
dest='force_all',
help=__('write all files (default: only write new and ' 'changed files)'),
help=__('write all files (default: only write new and changed files)'),
)
group.add_argument(
'--fresh-env',
'-E',
action='store_true',
dest='freshenv',
help=__("don't use a saved environment, always read " 'all files'),
help=__("don't use a saved environment, always read all files"),
)

group = parser.add_argument_group(__('path options'))
Expand All @@ -243,9 +243,7 @@ def get_parser() -> argparse.ArgumentParser:
'-c',
metavar='PATH',
dest='confdir',
help=__(
'directory for the configuration file (conf.py) ' '(default: SOURCE_DIR)'
),
help=__('directory for the configuration file (conf.py) (default: SOURCE_DIR)'),
)

group = parser.add_argument_group('build configuration options')
Expand Down
2 changes: 1 addition & 1 deletion sphinx/cmd/make_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
(
'',
'doctest',
'to run all doctests embedded in the documentation ' '(if enabled)',
'to run all doctests embedded in the documentation (if enabled)',
),
('', 'coverage', 'to run coverage check of the documentation (if enabled)'),
('', 'clean', 'to remove everything in the build directory'),
Expand Down
2 changes: 1 addition & 1 deletion sphinx/cmd/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def write_file(fpath: str, content: str, newline: str | None = None) -> None:
end='',
)
if d['makefile'] or d['batchfile']:
print(__('Use the Makefile to build the docs, like so:\n' ' make builder'))
print(__('Use the Makefile to build the docs, like so:\n make builder'))
else:
print(
__(
Expand Down
2 changes: 1 addition & 1 deletion sphinx/environment/adapters/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _toctree_entry(
else:
if ref in parents:
logger.warning(
__('circular toctree references ' 'detected, ignoring: %s <- %s'),
__('circular toctree references detected, ignoring: %s <- %s'),
ref,
' <- '.join(parents),
location=ref,
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/intersphinx/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _fetch_inventory_group(
else:
issues = '\n'.join(f[0] % f[1:] for f in failures)
LOGGER.warning(
__('failed to reach any of the inventories ' 'with the following issues:')
__('failed to reach any of the inventories with the following issues:')
+ '\n'
+ issues
)
Expand Down
2 changes: 1 addition & 1 deletion sphinx/testing/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from collections.abc import Callable

warnings.warn(
"'sphinx.testing.path' is deprecated. " "Use 'os.path' or 'pathlib' instead.",
"'sphinx.testing.path' is deprecated. Use 'os.path' or 'pathlib' instead.",
RemovedInSphinx90Warning,
stacklevel=2,
)
Expand Down
12 changes: 6 additions & 6 deletions sphinx/testing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def assert_node(node: Node, cls: Any = None, xpath: str = '', **kwargs: Any) ->
assert (
isinstance(node, nodes.Element)
), f'The node{xpath} does not have any children' # fmt: skip
assert (
len(node) == 1
), f'The node{xpath} has {len(node)} child nodes, not one'
assert len(node) == 1, (
f'The node{xpath} has {len(node)} child nodes, not one'
)
assert_node(node[0], cls[1:], xpath=xpath + '[0]', **kwargs)
elif isinstance(cls, tuple):
assert (
Expand Down Expand Up @@ -71,9 +71,9 @@ def assert_node(node: Node, cls: Any = None, xpath: str = '', **kwargs: Any) ->
if (key := key.replace('_', '-')) not in node:
msg = f'The node{xpath} does not have {key!r} attribute: {node!r}'
raise AssertionError(msg)
assert (
node[key] == value
), f'The node{xpath}[{key}] is not {value!r}: {node[key]!r}'
assert node[key] == value, (
f'The node{xpath}[{key}] is not {value!r}: {node[key]!r}'
)


# keep this to restrict the API usage and to have a correct return type
Expand Down
8 changes: 4 additions & 4 deletions sphinx/writers/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ def visit_reference(self, node: Element) -> None:
atts['href'] = self.cloak_mailto(atts['href'])
self.in_mailto = True
else:
assert (
'refid' in node
), 'References must have "refuri" or "refid" attribute.'
assert 'refid' in node, (
'References must have "refuri" or "refid" attribute.'
)
atts['href'] = '#' + node['refid']
if not isinstance(node.parent, nodes.TextElement):
assert len(node) == 1 and isinstance(node[0], nodes.image) # NoQA: PT018
Expand Down Expand Up @@ -388,7 +388,7 @@ def get_secnumber(self, node: Element) -> tuple[int, ...] | None:
if isinstance(node.parent, nodes.section):
if self.builder.name == 'singlehtml':
docname = self.docnames[-1]
anchorname = f"{docname}/#{node.parent['ids'][0]}"
anchorname = f'{docname}/#{node.parent["ids"][0]}'
if anchorname not in self.builder.secnumbers:
# try first heading which has no anchor
anchorname = f'{docname}/'
Expand Down
4 changes: 2 additions & 2 deletions sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ def visit_math(self, node: Element) -> None:

def visit_math_block(self, node: Element) -> None:
if node.get('label'):
label = f"equation:{node['docname']}:{node['label']}"
label = f'equation:{node["docname"]}:{node["label"]}'
else:
label = None

Expand All @@ -2477,7 +2477,7 @@ def visit_math_block(self, node: Element) -> None:
raise nodes.SkipNode

def visit_math_reference(self, node: Element) -> None:
label = f"equation:{node['docname']}:{node['target']}"
label = f'equation:{node["docname"]}:{node["target"]}'
eqref_format = self.config.math_eqref_format
if eqref_format:
try:
Expand Down
2 changes: 1 addition & 1 deletion sphinx/writers/manpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def header(self) -> str:
' "%(date)s" "%(version)s" "%(manual_group)s"\n'
)
if self._docinfo['subtitle']:
tmpl += '.SH NAME\n' '%(title)s \\- %(subtitle)s\n'
tmpl += '.SH NAME\n%(title)s \\- %(subtitle)s\n'
return tmpl % self._docinfo

def visit_start_of_file(self, node: Element) -> None:
Expand Down
17 changes: 9 additions & 8 deletions sphinx/writers/texinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ def init_settings(self) -> None:
'(%s)' % elements['filename'],
self.escape_arg(self.settings.texinfo_dir_description),
)
elements['direntry'] = (
'@dircategory %s\n' '@direntry\n' '%s' '@end direntry\n'
) % (self.escape_id(self.settings.texinfo_dir_category), entry)
elements['direntry'] = ('@dircategory %s\n@direntry\n%s@end direntry\n') % (
self.escape_id(self.settings.texinfo_dir_category),
entry,
)
elements['copying'] = COPYING % elements
# allow the user to override them all
elements.update(self.settings.texinfo_elements)
Expand Down Expand Up @@ -448,10 +449,10 @@ def _add_detailed_menu(name: str) -> None:
for subentry in entries:
_add_detailed_menu(subentry)

self.body.append('\n@detailmenu\n' ' --- The Detailed Node Listing ---\n')
self.body.append('\n@detailmenu\n --- The Detailed Node Listing ---\n')
for entry in entries:
_add_detailed_menu(entry)
self.body.append('\n@end detailmenu\n' '@end menu\n')
self.body.append('\n@end detailmenu\n@end menu\n')

def tex_image_length(self, width_str: str) -> str:
match = re.match(r'(\d*\.?\d*)\s*(\S*)', width_str)
Expand Down Expand Up @@ -1119,7 +1120,7 @@ def _visit_named_admonition(self, node: Element) -> None:

def depart_admonition(self, node: Element) -> None:
self.ensure_eol()
self.body.append('@end quotation\n' '@end cartouche\n')
self.body.append('@end quotation\n@end cartouche\n')

visit_attention = _visit_named_admonition
depart_attention = depart_admonition
Expand Down Expand Up @@ -1236,7 +1237,7 @@ def visit_image(self, node: Element) -> None:
width = self.tex_image_length(node.get('width', ''))
height = self.tex_image_length(node.get('height', ''))
alt = self.escape_arg(node.get('alt', ''))
filename = f"{self.elements['filename'][:-5]}-figures/{name}" # type: ignore[index]
filename = f'{self.elements["filename"][:-5]}-figures/{name}' # type: ignore[index]
self.body.append(f'\n@image{{{filename},{width},{height},{alt},{ext[1:]}}}\n')

def depart_image(self, node: Element) -> None:
Expand Down Expand Up @@ -1280,7 +1281,7 @@ def visit_substitution_definition(self, node: Element) -> None:

def visit_system_message(self, node: Element) -> None:
self.body.append(
'\n@verbatim\n' '<SYSTEM MESSAGE: %s>\n' '@end verbatim\n' % node.astext()
'\n@verbatim\n<SYSTEM MESSAGE: %s>\n@end verbatim\n' % node.astext()
)
raise nodes.SkipNode

Expand Down
7 changes: 2 additions & 5 deletions tests/test_builders/test_build_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ def test_html_raw_directive(app):
[
(".//link[@href='_static/persistent.css'][@rel='stylesheet']", '', True),
(
".//link[@href='_static/default.css']"
"[@rel='stylesheet']"
"[@title='Default']",
".//link[@href='_static/default.css'][@rel='stylesheet'][@title='Default']",
'',
True,
),
Expand Down Expand Up @@ -339,8 +337,7 @@ def test_html_raw_directive(app):
True,
),
(
".//link[@href='_static/more_alternate2.css']"
"[@rel='alternate stylesheet']",
".//link[@href='_static/more_alternate2.css'][@rel='alternate stylesheet']",
'',
True,
),
Expand Down
3 changes: 1 addition & 2 deletions tests/test_builders/test_build_html_5_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ def checker(nodes: Iterable[Element]) -> Literal[True]:
),
(
'markup.html',
".//a[@href='#with']"
"[@class='reference internal']/code/span[@class='pre']",
".//a[@href='#with'][@class='reference internal']/code/span[@class='pre']",
'^with$',
),
(
Expand Down
36 changes: 13 additions & 23 deletions tests/test_builders/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ def test_numref(app):
print(app.status.getvalue())
print(app.warning.getvalue())
assert (
'\\hyperref[\\detokenize{index:fig1}]'
'{Fig.\\@ \\ref{\\detokenize{index:fig1}}}'
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\@ \\ref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}'
Expand All @@ -400,8 +399,7 @@ def test_numref(app):
'{Table \\ref{\\detokenize{index:table-1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:table22}]'
'{Table:\\ref{\\detokenize{baz:table22}}}'
'\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:code-1}]'
Expand Down Expand Up @@ -462,8 +460,7 @@ def test_numref_with_prefix1(app):
assert '\\ref{\\detokenize{index:code-1}}' in result
assert '\\ref{\\detokenize{baz:code22}}' in result
assert (
'\\hyperref[\\detokenize{index:fig1}]'
'{Figure:\\ref{\\detokenize{index:fig1}}}'
'\\hyperref[\\detokenize{index:fig1}]{Figure:\\ref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}'
Expand All @@ -473,8 +470,7 @@ def test_numref_with_prefix1(app):
'{Tab\\_\\ref{\\detokenize{index:table-1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:table22}]'
'{Table:\\ref{\\detokenize{baz:table22}}}'
'\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:code-1}]'
Expand Down Expand Up @@ -540,8 +536,7 @@ def test_numref_with_prefix2(app):
'{Tab\\_\\ref{\\detokenize{index:table-1}}:}'
) in result
assert (
'\\hyperref[\\detokenize{baz:table22}]'
'{Table:\\ref{\\detokenize{baz:table22}}}'
'\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:code-1}]{Code\\sphinxhyphen{}\\ref{\\detokenize{index:code-1}} '
Expand All @@ -552,8 +547,7 @@ def test_numref_with_prefix2(app):
'{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}'
) in result
assert (
'\\hyperref[\\detokenize{foo:foo}]'
'{SECTION\\_\\ref{\\detokenize{foo:foo}}\\_}'
'\\hyperref[\\detokenize{foo:foo}]{SECTION\\_\\ref{\\detokenize{foo:foo}}\\_}'
) in result
assert (
'\\hyperref[\\detokenize{bar:bar-a}]'
Expand Down Expand Up @@ -590,8 +584,7 @@ def test_numref_with_language_ja(app):
print(app.status.getvalue())
print(app.warning.getvalue())
assert (
'\\hyperref[\\detokenize{index:fig1}]'
'{\u56f3 \\ref{\\detokenize{index:fig1}}}'
'\\hyperref[\\detokenize{index:fig1}]{\u56f3 \\ref{\\detokenize{index:fig1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}'
Expand All @@ -601,8 +594,7 @@ def test_numref_with_language_ja(app):
'{\u8868 \\ref{\\detokenize{index:table-1}}}'
) in result
assert (
'\\hyperref[\\detokenize{baz:table22}]'
'{Table:\\ref{\\detokenize{baz:table22}}}'
'\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}'
) in result
assert (
'\\hyperref[\\detokenize{index:code-1}]'
Expand Down Expand Up @@ -937,8 +929,7 @@ def test_footnote(app):
'numbered\n%\n\\end{footnote}'
) in result
assert (
'\\begin{footnote}[2]\\sphinxAtStartFootnote\nauto numbered\n%\n'
'\\end{footnote}'
'\\begin{footnote}[2]\\sphinxAtStartFootnote\nauto numbered\n%\n\\end{footnote}'
) in result
assert (
'\\begin{footnote}[3]\\sphinxAtStartFootnote\nnamed\n%\n\\end{footnote}'
Expand Down Expand Up @@ -1880,8 +1871,7 @@ def test_latex_nested_enumerated_list(app):

result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
assert (
'\\sphinxsetlistlabels{\\arabic}{enumi}{enumii}{}{.}%\n'
'\\setcounter{enumi}{4}\n'
'\\sphinxsetlistlabels{\\arabic}{enumi}{enumii}{}{.}%\n\\setcounter{enumi}{4}\n'
) in result
assert (
'\\sphinxsetlistlabels{\\alph}{enumii}{enumiii}{}{.}%\n'
Expand Down Expand Up @@ -2201,9 +2191,9 @@ def test_duplicated_labels_before_module(app):
):
tex_label_name = 'index:' + rst_label_name.replace('_', '-')
tex_label_code = r'\phantomsection\label{\detokenize{%s}}' % tex_label_name
assert (
content.count(tex_label_code) == 1
), f'duplicated label: {tex_label_name!r}'
assert content.count(tex_label_code) == 1, (
f'duplicated label: {tex_label_name!r}'
)
tested_labels.add(tex_label_code)

# ensure that we did not forget any label to check
Expand Down
Loading

0 comments on commit ce595dd

Please sign in to comment.