Skip to content

Commit 7f16e74

Browse files
committed
doc: Fix python code using ruff
This auto-fixes the code using ruff Signed-off-by: Jamie McCrae <[email protected]>
1 parent dae9b8c commit 7f16e74

File tree

22 files changed

+97
-109
lines changed

22 files changed

+97
-109
lines changed

doc/_extensions/inventory_builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# It can be run as a 1st step when projects contain multi-
1313
# directional links between them.
1414

15+
from collections.abc import Iterator
1516
from pathlib import Path
16-
from typing import Iterator, Set
1717

1818
from docutils import nodes
1919
from sphinx.builders import Builder
@@ -42,10 +42,10 @@ def get_outdated_docs(self) -> Iterator[str]:
4242
yield doc_name
4343
continue
4444

45-
def get_target_uri(self, docname: str, typ: str = None) -> str: #pylint: disable=no-self-use
45+
def get_target_uri(self, docname: str, typ: str = None) -> str:
4646
return docname + '.html'
4747

48-
def prepare_writing(self, docnames: Set[str]) -> None:
48+
def prepare_writing(self, docnames: set[str]) -> None:
4949
pass
5050

5151
def write_doc(self, docname: str, doctree: nodes.document) -> None:

doc/_extensions/manifest_revisions_table.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"""
2828

2929
import re
30-
from typing import Any, Dict, List
30+
from typing import Any
3131

3232
from docutils import nodes
3333
from docutils.parsers.rst import directives
@@ -36,7 +36,6 @@
3636
from sphinx.util.docutils import SphinxDirective
3737
from west.manifest import Manifest
3838

39-
4039
__version__ = "0.1.0"
4140

4241

@@ -85,7 +84,7 @@ def rev_url(base_url: str, rev: str) -> str:
8584

8685
return tag_fmt.format(rev=rev)
8786

88-
def run(self) -> List[nodes.Element]:
87+
def run(self) -> list[nodes.Element]:
8988
# parse show-first option
9089
show_first_raw = self.options.get("show-first", None)
9190
show_first = (
@@ -156,7 +155,7 @@ def run(self) -> List[nodes.Element]:
156155
return [table]
157156

158157

159-
def setup(app: Sphinx) -> Dict[str, Any]:
158+
def setup(app: Sphinx) -> dict[str, Any]:
160159
app.add_config_value("manifest_revisions_table_manifest", None, "env")
161160

162161
directives.register_directive("manifest-revisions-table", ManifestRevisionsTable)

doc/_extensions/ncs_include/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
from sphinx.application import Sphinx
6+
67
from . import ncs_include
78

89
__version__ = '0.0.1'

doc/_extensions/ncs_include/ncs_include.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import os.path
1212

1313
from docutils import io, statemachine
14-
from docutils.utils.error_reporting import SafeString, ErrorString
1514
from docutils.parsers.rst import directives
15+
from docutils.utils.error_reporting import ErrorString, SafeString
1616
from sphinx.util.docutils import SphinxDirective
1717

1818

@@ -41,8 +41,7 @@ def run(self):
4141
docset = self.options.get('docset', None)
4242
if docset is not None and \
4343
docset not in self.config.ncs_include_mapping:
44-
raise self.severe('The supplied "docset" was not found: "%s"' %
45-
docset)
44+
raise self.severe(f'The supplied "docset" was not found: "{docset}"')
4645

4746
indent = self.options.get('indent', 0)
4847
dedent = self.options.get('dedent', 0)
@@ -56,7 +55,7 @@ def run(self):
5655
raise self.severe('Choose one of "dedent" and "auto-dedent" only')
5756

5857
if not self.state.document.settings.file_insertion_enabled:
59-
raise self.warning('"%s" directive disabled.' % self.name)
58+
raise self.warning(f'"{self.name}" directive disabled.')
6059

6160
if docset is None:
6261
# without a docset fallback to Sphinx style include
@@ -76,13 +75,11 @@ def run(self):
7675
encoding=encoding,
7776
error_handler=e_handler)
7877
except UnicodeEncodeError:
79-
raise self.severe('Problems with "%s" directive path:\n'
80-
'Cannot encode input file path "%s" '
81-
'(wrong locale?).' %
82-
(self.name, SafeString(path)))
83-
except IOError as error:
84-
raise self.severe('Problems with "%s" directive path:\n%s.' %
85-
(self.name, ErrorString(error)))
78+
raise self.severe(f'Problems with "{self.name}" directive path:\n'
79+
f'Cannot encode input file path "{SafeString(path)}" '
80+
'(wrong locale?).')
81+
except OSError as error:
82+
raise self.severe(f'Problems with "{self.name}" directive path:\n{ErrorString(error)}.')
8683

8784
# Get to-be-included content
8885
startline = self.options.get('start-line', None)
@@ -94,8 +91,7 @@ def run(self):
9491
else:
9592
rawtext = include_file.read()
9693
except UnicodeError as error:
97-
raise self.severe(u'Problem with "%s" directive:\n%s' %
98-
(self.name, ErrorString(error)))
94+
raise self.severe(f'Problem with "{self.name}" directive:\n{ErrorString(error)}')
9995
# start-after/end-before: no restrictions on newlines in match-text,
10096
# and no restrictions on matching inside lines vs. line boundaries
10197
start_at_text = self.options.get('start-at', None)
@@ -104,8 +100,8 @@ def run(self):
104100
# skip content in rawtext before *and incl.* a matching text
105101
after_index = rawtext.find(after_text)
106102
if after_index < 0:
107-
raise self.severe('Problem with "start-after" option of "%s" '
108-
'directive:\nText not found.' % self.name)
103+
raise self.severe(f'Problem with "start-after" option of "{self.name}" '
104+
'directive:\nText not found.')
109105
if start_at_text:
110106
rawtext = rawtext[after_index:]
111107
else:
@@ -116,8 +112,8 @@ def run(self):
116112
# skip content in rawtext after *and incl.* a matching text
117113
before_index = rawtext.find(before_text)
118114
if before_index < 0:
119-
raise self.severe('Problem with "end-before" option of "%s" '
120-
'directive:\nText not found.' % self.name)
115+
raise self.severe(f'Problem with "end-before" option of "{self.name}" '
116+
'directive:\nText not found.')
121117
if end_at_text:
122118
rawtext = rawtext[:before_index + len(end_at_text)]
123119
else:

doc/_extensions/ncs_tool_versions.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
2929
"""
3030

31+
import re
32+
from collections.abc import Callable
33+
34+
import yaml
3135
from docutils import nodes
3236
from sphinx.application import Sphinx
33-
from typing import List, Dict, Callable
3437
from sphinx.util import logging
35-
import yaml
36-
import re
3738

3839
__version__ = "0.1.0"
3940

@@ -45,7 +46,7 @@ def remove_prefix(s: str, prefix: str) -> str:
4546
return s[len(prefix) :] if s.startswith(prefix) else s
4647

4748

48-
def parse_pip_requirements(lines: List[str]) -> Dict[str, str]:
49+
def parse_pip_requirements(lines: list[str]) -> dict[str, str]:
4950
"""Create a mapping from a pip requirements file.
5051
The listed dependencies are mapped to their required versions.
5152
Exact versions will only have their version displayed, and dependencies
@@ -114,7 +115,11 @@ def tool_version_replace(app: Sphinx) -> Callable:
114115
pip_versions = parse_pip_requirements(requirement_lines)
115116
versions.update(pip_versions)
116117

117-
def tool_version_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
118+
def tool_version_role(name, rawtext, text, lineno, inliner, options=None, content=None):
119+
if content is None:
120+
content = []
121+
if options is None:
122+
options = {}
118123
if text in versions:
119124
node = nodes.Text(versions[text])
120125
else:

doc/_extensions/options_from_kconfig.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from sphinx.application import Sphinx
1313
from sphinx.util.docutils import SphinxDirective
1414

15-
1615
__version__ = '0.0.1'
1716

1817

@@ -84,7 +83,7 @@ def run(self):
8483
self._monkey_patch_kconfiglib(kconfiglib)
8584

8685
# kconfiglib wants this env var defined
87-
os.environ['srctree'] = os.path.dirname(os.path.abspath(__file__))
86+
os.environ['SRCTREE'] = os.path.dirname(os.path.abspath(__file__))
8887
kconfig = kconfiglib.Kconfig(filename=path, warn=False)
8988

9089
prefix = self.options.get('prefix', None)

doc/_extensions/page_filter.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@
5959
:container: dl/dt
6060
"""
6161

62+
import json
63+
import re
64+
from pathlib import Path
65+
6266
from docutils import nodes
6367
from docutils.parsers.rst import directives
64-
from sphinx.util.docutils import SphinxDirective
6568
from sphinx.application import Sphinx
6669
from sphinx.util import logging
67-
from typing import Dict, List, Optional, Tuple
68-
from pathlib import Path
69-
import json
70-
import re
70+
from sphinx.util.docutils import SphinxDirective
7171

7272
__version__ = "0.1.0"
7373

@@ -92,7 +92,8 @@ class PageFilter(SphinxDirective):
9292

9393
def run(self):
9494
name = self.options.get("name", "")
95-
split_first = lambda s: s.split(maxsplit=1)
95+
def split_first(s):
96+
return s.split(maxsplit=1)
9697
content = list(map(split_first, self.content))
9798
default = self.options.get("default", "all")
9899
container = self.options.get("container", None)
@@ -112,7 +113,8 @@ def run(self):
112113
tags = self.options.get("tags", [])
113114
tags = {classname: displayname for classname, displayname in tags}
114115
tags["versions"] = ""
115-
create_tuple = lambda v: (v, v.replace("-", "."))
116+
def create_tuple(v):
117+
return v, v.replace("-", ".")
116118
versions = list(map(create_tuple, reversed(self.env.nrf_versions)))
117119
return [FilterDropdown(name, versions, default, container_element, tags)]
118120

@@ -134,10 +136,10 @@ class to create a tag from, and displayname is the content
134136
def __init__(
135137
self,
136138
name: str,
137-
options: List[Tuple[str, str]],
139+
options: list[tuple[str, str]],
138140
default_value: str = "all",
139141
container_element: str = None,
140-
filter_tags: Tuple[str, str] = None,
142+
filter_tags: tuple[str, str] = None,
141143
) -> None:
142144
super().__init__()
143145
self.name = name
@@ -176,16 +178,16 @@ def unknown_visit(self, node: nodes.Node) -> None:
176178
self._found_dropdowns.append(node)
177179

178180
@property
179-
def found_filter_dropdown(self) -> List[nodes.Node]:
181+
def found_filter_dropdown(self) -> list[nodes.Node]:
180182
return self._found_dropdowns
181183

182184

183185
def page_filter_install(
184186
app: Sphinx,
185187
pagename: str,
186188
templatename: str,
187-
context: Dict,
188-
doctree: Optional[nodes.Node],
189+
context: dict,
190+
doctree: nodes.Node | None,
189191
) -> None:
190192
"""Install the javascript filter function."""
191193

doc/_extensions/software_maturity_table.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@
9494
]
9595
"""
9696

97+
import requests
98+
import yaml
99+
from azure.storage.blob import ContainerClient
97100
from docutils import nodes
98101
from docutils.parsers.rst import directives
99-
from sphinx.util.docutils import SphinxDirective
100102
from sphinx.application import Sphinx
101-
from azure.storage.blob import ContainerClient
102103
from sphinx.util import logging
103-
import requests
104-
import yaml
104+
from sphinx.util.docutils import SphinxDirective
105105

106106
__version__ = "0.1.1"
107107

0 commit comments

Comments
 (0)