4"""List first-party, shared, and vendored library descriptions."""
8from pathlib
import Path
10REPO_ROOT = Path(__file__).resolve().parents[2]
17 "apps/shared_libs/third_party/*",
21def _vendor_brief(lib_dir: Path) -> str:
22 """Read one vendored component description from its parent registry."""
23 readme_path = lib_dir.parent /
"README.md"
24 if not readme_path.exists():
26 readme_text = readme_path.read_text(encoding=
"utf-8")
28 rf
"\|\s*`?{re.escape(lib_dir.name)}`?\s*\|\s*(.+?)\s*\|",
31 return match.group(1).strip()
if match
else ""
34def _readme_summary(text: str) -> str:
35 """Return the first prose line from a library README."""
36 excluded_prefixes = (
"#",
"=",
"-",
"[",
"!",
"<",
"Copyright",
"SPDX")
37 for source_line
in text.splitlines():
38 line = source_line.strip()
39 if line
and not line.startswith(excluded_prefixes):
40 suffix =
"..." if len(line) > DESCRIPTION_LIMIT
else ""
41 return line[:DESCRIPTION_LIMIT] + suffix
45def _brief(lib_dir: Path) -> str:
46 """Extract a library description from its header or README."""
47 if "third_party" in lib_dir.parts:
48 return _vendor_brief(lib_dir)
50 lib_name = lib_dir.name
52 lib_dir /
"inc" / f
"{lib_name}.h",
53 lib_dir /
"inc" / f
"{lib_name.replace('ra8_', '')}.h",
54 lib_dir / f
"{lib_name}.h",
55 lib_dir /
"README.md",
56 lib_dir /
"README.txt",
58 *(lib_dir /
"inc").glob(
"*.h"),
60 for document
in header_candidates:
61 if not document.exists():
63 text = document.read_text(encoding=
"utf-8", errors=
"ignore")
64 match = re.search(
r"@brief\s+([^\n]+)", text)
66 return match.group(1).strip()
67 if document.name.startswith(
"README"):
68 summary = _readme_summary(text)
74def _library_dirs() -> list[Path]:
75 """Return every direct library component from the canonical roots."""
76 candidates = {path
for pattern
in LIBRARY_PATTERNS
for path
in REPO_ROOT.glob(pattern)}
77 return sorted(path
for path
in candidates
if path.is_dir()
and path.name !=
"third_party")
80def _categorized_entries(search_keyword: str |
None) -> tuple[list[str], list[str], list[str]]:
81 """Build display rows for firmware, shared, and vendored libraries."""
82 first_party: list[str] = []
83 shared_party: list[str] = []
84 third_party: list[str] = []
85 for lib_dir
in _library_dirs():
87 brief = _brief(lib_dir)
90 and search_keyword
not in name.lower()
91 and search_keyword
not in brief.lower()
94 entry = f
" - {name:<{NAME_COLUMN_WIDTH}} {brief}"
95 if "third_party" in lib_dir.parts:
96 third_party.append(entry)
97 elif "shared_libs" in lib_dir.parts:
98 shared_party.append(entry)
100 first_party.append(entry)
101 return first_party, shared_party, third_party
104def _print_section(title: str, entries: list[str], *, visible: bool =
True) ->
None:
105 """Print one optional titled group."""
110 for entry
in entries:
115 """List libraries, optionally filtered by a case-insensitive query."""
116 search_keyword = sys.argv[1].lower()
if len(sys.argv) > 1
else None
117 first_party, shared_party, third_party = _categorized_entries(search_keyword)
120 print(f
"SEARCH RESULTS IN LIBRARIES FOR '{search_keyword}':")
121 if not first_party
and not third_party
and not shared_party:
122 print(
" (No matches found)")
124 print(
"FIRMWARE LIBRARIES:")
126 for entry
in first_party:
128 _print_section(
"SHARED LIBRARIES", shared_party, visible=search_keyword
is None)
129 _print_section(
"THIRD-PARTY LIBRARIES", third_party, visible=search_keyword
is None)
132if __name__ ==
"__main__":
void main(void)
The application entry point Reset_Handler hands control to.