Skip to content

Commit 3bedde2

Browse files
authored
🔧 Ruff format python files within docs folder (sphinx-doc#12139)
Remove `docs` files from the `exclude` list, and also add the `preview = false` format config, which is shown to reduce diffs to the current code base
1 parent d93223a commit 3bedde2

File tree

8 files changed

+135
-98
lines changed

8 files changed

+135
-98
lines changed

‎.ruff.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ forced-separate = [
423423
]
424424

425425
[format]
426+
preview = true
426427
quote-style = "single"
427428
exclude = [
428-
"doc/**/*",
429429
"sphinx/__init__.py",
430430
"sphinx/addnodes.py",
431431
"sphinx/application.py",

‎doc/conf.py‎

Lines changed: 86 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88

99
os.environ['SPHINX_AUTODOC_RELOAD_MODULES'] = '1'
1010

11-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo',
12-
'sphinx.ext.autosummary', 'sphinx.ext.extlinks',
13-
'sphinx.ext.intersphinx',
14-
'sphinx.ext.viewcode', 'sphinx.ext.inheritance_diagram',
15-
'sphinx.ext.coverage']
11+
extensions = [
12+
'sphinx.ext.autodoc',
13+
'sphinx.ext.doctest',
14+
'sphinx.ext.todo',
15+
'sphinx.ext.autosummary',
16+
'sphinx.ext.extlinks',
17+
'sphinx.ext.intersphinx',
18+
'sphinx.ext.viewcode',
19+
'sphinx.ext.inheritance_diagram',
20+
'sphinx.ext.coverage',
21+
]
1622
coverage_statistics_to_report = coverage_statistics_to_stdout = True
1723
templates_path = ['_templates']
1824
exclude_patterns = ['_build']
@@ -49,40 +55,47 @@
4955
epub_scheme = 'url'
5056
epub_identifier = epub_publisher
5157
epub_pre_files = [('index.xhtml', 'Welcome')]
52-
epub_post_files = [('usage/installation.xhtml', 'Installing Sphinx'),
53-
('develop.xhtml', 'Sphinx development')]
54-
epub_exclude_files = ['_static/opensearch.xml', '_static/doctools.js',
55-
'_static/searchtools.js',
56-
'_static/sphinx_highlight.js',
57-
'_static/basic.css',
58-
'_static/language_data.js',
59-
'search.html', '_static/websupport.js']
58+
epub_post_files = [
59+
('usage/installation.xhtml', 'Installing Sphinx'),
60+
('develop.xhtml', 'Sphinx development'),
61+
]
62+
epub_exclude_files = [
63+
'_static/opensearch.xml',
64+
'_static/doctools.js',
65+
'_static/searchtools.js',
66+
'_static/sphinx_highlight.js',
67+
'_static/basic.css',
68+
'_static/language_data.js',
69+
'search.html',
70+
'_static/websupport.js',
71+
]
6072
epub_fix_images = False
6173
epub_max_image_width = 0
6274
epub_show_urls = 'inline'
6375
epub_use_index = False
6476
epub_description = 'Sphinx documentation generator system manual'
6577

66-
latex_documents = [('index', 'sphinx.tex', 'Sphinx Documentation',
67-
'the Sphinx developers', 'manual', 1)]
78+
latex_documents = [
79+
('index', 'sphinx.tex', 'Sphinx Documentation', 'the Sphinx developers', 'manual', 1)
80+
]
6881
latex_logo = '_static/sphinx.png'
6982
latex_elements = {
7083
'fontenc': r'\usepackage[LGR,X2,T1]{fontenc}',
71-
'passoptionstopackages': r'''
84+
'passoptionstopackages': r"""
7285
\PassOptionsToPackage{svgnames}{xcolor}
73-
''',
74-
'preamble': r'''
86+
""",
87+
'preamble': r"""
7588
\DeclareUnicodeCharacter{229E}{\ensuremath{\boxplus}}
7689
\setcounter{tocdepth}{3}% depth of what main TOC shows (3=subsubsection)
7790
\setcounter{secnumdepth}{1}% depth of section numbering
7891
\setlength{\tymin}{2cm}% avoid too cramped table columns
79-
''',
92+
""",
8093
# fix missing index entry due to RTD doing only once pdflatex after makeindex
81-
'printindex': r'''
94+
'printindex': r"""
8295
\IfFileExists{\jobname.ind}
8396
{\footnotesize\raggedright\printindex}
8497
{\begin{sphinxtheindex}\end{sphinxtheindex}}
85-
''',
98+
""",
8699
}
87100
latex_show_urls = 'footnote'
88101
latex_use_xindy = True
@@ -92,30 +105,46 @@
92105
autodoc_member_order = 'groupwise'
93106
autosummary_generate = False
94107
todo_include_todos = True
95-
extlinks = {'duref': ('https://docutils.sourceforge.io/docs/ref/rst/'
96-
'restructuredtext.html#%s', '%s'),
97-
'durole': ('https://docutils.sourceforge.io/docs/ref/rst/'
98-
'roles.html#%s', '%s'),
99-
'dudir': ('https://docutils.sourceforge.io/docs/ref/rst/'
100-
'directives.html#%s', '%s')}
108+
extlinks = {
109+
'duref': (
110+
'https://docutils.sourceforge.io/docs/ref/rst/' 'restructuredtext.html#%s',
111+
'%s',
112+
),
113+
'durole': ('https://docutils.sourceforge.io/docs/ref/rst/' 'roles.html#%s', '%s'),
114+
'dudir': ('https://docutils.sourceforge.io/docs/ref/rst/' 'directives.html#%s', '%s'),
115+
}
101116

102117
man_pages = [
103-
('index', 'sphinx-all', 'Sphinx documentation generator system manual',
104-
'the Sphinx developers', 1),
105-
('man/sphinx-build', 'sphinx-build', 'Sphinx documentation generator tool',
106-
'', 1),
107-
('man/sphinx-quickstart', 'sphinx-quickstart', 'Sphinx documentation '
108-
'template generator', '', 1),
109-
('man/sphinx-apidoc', 'sphinx-apidoc', 'Sphinx API doc generator tool',
110-
'', 1),
111-
('man/sphinx-autogen', 'sphinx-autogen', 'Generate autodoc stub pages',
112-
'', 1),
118+
(
119+
'index',
120+
'sphinx-all',
121+
'Sphinx documentation generator system manual',
122+
'the Sphinx developers',
123+
1,
124+
),
125+
('man/sphinx-build', 'sphinx-build', 'Sphinx documentation generator tool', '', 1),
126+
(
127+
'man/sphinx-quickstart',
128+
'sphinx-quickstart',
129+
'Sphinx documentation ' 'template generator',
130+
'',
131+
1,
132+
),
133+
('man/sphinx-apidoc', 'sphinx-apidoc', 'Sphinx API doc generator tool', '', 1),
134+
('man/sphinx-autogen', 'sphinx-autogen', 'Generate autodoc stub pages', '', 1),
113135
]
114136

115137
texinfo_documents = [
116-
('index', 'sphinx', 'Sphinx Documentation', 'the Sphinx developers',
117-
'Sphinx', 'The Sphinx documentation builder.', 'Documentation tools',
118-
1),
138+
(
139+
'index',
140+
'sphinx',
141+
'Sphinx Documentation',
142+
'the Sphinx developers',
143+
'Sphinx',
144+
'The Sphinx documentation builder.',
145+
'Documentation tools',
146+
1,
147+
),
119148
]
120149

121150
intersphinx_mapping = {
@@ -129,7 +158,10 @@
129158
gettext_compact = False
130159

131160
nitpick_ignore = {
132-
('cpp:class', 'template<typename TOuter> template<typename TInner> Wrapper::Outer<TOuter>::Inner'), # NoQA: E501
161+
(
162+
'cpp:class',
163+
'template<typename TOuter> template<typename TInner> Wrapper::Outer<TOuter>::Inner',
164+
), # NoQA: E501
133165
('cpp:identifier', 'MyContainer'),
134166
('js:func', 'SomeError'),
135167
('js:func', 'number'),
@@ -213,13 +245,13 @@ def parse_event(env, sig, signode):
213245
def linkify_issues_in_changelog(app, docname, source):
214246
"""Linkify issue references like #123 in changelog to GitHub."""
215247
if docname == 'changes':
216-
changelog_path = os.path.join(os.path.dirname(__file__), "../CHANGES.rst")
248+
changelog_path = os.path.join(os.path.dirname(__file__), '../CHANGES.rst')
217249
# this path trickery is needed because this script can
218250
# be invoked with different working directories:
219251
# * running make in docs/
220252
# * running tox -e docs in the repo root dir
221253

222-
with open(changelog_path, encoding="utf-8") as f:
254+
with open(changelog_path, encoding='utf-8') as f:
223255
changelog = f.read()
224256

225257
def linkify(match):
@@ -234,12 +266,16 @@ def linkify(match):
234266
def setup(app):
235267
from sphinx.ext.autodoc import cut_lines
236268
from sphinx.util.docfields import GroupedField
269+
237270
app.connect('autodoc-process-docstring', cut_lines(4, what=['module']))
238271
app.connect('source-read', linkify_issues_in_changelog)
239-
app.add_object_type('confval', 'confval',
240-
objname='configuration value',
241-
indextemplate='pair: %s; configuration value')
242-
fdesc = GroupedField('parameter', label='Parameters',
243-
names=['param'], can_collapse=True)
244-
app.add_object_type('event', 'event', 'pair: %s; event', parse_event,
245-
doc_field_types=[fdesc])
272+
app.add_object_type(
273+
'confval',
274+
'confval',
275+
objname='configuration value',
276+
indextemplate='pair: %s; configuration value',
277+
)
278+
fdesc = GroupedField('parameter', label='Parameters', names=['param'], can_collapse=True)
279+
app.add_object_type(
280+
'event', 'event', 'pair: %s; event', parse_event, doc_field_types=[fdesc]
281+
)

‎doc/development/tutorials/examples/autodoc_intenum.py‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class IntEnumDocumenter(ClassDocumenter):
1919
option_spec['hex'] = bool_option
2020

2121
@classmethod
22-
def can_document_member(cls,
23-
member: Any, membername: str,
24-
isattr: bool, parent: Any) -> bool:
22+
def can_document_member(
23+
cls, member: Any, membername: str, isattr: bool, parent: Any
24+
) -> bool:
2525
try:
2626
return issubclass(member, IntEnum)
2727
except TypeError:
@@ -31,11 +31,11 @@ def add_directive_header(self, sig: str) -> None:
3131
super().add_directive_header(sig)
3232
self.add_line(' :final:', self.get_sourcename())
3333

34-
def add_content(self,
35-
more_content: StringList | None,
36-
no_docstring: bool = False,
37-
) -> None:
38-
34+
def add_content(
35+
self,
36+
more_content: StringList | None,
37+
no_docstring: bool = False,
38+
) -> None:
3939
super().add_content(more_content, no_docstring)
4040

4141
source_name = self.get_sourcename()
@@ -48,8 +48,7 @@ def add_content(self,
4848
if use_hex:
4949
the_member_value = hex(the_member_value)
5050

51-
self.add_line(
52-
f"**{the_member_name}**: {the_member_value}", source_name)
51+
self.add_line(f'**{the_member_name}**: {the_member_value}', source_name)
5352
self.add_line('', source_name)
5453

5554

‎doc/development/tutorials/examples/helloworld.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33

44

55
class HelloWorld(Directive):
6-
76
def run(self):
87
paragraph_node = nodes.paragraph(text='Hello World!')
98
return [paragraph_node]
109

1110

1211
def setup(app):
13-
app.add_directive("helloworld", HelloWorld)
12+
app.add_directive('helloworld', HelloWorld)
1413

1514
return {
1615
'version': '0.1',

‎doc/development/tutorials/examples/recipe.py‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def handle_signature(self, sig, signode):
2525
def add_target_and_index(self, name_cls, sig, signode):
2626
signode['ids'].append('recipe' + '-' + sig)
2727
if 'contains' in self.options:
28-
ingredients = [
29-
x.strip() for x in self.options.get('contains').split(',')]
28+
ingredients = [x.strip() for x in self.options.get('contains').split(',')]
3029

3130
recipes = self.env.get_domain('recipe')
3231
recipes.add_recipe(sig, ingredients)
@@ -42,9 +41,10 @@ class IngredientIndex(Index):
4241
def generate(self, docnames=None):
4342
content = defaultdict(list)
4443

45-
recipes = {name: (dispname, typ, docname, anchor)
46-
for name, dispname, typ, docname, anchor, _
47-
in self.domain.get_objects()}
44+
recipes = {
45+
name: (dispname, typ, docname, anchor)
46+
for name, dispname, typ, docname, anchor, _ in self.domain.get_objects()
47+
}
4848
recipe_ingredients = self.domain.data['recipe_ingredients']
4949
ingredient_recipes = defaultdict(list)
5050

@@ -60,8 +60,7 @@ def generate(self, docnames=None):
6060
for ingredient, recipe_names in ingredient_recipes.items():
6161
for recipe_name in recipe_names:
6262
dispname, typ, docname, anchor = recipes[recipe_name]
63-
content[ingredient].append(
64-
(dispname, 0, docname, anchor, docname, '', typ))
63+
content[ingredient].append((dispname, 0, docname, anchor, docname, '', typ))
6564

6665
# convert the dict to the sorted list of tuples expected
6766
content = sorted(content.items())
@@ -88,8 +87,15 @@ def generate(self, docnames=None):
8887
#
8988
# name, subtype, docname, anchor, extra, qualifier, description
9089
for _name, dispname, typ, docname, anchor, _priority in recipes:
91-
content[dispname[0].lower()].append(
92-
(dispname, 0, docname, anchor, docname, '', typ))
90+
content[dispname[0].lower()].append((
91+
dispname,
92+
0,
93+
docname,
94+
anchor,
95+
docname,
96+
'',
97+
typ,
98+
))
9399

94100
# convert the dict to the sorted list of tuples expected
95101
content = sorted(content.items())
@@ -98,7 +104,6 @@ def generate(self, docnames=None):
98104

99105

100106
class RecipeDomain(Domain):
101-
102107
name = 'recipe'
103108
label = 'Recipe Sample'
104109
roles = {
@@ -122,18 +127,18 @@ def get_full_qualified_name(self, node):
122127
def get_objects(self):
123128
yield from self.data['recipes']
124129

125-
def resolve_xref(self, env, fromdocname, builder, typ, target, node,
126-
contnode):
127-
match = [(docname, anchor)
128-
for name, sig, typ, docname, anchor, prio
129-
in self.get_objects() if sig == target]
130+
def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
131+
match = [
132+
(docname, anchor)
133+
for name, sig, typ, docname, anchor, prio in self.get_objects()
134+
if sig == target
135+
]
130136

131137
if len(match) > 0:
132138
todocname = match[0][0]
133139
targ = match[0][1]
134140

135-
return make_refnode(builder, fromdocname, todocname, targ,
136-
contnode, targ)
141+
return make_refnode(builder, fromdocname, todocname, targ, contnode, targ)
137142
else:
138143
print('Awww, found nothing')
139144
return None
@@ -145,8 +150,7 @@ def add_recipe(self, signature, ingredients):
145150

146151
self.data['recipe_ingredients'][name] = ingredients
147152
# name, dispname, type, docname, anchor, priority
148-
self.data['recipes'].append(
149-
(name, signature, 'Recipe', self.env.docname, anchor, 0))
153+
self.data['recipes'].append((name, signature, 'Recipe', self.env.docname, anchor, 0))
150154

151155

152156
def setup(app):

0 commit comments

Comments
 (0)