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é <benjamin@zephyrproject.org>
This commit is contained in:
Benjamin Cabé 2024-11-22 16:28:30 +01:00 committed by Anas Nashif
commit e544465cd6
6 changed files with 36 additions and 57 deletions

View file

@ -43,36 +43,9 @@
"./boards/microchip/mec172xevb_assy6906/support/mec172x_remote_flasher.py" = [
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
]
"./doc/_scripts/gen_boards_catalog.py" = [
"E401", # https://docs.astral.sh/ruff/rules/multiple-imports-on-one-line
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
]
"./doc/_scripts/gen_devicetree_rest.py" = [
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
"UP034", # https://docs.astral.sh/ruff/rules/extraneous-parentheses
]
"./doc/_scripts/gen_helpers.py" = [
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
]
"./doc/_scripts/redirects.py" = [
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
]
"./doc/conf.py" = [
"E402", # https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file
"E501", # https://docs.astral.sh/ruff/rules/line-too-long
"F541", # https://docs.astral.sh/ruff/rules/f-string-missing-placeholders
"F821", # https://docs.astral.sh/ruff/rules/undefined-name
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
"SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler
]
"./doc/develop/test/twister/sample_blackbox_test.py" = [
"B905", # https://docs.astral.sh/ruff/rules/zip-without-explicit-strict
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
"UP026", # https://docs.astral.sh/ruff/rules/deprecated-mock-import
]
"./modules/mbedtls/create_psa_files.py" = [
"E101", # https://docs.astral.sh/ruff/rules/mixed-spaces-and-tabs
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports

View file

@ -5,7 +5,8 @@ import logging
from collections import namedtuple
from pathlib import Path
import list_boards, list_hardware
import list_boards
import list_hardware
import yaml
import zephyr_module
from gen_devicetree_rest import VndLookup
@ -96,7 +97,7 @@ def get_catalog():
pattern = f"{board.name}*.yaml"
for twister_file in board.dir.glob(pattern):
try:
with open(twister_file, "r") as f:
with open(twister_file) as f:
board_data = yaml.safe_load(f)
archs.add(board_data.get("arch"))
except Exception as e:

View file

@ -7,20 +7,19 @@ devicetree bindings.
"""
import argparse
from collections import defaultdict
import glob
import io
import logging
import os
from pathlib import Path
import pprint
import re
import sys
import textwrap
from devicetree import edtlib
from collections import defaultdict
from pathlib import Path
import gen_helpers
from devicetree import edtlib
ZEPHYR_BASE = Path(__file__).parents[2]
@ -265,7 +264,7 @@ def load_driver_sources():
if not filename.endswith(('.c', '.h')):
continue
filepath = Path(dirpath) / filename
with open(filepath, "r", encoding="utf-8") as f:
with open(filepath, encoding="utf-8") as f:
content = f.read()
relative_path = filepath.relative_to(ZEPHYR_BASE)
@ -349,9 +348,9 @@ def write_dummy_index(bindings, out_dir):
# build compatibles set and dump it
compatibles = {binding.compatible for binding in bindings}
content += '\n'.join((
content += '\n'.join(
f'.. dtcompatible:: {compatible}' for compatible in compatibles
))
)
write_if_updated(out_dir / 'bindings.rst', content)

View file

@ -7,6 +7,7 @@ Helper functions used by gen_kconfig_rest.py and gen_devicetree_rest.py.
import errno
def write_if_updated(path, s):
"""
Writes 's' as the contents of <out_dir>/<filename>, but only if it
@ -17,7 +18,7 @@ def write_if_updated(path, s):
"""
try:
with open(path, "r", encoding="utf-8") as f:
with open(path, encoding="utf-8") as f:
if s == f.read():
return False
except OSError as e:

View file

@ -1,11 +1,11 @@
# Zephyr documentation build configuration file.
# Reference: https://www.sphinx-doc.org/en/master/usage/configuration.html
import sys
import os
from pathlib import Path
import re
import sys
import textwrap
from pathlib import Path
ZEPHYR_BASE = Path(__file__).resolve().parents[1]
ZEPHYR_BUILD = Path(os.environ.get("OUTPUT_DIR")).resolve()
@ -25,7 +25,7 @@ sys.path.insert(0, str(ZEPHYR_BASE / "scripts" / "west_commands"))
# Add the directory which contains the pytest-twister-pytest
sys.path.insert(0, str(ZEPHYR_BASE / "scripts" / "pylib" / "pytest-twister-harness" / "src"))
import redirects
import redirects # noqa: E402
try:
import west as west_found
@ -100,7 +100,7 @@ extensions = [
# Ensure "sphinxcontrib.rsvgconverter" is added before "sphinx.ext.imgconverter"
# as it's better at converting SVG with extended features (like the ones from
# draw.io) to PDF format).
if tags.has("convertimages"): # pylint: disable=undefined-variable
if tags.has("convertimages"): # pylint: disable=undefined-variable # noqa: F821
extensions.append("sphinxcontrib.rsvgconverter")
extensions.append("sphinx.ext.imgconverter")
@ -149,11 +149,16 @@ rst_epilog = f"""
.. |sdk-version-ltrim| unicode:: {sdk_version}
:ltrim:
.. _Zephyr SDK bundle: https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v{sdk_version}
.. |sdk-url-linux| replace:: `{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_linux-x86_64.tar.xz`
.. |sdk-url-linux-sha| replace:: `{SDK_URL_BASE}/v{sdk_version}/sha256.sum`
.. |sdk-url-macos| replace:: `{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_macos-x86_64.tar.xz`
.. |sdk-url-macos-sha| replace:: `{SDK_URL_BASE}/v{sdk_version}/sha256.sum`
.. |sdk-url-windows| replace:: `{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_windows-x86_64.7z`
.. |sdk-url-linux| replace::
`{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_linux-x86_64.tar.xz`
.. |sdk-url-linux-sha| replace::
`{SDK_URL_BASE}/v{sdk_version}/sha256.sum`
.. |sdk-url-macos| replace::
`{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_macos-x86_64.tar.xz`
.. |sdk-url-macos-sha| replace::
`{SDK_URL_BASE}/v{sdk_version}/sha256.sum`
.. |sdk-url-windows| replace::
`{SDK_URL_BASE}/v{sdk_version}/zephyr-sdk-{sdk_version}_windows-x86_64.7z`
"""
# -- Options for HTML output ----------------------------------------------
@ -179,9 +184,9 @@ html_additional_pages = {
"gsearch": "gsearch.html"
}
is_release = tags.has("release") # pylint: disable=undefined-variable
is_release = tags.has("release") # pylint: disable=undefined-variable # noqa: F821
reference_prefix = ""
if tags.has("publish"): # pylint: disable=undefined-variable
if tags.has("publish"): # pylint: disable=undefined-variable # noqa: F821
reference_prefix = f"/{version}" if is_release else "/latest"
docs_title = "Docs / {}".format(version if is_release else "Latest")
html_context = {
@ -213,8 +218,8 @@ html_context = {
latex_elements = {
"papersize": "a4paper",
"maketitle": open(ZEPHYR_BASE / "doc" / "_static" / "latex" / "title.tex").read(),
"preamble": open(ZEPHYR_BASE / "doc" / "_static" / "latex" / "preamble.tex").read(),
"maketitle": (ZEPHYR_BASE / "doc" / "_static" / "latex" / "title.tex").read_text(),
"preamble": (ZEPHYR_BASE / "doc" / "_static" / "latex" / "preamble.tex").read_text(),
"makeindex": r"\usepackage[columns=1]{idxlayout}\makeindex",
"fontpkg": textwrap.dedent(r"""
\usepackage{noto}
@ -271,7 +276,7 @@ notfound_urls_prefix = f"/{version}/" if is_release else "/latest/"
# -- Options for zephyr.gh_utils ------------------------------------------
gh_link_version = f"v{version}" if is_release else "main"
gh_link_base_url = f"https://github.com/zephyrproject-rtos/zephyr"
gh_link_base_url = "https://github.com/zephyrproject-rtos/zephyr"
gh_link_prefixes = {
"samples/.*": "",
"boards/.*": "",

View file

@ -4,13 +4,13 @@
# SPDX-License-Identifier: Apache-2.0
import importlib
import mock
import os
import pytest
import sys
import json
import os
import sys
from unittest import mock
from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock
import pytest
from conftest import TEST_DATA, ZEPHYR_BASE, testsuite_filename_mock
from twisterlib.testplan import TestPlan
@ -57,7 +57,7 @@ class TestDummy:
# Flags related to platform selection
+ [
val
for pair in zip(["-p"] * len(test_platforms), test_platforms)
for pair in zip(["-p"] * len(test_platforms), test_platforms, strict=False)
for val in pair
]
)