kerneldoc.py¶
clew/kerneldoc.py
kernel-doc comments, read into their own `kerneldoc` layer (S6; index only).
ingest_kerneldoc
int clew.kerneldoc.ingest_kerneldoc(Path db_path, Path repo_root, IndexCache|None cache=None)
Record every indexed C file's kernel-doc blocks.
Source · 33 lines
def ingest_kerneldoc(db_path: Path, repo_root: Path, cache: IndexCache | None = None) -> int:
"""THE TABLE IS ALWAYS CREATED, empty in a tree with no kernel-doc.
@brief Build the kernel-doc layer.
@return Row count.
"""
from .filedocs import _indexed_files
conn = sqlite3.connect(str(db_path))
try:
conn.executescript(_DDL)
conn.execute("DELETE FROM kerneldoc")
resolved: dict[str, str] = {}
rows = []
for rel in _indexed_files(conn):
if not rel.endswith(_SUFFIXES):
continue
if (
within_repo(
repo_root / rel, repo_root, setting=f"kernel-doc of {rel}", memo=resolved
)
is None
):
continue
rows += [_row(rel, b) for b in kerneldoc_of(cache, repo_root, rel)]
conn.executemany(_INSERT, rows)
conn.commit()
finally:
conn.close()
logger.info("kerneldoc: %d block(s)", len(rows))
return len(rows)
Activity · 17 steps
Requirements
parse_kerneldoc
list[dict] clew.kerneldoc.parse_kerneldoc(str text)
The kernel-doc blocks of one C source text.
Called by kerneldoc_of
Tested by
Calls _block
Source · 16 lines
def parse_kerneldoc(text: str) -> list[dict]:
"""@brief Read every kernel-doc block. @return Blocks."""
out = []
for match in _BLOCK.finditer(text):
body = [re.sub(r"^\s*\* ?", "", raw).rstrip() for raw in match.group(1).splitlines()]
while body and not body[0].strip():
body.pop(0)
if not body or _DOXYGEN.search(match.group(1)):
continue
block = _block(body)
if block is not None:
block["line"] = text.count("\n", 0, match.start()) + 1
out.append(block)
return out
Activity · 12 steps
Requirements
refresh_kerneldoc
None clew.kerneldoc.refresh_kerneldoc(sqlite3.Connection conn, Path repo_root, str rel, IndexCache cache)
Rewrite one edited file's kernel-doc rows (the fast tier).
Source · 10 lines
def refresh_kerneldoc(
conn: sqlite3.Connection, repo_root: Path, rel: str, cache: IndexCache
) -> None:
"""@brief The same rows `ingest_kerneldoc` writes, for one file. @return None."""
if not rel.endswith(_SUFFIXES):
return
if conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'kerneldoc'").fetchone() is None:
return
conn.execute("DELETE FROM kerneldoc WHERE file_path = ?", (rel,))
conn.executemany(_INSERT, [_row(rel, b) for b in kerneldoc_of(cache, repo_root, rel)])1 more lines, not shown