Skip to content

Commit c5e1b72

Browse files
kartbenjhedberg
authored andcommitted
doc: _extensions: apply ruff format
Documentation extensions are often edited so bite the bullet and apply `ruff format` on them and stop excluding them in ruff-excludes Signed-off-by: Benjamin Cabé <[email protected]>
1 parent 47d521f commit c5e1b72

File tree

13 files changed

+86
-103
lines changed

13 files changed

+86
-103
lines changed

.ruff-excludes.toml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,19 +1225,6 @@ exclude = [
12251225
"./arch/xtensa/core/gen_zsr.py",
12261226
"./arch/xtensa/core/xtensa_intgen.py",
12271227
"./boards/microchip/mec172xevb_assy6906/support/mec172x_remote_flasher.py",
1228-
"./doc/_extensions/zephyr/api_overview.py",
1229-
"./doc/_extensions/zephyr/application.py",
1230-
"./doc/_extensions/zephyr/domain/__init__.py",
1231-
"./doc/_extensions/zephyr/doxybridge.py",
1232-
"./doc/_extensions/zephyr/doxyrunner.py",
1233-
"./doc/_extensions/zephyr/doxytooltip/__init__.py",
1234-
"./doc/_extensions/zephyr/dtcompatible-role.py",
1235-
"./doc/_extensions/zephyr/external_content.py",
1236-
"./doc/_extensions/zephyr/gh_utils.py",
1237-
"./doc/_extensions/zephyr/html_redirects.py",
1238-
"./doc/_extensions/zephyr/kconfig/__init__.py",
1239-
"./doc/_extensions/zephyr/link-roles.py",
1240-
"./doc/_scripts/gen_boards_catalog.py",
12411228
"./doc/_scripts/gen_devicetree_rest.py",
12421229
"./doc/_scripts/redirects.py",
12431230
"./doc/conf.py",

doc/_extensions/zephyr/api_overview.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ def visit_group(self, group, all_groups, rows, indent=0):
8989
github_uri = self.config.api_overview_base_url + "/releases/tag/"
9090
cdef = group.get_compounddef()[0]
9191

92-
ssects = [
93-
s for p in cdef.get_detaileddescription().get_para() for s in p.get_simplesect()
94-
]
92+
ssects = [s for p in cdef.get_detaileddescription().get_para() for s in p.get_simplesect()]
9593
for sect in ssects:
9694
if sect.get_kind() == "since":
9795
since = sect.get_para()[0].get_valueOf_()
@@ -123,7 +121,7 @@ def visit_group(self, group, all_groups, rows, indent=0):
123121

124122
# Next entry will contain the spacer and the link with API name
125123
entry = nodes.entry()
126-
span = nodes.Text("".join(["\U000000A0"] * indent))
124+
span = nodes.Text("".join(["\U000000a0"] * indent))
127125
entry += span
128126

129127
# API name with link
@@ -143,9 +141,7 @@ def visit_group(self, group, all_groups, rows, indent=0):
143141
rows.append(row_node)
144142

145143
for innergroup in cdef.get_innergroup():
146-
self.visit_group(
147-
get_group(innergroup, all_groups), all_groups, rows, indent + 6
148-
)
144+
self.visit_group(get_group(innergroup, all_groups), all_groups, rows, indent + 6)
149145

150146

151147
def setup(app) -> dict[str, Any]:

doc/_extensions/zephyr/application.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
ZEPHYR_BASE = Path(__file__).parents[3]
1313

14+
1415
# TODO: extend and modify this for Windows.
1516
#
1617
# This could be as simple as generating a couple of sets of instructions, one
@@ -20,6 +21,7 @@ class ZephyrAppCommandsDirective(Directive):
2021
This is a Zephyr directive for generating consistent documentation
2122
of the shell commands needed to manage (build, flash, etc.) an application.
2223
'''
24+
2325
has_content = False
2426
required_arguments = 0
2527
optional_arguments = 0
@@ -119,10 +121,8 @@ def run(self):
119121
build_dir = ('build' + '/' + build_dir_append).rstrip('/')
120122

121123
# Prepare repeatable arguments
122-
host_os = [host_os] if host_os != "all" else [v for v in self.HOST_OS
123-
if v != 'all']
124-
tools = [tool] if tool != "all" else [v for v in self.TOOLS
125-
if v != 'all']
124+
host_os = [host_os] if host_os != "all" else [v for v in self.HOST_OS if v != 'all']
125+
tools = [tool] if tool != "all" else [v for v in self.TOOLS if v != 'all']
126126
build_args_list = build_args.split(' ') if build_args is not None else None
127127
snippet_list = snippets.split(',') if snippets is not None else None
128128
shield_list = shield.split(',') if shield is not None else None
@@ -155,7 +155,7 @@ def run(self):
155155
'debug_args': debug_args,
156156
'debugserver_args': debugserver_args,
157157
'attach_args': attach_args,
158-
}
158+
}
159159

160160
if 'west' in tools:
161161
w = self._generate_west(**run_config)
@@ -171,8 +171,7 @@ def run(self):
171171
c = self._generate_cmake(**run_config)
172172
if tool_comment:
173173
paragraph = nodes.paragraph()
174-
paragraph += nodes.Text(tool_comment.format(
175-
f'CMake and {generator}'))
174+
paragraph += nodes.Text(tool_comment.format(f'CMake and {generator}'))
176175
content.append(paragraph)
177176
content.append(self._lit_block(c))
178177
else:
@@ -284,8 +283,10 @@ def _generate_west(self, **kwargs):
284283
def _mkdir(mkdir, build_dir, host_os, skip_config):
285284
content = []
286285
if skip_config:
287-
content.append(f"# If you already made a build directory ({build_dir}) and ran cmake, "
288-
f"just 'cd {build_dir}' instead.")
286+
content.append(
287+
f"# If you already made a build directory ({build_dir}) and ran cmake, "
288+
f"just 'cd {build_dir}' instead."
289+
)
289290
if host_os == 'all':
290291
content.append(f'mkdir {build_dir} && cd {build_dir}')
291292
if host_os == "unix":
@@ -320,8 +321,7 @@ def _cd_into(self, mkdir, **kwargs):
320321
if not app and mkdir and num_slashes == 0:
321322
# When there's no app and a single level deep build dir,
322323
# simplify output
323-
content.extend(self._mkdir(mkdir, build_dir, 'all',
324-
skip_config))
324+
content.extend(self._mkdir(mkdir, build_dir, 'all', skip_config))
325325
if not compact:
326326
content.append('')
327327
return content
@@ -383,16 +383,20 @@ def _generate_cmake(self, **kwargs):
383383

384384
if not compact:
385385
if not cd_into and skip_config:
386-
content.append(f'# If you already ran cmake with -B{build_dir}, you '
387-
f'can skip this step and run {generator} directly.')
386+
content.append(
387+
f'# If you already ran cmake with -B{build_dir}, you '
388+
f'can skip this step and run {generator} directly.'
389+
)
388390
else:
389-
content.append(f'# Use cmake to configure a {generator.capitalize()}-based build'
390-
'system:')
391+
content.append(
392+
f'# Use cmake to configure a {generator.capitalize()}-based buildsystem:'
393+
)
391394

392-
content.append(f'cmake{cmake_build_dir}{gen_arg}{cmake_args}{snippet_args}{shield_args}{source_dir}')
395+
content.append(
396+
f'cmake{cmake_build_dir}{gen_arg}{cmake_args}{snippet_args}{shield_args}{source_dir}'
397+
)
393398
if not compact:
394-
content.extend(['',
395-
'# Now run the build tool on the generated build system:'])
399+
content.extend(['', '# Now run the build tool on the generated build system:'])
396400

397401
if 'build' in goals:
398402
content.append(f'{generator}{tool_build_dir}{build_args}')
@@ -407,8 +411,4 @@ def _generate_cmake(self, **kwargs):
407411
def setup(app):
408412
app.add_directive('zephyr-app-commands', ZephyrAppCommandsDirective)
409413

410-
return {
411-
'version': '1.0',
412-
'parallel_read_safe': True,
413-
'parallel_write_safe': True
414-
}
414+
return {'version': '1.0', 'parallel_read_safe': True, 'parallel_write_safe': True}

doc/_extensions/zephyr/domain/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,18 @@ def convert_node(self, node):
221221
json_ld = nodes.raw(
222222
"",
223223
f"""<script type="application/ld+json">
224-
{json.dumps({
225-
"@context": "http://schema.org",
226-
"@type": "SoftwareSourceCode",
227-
"name": node['name'],
228-
"description": node.children[0].astext(),
229-
"codeSampleType": "full",
230-
"codeRepository": gh_link_get_url(self.app, self.env.docname)
231-
})}
224+
{
225+
json.dumps(
226+
{
227+
"@context": "http://schema.org",
228+
"@type": "SoftwareSourceCode",
229+
"name": node['name'],
230+
"description": node.children[0].astext(),
231+
"codeSampleType": "full",
232+
"codeRepository": gh_link_get_url(self.app, self.env.docname),
233+
}
234+
)
235+
}
232236
</script>""",
233237
format="html",
234238
)

doc/_extensions/zephyr/doxybridge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class DoxygenGroupDirective(SphinxDirective):
4040
}
4141

4242
def run(self):
43-
4443
desc_node = addnodes.desc()
4544
desc_node["domain"] = "c"
4645
desc_node["objtype"] = "group"
@@ -52,7 +51,7 @@ def run(self):
5251
reftype="group",
5352
reftarget=self.arguments[0],
5453
refwarn=True,
55-
project=self.options.get("project")
54+
project=self.options.get("project"),
5655
)
5756
group_xref += nodes.Text(self.arguments[0])
5857
title_signode += group_xref

doc/_extensions/zephyr/doxyrunner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def hash_file(file: Path) -> str:
7878

7979
return sha256.hexdigest()
8080

81+
8182
def get_doxygen_option(doxyfile: str, option: str) -> list[str]:
8283
"""Obtain the value of a Doxygen option.
8384

doc/_extensions/zephyr/doxytooltip/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
RESOURCES_DIR = Path(__file__).parent / "static"
2121

22+
2223
def setup(app: Sphinx) -> dict[str, Any]:
2324
app.config.html_static_path.append(RESOURCES_DIR.as_posix())
2425

doc/_extensions/zephyr/dtcompatible-role.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
in the right places.
1212
"""
1313

14+
1415
def setup(app):
1516
app.add_crossref_type('dtcompatible', 'dtcompatible')
1617

doc/_extensions/zephyr/external_content.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ def sync_contents(app: Sphinx) -> None:
102102
to_copy = []
103103
to_delete = set(f for f in srcdir.glob("**/*") if not f.is_dir())
104104
to_keep = set(
105-
f
106-
for k in app.config.external_content_keep
107-
for f in srcdir.glob(k)
108-
if not f.is_dir()
105+
f for k in app.config.external_content_keep for f in srcdir.glob(k) if not f.is_dir()
109106
)
110107

111108
def _pattern_excludes(f):
@@ -117,8 +114,11 @@ def _pattern_excludes(f):
117114
for src in prefix_src.glob(glob):
118115
if src.is_dir():
119116
to_copy.extend(
120-
[(f, prefix_src) for f in src.glob("**/*") if
121-
(not f.is_dir() and not _pattern_excludes(f))]
117+
[
118+
(f, prefix_src)
119+
for f in src.glob("**/*")
120+
if (not f.is_dir() and not _pattern_excludes(f))
121+
]
122122
)
123123
elif not _pattern_excludes(src):
124124
to_copy.append((src, prefix_src))

doc/_extensions/zephyr/gh_utils.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050

5151
from get_maintainer import Maintainers
5252

53-
ZEPHYR_BASE : Final[str] = Path(__file__).parents[3]
54-
MAINTAINERS : Final[Maintainers] = Maintainers(filename=f"{ZEPHYR_BASE}/MAINTAINERS.yml")
53+
ZEPHYR_BASE: Final[str] = Path(__file__).parents[3]
54+
MAINTAINERS: Final[Maintainers] = Maintainers(filename=f"{ZEPHYR_BASE}/MAINTAINERS.yml")
5555

5656

5757
__version__ = "0.1.0"
@@ -140,15 +140,8 @@ def gh_link_get_open_issue_url(app: Sphinx, pagename: str, sha1: str) -> str | N
140140
form_data = {
141141
"template": "001_bug_report.yml",
142142
"title": f"doc: Documentation issue in '{pagename}'",
143-
"labels": [
144-
"bug",
145-
"area: Documentation"
146-
],
147-
"env": (
148-
f"- Page: {pagename}\n"
149-
f"- Version: {app.config.gh_link_version}\n"
150-
f"- SHA-1: {sha1}"
151-
),
143+
"labels": ["bug", "area: Documentation"],
144+
"env": (f"- Page: {pagename}\n- Version: {app.config.gh_link_version}\n- SHA-1: {sha1}"),
152145
"context": (
153146
"This issue was reported from the online documentation page using the "
154147
"'Report an issue' button."
@@ -213,7 +206,7 @@ def git_info_filter(app: Sphinx, pagename) -> tuple[str, str] | None:
213206
.decode("utf-8")
214207
.strip()
215208
)
216-
if not date_and_sha1: # added but not committed
209+
if not date_and_sha1: # added but not committed
217210
return None
218211
date, sha1 = date_and_sha1.split(" ", 1)
219212
date_object = datetime.fromtimestamp(int(date))
@@ -225,6 +218,7 @@ def git_info_filter(app: Sphinx, pagename) -> tuple[str, str] | None:
225218
except subprocess.CalledProcessError:
226219
return None
227220

221+
228222
def add_jinja_filter(app: Sphinx):
229223
if app.builder.format != "html":
230224
return

0 commit comments

Comments
 (0)