Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Formatting #4

Merged
merged 3 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ jobs:
- name: Run Regression Tests
run: |
make run-regression-tests

- name: Run Ruff Formatter
uses: chartboost/ruff-action@v1
with:
src: "./src"
args: "format --check"

- name: Run Ruff Linter
uses: chartboost/ruff-action@v1
with:
src: "./src"
args: "check"
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@ modm_data = ["*.md", "*/*.md", "*/*/*.md", "*/*/*/*.md"]

[tool.setuptools-git-versioning]
version_file = "VERSION"

[tool.ruff]
exclude = [".venv/", "ext/", "build/", "log/"]
line-length = 120
target-version = "py311"
47 changes: 34 additions & 13 deletions src/modm_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,49 @@
"""

from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version("modm_data")
except PackageNotFoundError:
__version__ = "0.0.1"


from . import cubehal
from . import cubemx
from . import cube2owl
from . import dl
from . import header2svd
from . import html
from . import html2owl
from . import html2svd
from . import owl
from . import pdf
from . import pdf2html
from . import svd
from . import utils
from . import (
cubehal,
cubemx,
cube2owl,
dl,
header2svd,
html,
html2owl,
html2svd,
owl,
pdf,
pdf2html,
svd,
utils,
)

__all__ = [
"cube2owl",
"cubehal",
"cubemx",
"dl",
"header2svd",
"html",
"html2owl",
"html2svd",
"owl",
"pdf",
"pdf2html",
"svd",
"utils",
]

# Silence warnings about path import order when calling modules directly
import sys

if not sys.warnoptions:
import warnings

warnings.filterwarnings("ignore", category=RuntimeWarning, module="runpy")
21 changes: 11 additions & 10 deletions src/modm_data/cube2owl/__main__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# Copyright 2022, Niklas Hauser
# SPDX-License-Identifier: MPL-2.0

import re
import tqdm
import argparse
import subprocess
from pathlib import Path
from collections import defaultdict
from multiprocessing.pool import ThreadPool

from modm_data.cubemx import devices_from_prefix, devices_from_partname
from modm_data.header2svd.stmicro import Header
from modm_data.html.stmicro import datasheet_for_device, reference_manual_for_device
from modm_data.owl.stmicro import create_ontology
from modm_data.py2owl.stmicro import *
from modm_data.py2owl.stmicro import owl_from_did, owl_from_cubemx, owl_from_header, owl_from_doc


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

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


for partname in devices_from_prefix(args.prefix.lower()):
ds, rm = None, None
for device in devices_from_partname(partname):
did = device["id"]
# Only change the documentation object if necessary to preserve caching
if ds != (nds := datasheet_for_device(did)): ds = nds
if rm != (nrm := reference_manual_for_device(did)): rm = nrm
if ds != (nds := datasheet_for_device(did)):
ds = nds
if rm != (nrm := reference_manual_for_device(did)):
rm = nrm
print(did, ds, rm)
if ds is None or rm is None:
print(f"Ignoring {did} due to lack of documents")
Expand Down
2 changes: 2 additions & 0 deletions src/modm_data/cubehal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
"""

from .dmamux_requests import read_request_map

__all__ = ["read_request_map"]
22 changes: 12 additions & 10 deletions src/modm_data/cubehal/dmamux_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
import re
from pathlib import Path
from ..utils import ext_path
from ..owl import DeviceIdentifier

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

def read_request_map(did: "modm_data.owl.DeviceIdentifier") -> dict[str, int]:

def read_request_map(did: DeviceIdentifier) -> dict[str, int]:
"""
Reads the DMA requests mapping from the Low-Level (LL) CubeHAL header files.

:param did: Device to query for.

:return: A dictionary of DMA trigger name to trigger position.
"""
dma_header = _get_hal_dma_header_path(did.family)
Expand All @@ -27,7 +28,7 @@ def read_request_map(did: "modm_data.owl.DeviceIdentifier") -> dict[str, int]:
elif did.family == "l4" and did.name[0] in ["p", "q", "r", "s"]:
request_map = _read_requests_l4(did.name in ["p5", "q5"])
else:
raise RuntimeError("No DMAMUX request data available for {}".format(did))
raise RuntimeError(f"No DMAMUX request data available for {did}")
_fix_request_data(request_map)
return request_map

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

request_map.update(fix_requests)


def _get_include_path(family):
return _CUBE_PATH / Path("stm32{}xx/Inc".format(family))
return _CUBE_PATH / Path(f"stm32{family}xx/Inc")


def _get_hal_dma_header_path(family):
return _get_include_path(family) / Path("stm32{}xx_hal_dma.h".format(family))
return _get_include_path(family) / Path(f"stm32{family}xx_hal_dma.h")


def _get_ll_dmamux_header_path(family):
return _get_include_path(family) / Path("stm32{}xx_ll_dmamux.h".format(family))
return _get_include_path(family) / Path(f"stm32{family}xx_ll_dmamux.h")


# For G4, H7 and L5
Expand All @@ -91,7 +93,7 @@ def _read_requests(hal_dma_file):
# For G0, WB and WL
def _read_requests_from_ll_dmamux(hal_dma_file, ll_dmamux_file):
dmamux_map = _read_map(ll_dmamux_file, _DMAMUX_PATTERN)
request_pattern = re.compile("^\s*#define\s+(?P<name>(DMA_REQUEST_\w+))\s+(?P<id>(LL_DMAMUX?_REQ_\w+))\s*")
request_pattern = re.compile(r"^\s*#define\s+(?P<name>(DMA_REQUEST_\w+))\s+(?P<id>(LL_DMAMUX?_REQ_\w+))\s*")
requests_map = _read_map(hal_dma_file, request_pattern)
out_map = {}
for r in requests_map.keys():
Expand Down Expand Up @@ -130,7 +132,7 @@ def _read_requests_l4(read_for_p5_q5):
if m:
name = m.group("name").replace("DMA_REQUEST_", "", 1)
if name in out_map:
raise RuntimeError("Duplicate entry {}".format(name))
raise RuntimeError(f"Duplicate entry {name}")
out_map[name] = int(m.group("id"))
return out_map

Expand All @@ -143,6 +145,6 @@ def _read_map(filename, pattern):
if m:
name = m.group("name")
if name in out_map:
raise RuntimeError("Duplicate entry {}".format(name))
raise RuntimeError(f"Duplicate entry {name}")
out_map[name] = m.group("id")
return out_map
11 changes: 8 additions & 3 deletions src/modm_data/cubemx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

"""
# STMicro STM32CubeMX Database


"""

from .device_data import devices_from_prefix, devices_from_partname, cubemx_device_list
from .device_data import devices_from_family, devices_from_prefix, devices_from_partname, cubemx_device_list

__all__ = [
"devices_from_family",
"devices_from_prefix",
"devices_from_partname",
"cubemx_device_list",
]
Loading
Loading