Skip to content

Commit 2acd685

Browse files
committed
[ruff] Format and lint all code
1 parent c7fb4f4 commit 2acd685

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2707
-2224
lines changed

src/modm_data/__init__.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,49 @@
66
"""
77

88
from importlib.metadata import version, PackageNotFoundError
9+
910
try:
1011
__version__ = version("modm_data")
1112
except PackageNotFoundError:
1213
__version__ = "0.0.1"
1314

1415

15-
from . import cubehal
16-
from . import cubemx
17-
from . import cube2owl
18-
from . import dl
19-
from . import header2svd
20-
from . import html
21-
from . import html2owl
22-
from . import html2svd
23-
from . import owl
24-
from . import pdf
25-
from . import pdf2html
26-
from . import svd
27-
from . import utils
16+
from . import (
17+
cubehal,
18+
cubemx,
19+
cube2owl,
20+
dl,
21+
header2svd,
22+
html,
23+
html2owl,
24+
html2svd,
25+
owl,
26+
pdf,
27+
pdf2html,
28+
svd,
29+
utils,
30+
)
31+
32+
__all__ = [
33+
"cube2owl",
34+
"cubehal",
35+
"cubemx",
36+
"dl",
37+
"header2svd",
38+
"html",
39+
"html2owl",
40+
"html2svd",
41+
"owl",
42+
"pdf",
43+
"pdf2html",
44+
"svd",
45+
"utils",
46+
]
2847

2948
# Silence warnings about path import order when calling modules directly
3049
import sys
50+
3151
if not sys.warnoptions:
3252
import warnings
53+
3354
warnings.filterwarnings("ignore", category=RuntimeWarning, module="runpy")

src/modm_data/cube2owl/__main__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
# Copyright 2022, Niklas Hauser
22
# SPDX-License-Identifier: MPL-2.0
33

4-
import re
54
import tqdm
65
import argparse
76
import subprocess
87
from pathlib import Path
9-
from collections import defaultdict
108
from multiprocessing.pool import ThreadPool
119

1210
from modm_data.cubemx import devices_from_prefix, devices_from_partname
1311
from modm_data.header2svd.stmicro import Header
1412
from modm_data.html.stmicro import datasheet_for_device, reference_manual_for_device
1513
from modm_data.owl.stmicro import create_ontology
16-
from modm_data.py2owl.stmicro import *
14+
from modm_data.py2owl.stmicro import owl_from_did, owl_from_cubemx, owl_from_header, owl_from_doc
1715

1816

1917
def main():
@@ -29,23 +27,26 @@ def main():
2927
partnames = sorted(list(set(p[:9] for p in partnames)))
3028

3129
Path("log/stmicro/owl").mkdir(exist_ok=True, parents=True)
32-
calls = [f"python3 -m modm_data.cubemx2owl --prefix {partname} "
33-
f"> log/stmicro/owl/cubemx_{partname}.txt 2>&1"
34-
for partname in partnames]
30+
calls = [
31+
f"python3 -m modm_data.cube2owl --prefix {partname} > log/stmicro/owl/cubemx_{partname}.txt 2>&1"
32+
for partname in partnames
33+
]
3534
with ThreadPool() as pool:
3635
retvals = list(tqdm.tqdm(pool.imap(lambda c: subprocess.run(c, shell=True), calls), total=len(calls)))
3736
for retval, call in zip(retvals, calls):
38-
if retval.returncode != 0: print(call)
37+
if retval.returncode != 0:
38+
print(call)
3939
return all(r.returncode == 0 for r in retvals)
4040

41-
4241
for partname in devices_from_prefix(args.prefix.lower()):
4342
ds, rm = None, None
4443
for device in devices_from_partname(partname):
4544
did = device["id"]
4645
# Only change the documentation object if necessary to preserve caching
47-
if ds != (nds := datasheet_for_device(did)): ds = nds
48-
if rm != (nrm := reference_manual_for_device(did)): rm = nrm
46+
if ds != (nds := datasheet_for_device(did)):
47+
ds = nds
48+
if rm != (nrm := reference_manual_for_device(did)):
49+
rm = nrm
4950
print(did, ds, rm)
5051
if ds is None or rm is None:
5152
print(f"Ignoring {did} due to lack of documents")

src/modm_data/cubehal/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
"""
1212

1313
from .dmamux_requests import read_request_map
14+
15+
__all__ = ["read_request_map"]

src/modm_data/cubehal/dmamux_requests.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
import re
55
from pathlib import Path
66
from ..utils import ext_path
7+
from ..owl import DeviceIdentifier
78

89
_CUBE_PATH = ext_path("stmicro/cubehal")
910
_DMAMUX_PATTERN = re.compile(r"^\s*#define\s+(?P<name>(LL_DMAMUX_REQ_\w+))\s+(?P<id>(0x[0-9A-Fa-f]+))U")
1011
_REQUEST_PATTERN = re.compile(r"^\s*#define\s+(?P<name>(DMA_REQUEST_\w+))\s+(?P<id>([0-9]+))U")
1112

12-
def read_request_map(did: "modm_data.owl.DeviceIdentifier") -> dict[str, int]:
13+
14+
def read_request_map(did: DeviceIdentifier) -> dict[str, int]:
1315
"""
1416
Reads the DMA requests mapping from the Low-Level (LL) CubeHAL header files.
1517
1618
:param did: Device to query for.
17-
1819
:return: A dictionary of DMA trigger name to trigger position.
1920
"""
2021
dma_header = _get_hal_dma_header_path(did.family)
@@ -27,7 +28,7 @@ def read_request_map(did: "modm_data.owl.DeviceIdentifier") -> dict[str, int]:
2728
elif did.family == "l4" and did.name[0] in ["p", "q", "r", "s"]:
2829
request_map = _read_requests_l4(did.name in ["p5", "q5"])
2930
else:
30-
raise RuntimeError("No DMAMUX request data available for {}".format(did))
31+
raise RuntimeError(f"No DMAMUX request data available for {did}")
3132
_fix_request_data(request_map)
3233
return request_map
3334

@@ -63,20 +64,21 @@ def _fix_request_data(request_map):
6364
else:
6465
m = dac_pattern.match(name)
6566
if m:
66-
fix_requests["{}_CH{}".format(m.group("dac"), m.group("ch"))] = number
67+
fix_requests[f'{m.group("dac")}_CH{m.group("ch")}'] = number
6768

6869
request_map.update(fix_requests)
6970

71+
7072
def _get_include_path(family):
71-
return _CUBE_PATH / Path("stm32{}xx/Inc".format(family))
73+
return _CUBE_PATH / Path(f"stm32{family}xx/Inc")
7274

7375

7476
def _get_hal_dma_header_path(family):
75-
return _get_include_path(family) / Path("stm32{}xx_hal_dma.h".format(family))
77+
return _get_include_path(family) / Path(f"stm32{family}xx_hal_dma.h")
7678

7779

7880
def _get_ll_dmamux_header_path(family):
79-
return _get_include_path(family) / Path("stm32{}xx_ll_dmamux.h".format(family))
81+
return _get_include_path(family) / Path(f"stm32{family}xx_ll_dmamux.h")
8082

8183

8284
# For G4, H7 and L5
@@ -91,7 +93,7 @@ def _read_requests(hal_dma_file):
9193
# For G0, WB and WL
9294
def _read_requests_from_ll_dmamux(hal_dma_file, ll_dmamux_file):
9395
dmamux_map = _read_map(ll_dmamux_file, _DMAMUX_PATTERN)
94-
request_pattern = re.compile("^\s*#define\s+(?P<name>(DMA_REQUEST_\w+))\s+(?P<id>(LL_DMAMUX?_REQ_\w+))\s*")
96+
request_pattern = re.compile(r"^\s*#define\s+(?P<name>(DMA_REQUEST_\w+))\s+(?P<id>(LL_DMAMUX?_REQ_\w+))\s*")
9597
requests_map = _read_map(hal_dma_file, request_pattern)
9698
out_map = {}
9799
for r in requests_map.keys():
@@ -130,7 +132,7 @@ def _read_requests_l4(read_for_p5_q5):
130132
if m:
131133
name = m.group("name").replace("DMA_REQUEST_", "", 1)
132134
if name in out_map:
133-
raise RuntimeError("Duplicate entry {}".format(name))
135+
raise RuntimeError(f"Duplicate entry {name}")
134136
out_map[name] = int(m.group("id"))
135137
return out_map
136138

@@ -143,6 +145,6 @@ def _read_map(filename, pattern):
143145
if m:
144146
name = m.group("name")
145147
if name in out_map:
146-
raise RuntimeError("Duplicate entry {}".format(name))
148+
raise RuntimeError(f"Duplicate entry {name}")
147149
out_map[name] = m.group("id")
148150
return out_map

src/modm_data/cubemx/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
"""
55
# STMicro STM32CubeMX Database
6-
7-
86
"""
97

10-
from .device_data import devices_from_prefix, devices_from_partname, cubemx_device_list
8+
from .device_data import devices_from_family, devices_from_prefix, devices_from_partname, cubemx_device_list
9+
10+
__all__ = [
11+
"devices_from_family",
12+
"devices_from_prefix",
13+
"devices_from_partname",
14+
"cubemx_device_list",
15+
]

0 commit comments

Comments
 (0)