mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Bump Ruff to 0.3.7
This commit is contained in:
@@ -19,6 +19,7 @@ ignore = [
|
||||
"E741", # Ambiguous variable name: `{name}`
|
||||
"F841", # Local variable `{name}` is assigned to but never used
|
||||
"FURB101", # `open` and `read` should be replaced by `Path(...).read_text(...)`
|
||||
"FURB103", # `open` and `write` should be replaced by `Path(...).write_text(...)`
|
||||
"PLC1901", # simplify truthy/falsey string comparisons
|
||||
"SIM102", # Use a single `if` statement instead of nested `if` statements
|
||||
"SIM108", # Use ternary operator `{contents}` instead of `if`-`else`-block
|
||||
@@ -370,7 +371,10 @@ select = [
|
||||
"doc/conf.py" = ["INP001", "W605"]
|
||||
"doc/development/tutorials/examples/*" = ["INP001"]
|
||||
# allow print() in the tutorial
|
||||
"doc/development/tutorials/examples/recipe.py" = ["T201"]
|
||||
"doc/development/tutorials/examples/recipe.py" = [
|
||||
"FURB118",
|
||||
"T201"
|
||||
]
|
||||
"sphinx/domains/**" = ["FURB113"]
|
||||
"tests/test_domains/test_domain_cpp.py" = ["FURB113"]
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ docs = [
|
||||
]
|
||||
lint = [
|
||||
"flake8>=3.5.0",
|
||||
"ruff==0.3.4",
|
||||
"ruff==0.3.7",
|
||||
"mypy==1.9.0",
|
||||
"sphinx-lint",
|
||||
"types-docutils",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import operator
|
||||
import time
|
||||
from codecs import open
|
||||
from collections import defaultdict
|
||||
@@ -281,7 +282,7 @@ class MessageCatalogBuilder(I18nBuilder):
|
||||
__("writing message catalogs... "),
|
||||
"darkgreen", len(self.catalogs),
|
||||
self.app.verbosity,
|
||||
lambda textdomain__: textdomain__[0]):
|
||||
operator.itemgetter(0)):
|
||||
# noop if config.gettext_compact is set
|
||||
ensuredir(path.join(self.outdir, path.dirname(textdomain)))
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import operator
|
||||
import posixpath
|
||||
import traceback
|
||||
from importlib import import_module
|
||||
@@ -254,7 +255,7 @@ def collect_pages(app: Sphinx) -> Iterator[tuple[str, dict[str, Any], str]]:
|
||||
sorted(env._viewcode_modules.items()),
|
||||
__('highlighting module code... '), "blue",
|
||||
len(env._viewcode_modules),
|
||||
app.verbosity, lambda x: x[0]):
|
||||
app.verbosity, operator.itemgetter(0)):
|
||||
if not entry:
|
||||
continue
|
||||
if not should_generate_module_page(app, modname):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""Test the search index builder."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import warnings
|
||||
@@ -308,6 +309,24 @@ def test_parallel(app):
|
||||
|
||||
@pytest.mark.sphinx(testroot='search')
|
||||
def test_search_index_is_deterministic(app):
|
||||
app.build(force_all=True)
|
||||
index = load_searchindex(app.outdir / 'searchindex.js')
|
||||
# Pretty print the index. Only shown by pytest on failure.
|
||||
print(f'searchindex.js contents:\n\n{json.dumps(index, indent=2)}')
|
||||
assert_is_sorted(index, '')
|
||||
|
||||
|
||||
def is_title_tuple_type(item: list[int | str]):
|
||||
"""
|
||||
In the search index, titles inside .alltitles are stored as a tuple of
|
||||
(document_idx, title_anchor). Tuples are represented as lists in JSON,
|
||||
but their contents must not be sorted. We cannot sort them anyway, as
|
||||
document_idx is an int and title_anchor is a str.
|
||||
"""
|
||||
return len(item) == 2 and isinstance(item[0], int) and isinstance(item[1], str)
|
||||
|
||||
|
||||
def assert_is_sorted(item, path: str):
|
||||
lists_not_to_sort = {
|
||||
# Each element of .titles is related to the element of .docnames in the same position.
|
||||
# The ordering is deterministic because .docnames is sorted.
|
||||
@@ -317,27 +336,13 @@ def test_search_index_is_deterministic(app):
|
||||
'.filenames',
|
||||
}
|
||||
|
||||
# In the search index, titles inside .alltitles are stored as a tuple of
|
||||
# (document_idx, title_anchor). Tuples are represented as lists in JSON,
|
||||
# but their contents must not be sorted. We cannot sort them anyway, as
|
||||
# document_idx is an int and title_anchor is a str.
|
||||
def is_title_tuple_type(item):
|
||||
return len(item) == 2 and isinstance(item[0], int) and isinstance(item[1], str)
|
||||
|
||||
def assert_is_sorted(item, path):
|
||||
err_path = path if path else '<root>'
|
||||
if isinstance(item, dict):
|
||||
assert list(item.keys()) == sorted(item.keys()), f'{err_path} is not sorted'
|
||||
for key, value in item.items():
|
||||
assert_is_sorted(value, f'{path}.{key}')
|
||||
elif isinstance(item, list):
|
||||
if not is_title_tuple_type(item) and path not in lists_not_to_sort:
|
||||
assert item == sorted(item), f'{err_path} is not sorted'
|
||||
for i, child in enumerate(item):
|
||||
assert_is_sorted(child, f'{path}[{i}]')
|
||||
|
||||
app.build(force_all=True)
|
||||
index = load_searchindex(app.outdir / 'searchindex.js')
|
||||
# Pretty print the index. Only shown by pytest on failure.
|
||||
print(f'searchindex.js contents:\n\n{json.dumps(index, indent=2)}')
|
||||
assert_is_sorted(index, '')
|
||||
err_path = path or '<root>'
|
||||
if isinstance(item, dict):
|
||||
assert list(item.keys()) == sorted(item.keys()), f'{err_path} is not sorted'
|
||||
for key, value in item.items():
|
||||
assert_is_sorted(value, f'{path}.{key}')
|
||||
elif isinstance(item, list):
|
||||
if not is_title_tuple_type(item) and path not in lists_not_to_sort:
|
||||
assert item == sorted(item), f'{err_path} is not sorted'
|
||||
for i, child in enumerate(item):
|
||||
assert_is_sorted(child, f'{path}[{i}]')
|
||||
|
||||
Reference in New Issue
Block a user