ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
docattach_scope.py
Go to the documentation of this file.
1# SPDX-License-Identifier: MIT
2# Copyright (c) 2026 Brighton Sikarskie
3"""Which files ``check_doc_attachment.py`` reads.
4
5Split out of the checker (#359) so the scope is one small, readable thing
6rather than five constants scattered above 1600 lines of rules. A scope that
7is hard to find is a scope nobody re-reads, and a checker whose roots quietly
8stopped describing the tree is the defect this repository has now hit five
9times -- see the ``check_lint_coverage.py`` docstring for the tally.
10"""
11
12from __future__ import annotations
13
14import os
15from pathlib import Path
16
17REPO_ROOT = Path(__file__).resolve().parents[2]
18
19#: First-party roots. Mirrors the CLAUDE.md "Scope" note: every first-party
20#: file, not just the firmware. ``tools/`` and ``tests/`` are in deliberately
21#: -- leaving them out is how a whole host emulator went ungated before.
22SCAN_ROOTS = ("libs", "port", "examples", "tools", "apps", "tests")
23
24#: Path fragments that mark non-first-party or generated trees.
25EXCLUDED_PARTS = frozenset(
26 {
27 "third_party",
28 "ra8_fonts",
29 "build",
30 "build-cov",
31 "build-bench",
32 "build-scan",
33 "build-mcdc",
34 "build-emu",
35 "_deps",
36 "CMakeFiles",
37 }
38)
39
40SOURCE_SUFFIXES = (".c", ".h")
41
42
43def iter_sources(targets: list[Path]) -> list[Path]:
44 """Every in-scope source file under ``targets``."""
45 out: list[Path] = []
46 for target in targets:
47 if target.is_file():
48 if target.suffix in SOURCE_SUFFIXES:
49 out.append(target)
50 continue
51 for dirpath, dirnames, filenames in os.walk(target):
52 dirnames[:] = [d for d in dirnames if d not in EXCLUDED_PARTS]
53 for fn in filenames:
54 if not fn.endswith(SOURCE_SUFFIXES):
55 continue
56 p = Path(dirpath) / fn
57 if EXCLUDED_PARTS & set(p.relative_to(REPO_ROOT).parts):
58 continue
59 out.append(p)
60 return sorted(set(out))
61
62
63def default_targets() -> list[Path]:
64 """Every first-party root that exists in this checkout."""
65 return [REPO_ROOT / r for r in SCAN_ROOTS if (REPO_ROOT / r).is_dir()]