Skip to content

Commit e544465

Browse files
kartbennashif
authored andcommitted
doc: _scripts: conf: apply ruff lint rules
This makes all remaining Python scripts in doc compliant w.r.t current Ruff rules Signed-off-by: Benjamin Cabé <[email protected]>
1 parent cf005fe commit e544465

File tree

6 files changed

+35
-56
lines changed

6 files changed

+35
-56
lines changed

.ruff-excludes.toml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,9 @@
4343
"./boards/microchip/mec172xevb_assy6906/support/mec172x_remote_flasher.py" = [
4444
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
4545
]
46-
"./doc/_scripts/gen_boards_catalog.py" = [
47-
"E401", # https://docs.astral.sh/ruff/rules/multiple-imports-on-one-line
48-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
49-
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
50-
]
51-
"./doc/_scripts/gen_devicetree_rest.py" = [
52-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
53-
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
54-
"UP034", # https://docs.astral.sh/ruff/rules/extraneous-parentheses
55-
]
56-
"./doc/_scripts/gen_helpers.py" = [
57-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
58-
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
59-
]
6046
"./doc/_scripts/redirects.py" = [
6147
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
6248
]
63-
"./doc/conf.py" = [
64-
"E402", # https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file
65-
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
66-
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
67-
"F821", # https://docs.astral.sh/ruff/rules/undefined-name
68-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
69-
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler
70-
]
71-
"./doc/develop/test/twister/sample_blackbox_test.py" = [
72-
"B905", # https://docs.astral.sh/ruff/rules/zip-without-explicit-strict
73-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
74-
"UP026", # https://docs.astral.sh/ruff/rules/deprecated-mock-import
75-
]
7649
"./modules/mbedtls/create_psa_files.py" = [
7750
"E101", # https://docs.astral.sh/ruff/rules/mixed-spaces-and-tabs
7851
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports

doc/_scripts/gen_boards_catalog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from collections import namedtuple
66
from pathlib import Path
77

8-
import list_boards, list_hardware
8+
import list_boards
9+
import list_hardware
910
import yaml
1011
import zephyr_module
1112
from gen_devicetree_rest import VndLookup
@@ -96,7 +97,7 @@ def get_catalog():
9697
pattern = f"{board.name}*.yaml"
9798
for twister_file in board.dir.glob(pattern):
9899
try:
99-
with open(twister_file, "r") as f:
100+
with open(twister_file) as f:
100101
board_data = yaml.safe_load(f)
101102
archs.add(board_data.get("arch"))
102103
except Exception as e:

doc/_scripts/gen_devicetree_rest.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@
77
"""
88

99
import argparse
10-
from collections import defaultdict
1110
import glob
1211
import io
1312
import logging
1413
import os
15-
from pathlib import Path
1614
import pprint
1715
import re
1816
import sys
1917
import textwrap
20-
21-
from devicetree import edtlib
18+
from collections import defaultdict
19+
from pathlib import Path
2220

2321
import gen_helpers
22+
from devicetree import edtlib
2423

2524
ZEPHYR_BASE = Path(__file__).parents[2]
2625

@@ -265,7 +264,7 @@ def load_driver_sources():
265264
if not filename.endswith(('.c', '.h')):
266265
continue
267266
filepath = Path(dirpath) / filename
268-
with open(filepath, "r", encoding="utf-8") as f:
267+
with open(filepath, encoding="utf-8") as f:
269268
content = f.read()
270269

271270
relative_path = filepath.relative_to(ZEPHYR_BASE)
@@ -349,9 +348,9 @@ def write_dummy_index(bindings, out_dir):
349348

350349
# build compatibles set and dump it
351350
compatibles = {binding.compatible for binding in bindings}
352-
content += '\n'.join((
351+
content += '\n'.join(
353352
f'.. dtcompatible:: {compatible}' for compatible in compatibles
354-
))
353+
)
355354

356355
write_if_updated(out_dir / 'bindings.rst', content)
357356

doc/_scripts/gen_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import errno
99

10+
1011
def write_if_updated(path, s):
1112
"""
1213
Writes 's' as the contents of <out_dir>/<filename>, but only if it
@@ -17,7 +18,7 @@ def write_if_updated(path, s):
1718
"""
1819

1920
try:
20-
with open(path, "r", encoding="utf-8") as f:
21+
with open(path, encoding="utf-8") as f:
2122
if s == f.read():
2223
return False
2324
except OSError as e:

doc/conf.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Zephyr documentation build configuration file.
22
# Reference: https://www.sphinx-doc.org/en/master/usage/configuration.html
33

4-
import sys
54
import os
6-
from pathlib import Path
75
import re
6+
import sys
87
import textwrap
8+
from pathlib import Path
99

1010
ZEPHYR_BASE = Path(__file__).resolve().parents[1]
1111
ZEPHYR_BUILD = Path(os.environ.get("OUTPUT_DIR")).resolve()
@@ -25,7 +25,7 @@
2525
# Add the directory which contains the pytest-twister-pytest
2626
sys.path.insert(0, str(ZEPHYR_BASE / "scripts" / "pylib" / "pytest-twister-harness" / "src"))
2727

28-
import redirects
28+
import redirects # noqa: E402
2929

3030
try:
3131
import west as west_found
@@ -100,7 +100,7 @@
100100
# Ensure "sphinxcontrib.rsvgconverter" is added before "sphinx.ext.imgconverter"
101101
# as it's better at converting SVG with extended features (like the ones from
102102
# draw.io) to PDF format).
103-
if tags.has("convertimages"): # pylint: disable=undefined-variable
103+
if tags.has("convertimages"): # pylint: disable=undefined-variable # noqa: F821
104104
extensions.append("sphinxcontrib.rsvgconverter")
105105
extensions.append("sphinx.ext.imgconverter")
106106

@@ -149,11 +149,16 @@
149149
.. |sdk-version-ltrim| unicode:: {sdk_version}
150150
:ltrim:
151151
.. _Zephyr SDK bundle: https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v{sdk_version}
152-
.. |sdk-url-linux| replace:: `{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_linux-x86_64.tar.xz`
153-
.. |sdk-url-linux-sha| replace:: `{SDK_URL_BASE}/v{sdk_version}/sha256.sum`
154-
.. |sdk-url-macos| replace:: `{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_macos-x86_64.tar.xz`
155-
.. |sdk-url-macos-sha| replace:: `{SDK_URL_BASE}/v{sdk_version}/sha256.sum`
156-
.. |sdk-url-windows| replace:: `{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_windows-x86_64.7z`
152+
.. |sdk-url-linux| replace::
153+
`{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_linux-x86_64.tar.xz`
154+
.. |sdk-url-linux-sha| replace::
155+
`{SDK_URL_BASE}/v{sdk_version}/sha256.sum`
156+
.. |sdk-url-macos| replace::
157+
`{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_macos-x86_64.tar.xz`
158+
.. |sdk-url-macos-sha| replace::
159+
`{SDK_URL_BASE}/v{sdk_version}/sha256.sum`
160+
.. |sdk-url-windows| replace::
161+
`{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_windows-x86_64.7z`
157162
"""
158163

159164
# -- Options for HTML output ----------------------------------------------
@@ -179,9 +184,9 @@
179184
"gsearch": "gsearch.html"
180185
}
181186

182-
is_release = tags.has("release") # pylint: disable=undefined-variable
187+
is_release = tags.has("release") # pylint: disable=undefined-variable # noqa: F821
183188
reference_prefix = ""
184-
if tags.has("publish"): # pylint: disable=undefined-variable
189+
if tags.has("publish"): # pylint: disable=undefined-variable # noqa: F821
185190
reference_prefix = f"/{version}" if is_release else "/latest"
186191
docs_title = "Docs / {}".format(version if is_release else "Latest")
187192
html_context = {
@@ -213,8 +218,8 @@
213218

214219
latex_elements = {
215220
"papersize": "a4paper",
216-
"maketitle": open(ZEPHYR_BASE / "doc" / "_static" / "latex" / "title.tex").read(),
217-
"preamble": open(ZEPHYR_BASE / "doc" / "_static" / "latex" / "preamble.tex").read(),
221+
"maketitle": (ZEPHYR_BASE / "doc" / "_static" / "latex" / "title.tex").read_text(),
222+
"preamble": (ZEPHYR_BASE / "doc" / "_static" / "latex" / "preamble.tex").read_text(),
218223
"makeindex": r"\usepackage[columns=1]{idxlayout}\makeindex",
219224
"fontpkg": textwrap.dedent(r"""
220225
\usepackage{noto}
@@ -271,7 +276,7 @@
271276
# -- Options for zephyr.gh_utils ------------------------------------------
272277

273278
gh_link_version = f"v{version}" if is_release else "main"
274-
gh_link_base_url = f"https://github.com/zephyrproject-rtos/zephyr"
279+
gh_link_base_url = "https://github.com/zephyrproject-rtos/zephyr"
275280
gh_link_prefixes = {
276281
"samples/.*": "",
277282
"boards/.*": "",

doc/develop/test/twister/sample_blackbox_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
import importlib
7-
import mock
7+
import json
88
import os
9-
import pytest
109
import sys
11-
import json
10+
from unittest import mock
1211

13-
from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock
12+
import pytest
13+
from conftest import TEST_DATA, ZEPHYR_BASE, testsuite_filename_mock
1414
from twisterlib.testplan import TestPlan
1515

1616

@@ -57,7 +57,7 @@ def test_level(self, capfd, out_path, level, expected_tests):
5757
# Flags related to platform selection
5858
+ [
5959
val
60-
for pair in zip(["-p"] * len(test_platforms), test_platforms)
60+
for pair in zip(["-p"] * len(test_platforms), test_platforms, strict=False)
6161
for val in pair
6262
]
6363
)

0 commit comments

Comments
 (0)