from __future__ import annotations
import os
import sys
SRC = "src"
def has_module_doc(path: str) -> bool:
with open(path, encoding="utf-8", errors="replace") as fh:
for line in fh:
stripped = line.strip()
if not stripped or stripped.startswith("#!["):
continue
return stripped.startswith("//!")
return False
def main() -> int:
if not os.path.isdir(SRC):
print("run from the repository root", file=sys.stderr)
return 2
missing, total = [], 0
for root, _dirs, files in os.walk(SRC):
for name in sorted(files):
if not name.endswith(".rs"):
continue
total += 1
path = os.path.join(root, name)
if not has_module_doc(path):
missing.append(path)
if missing:
print(f"{len(missing)} of {total} source files have no `//!` module doc:",
file=sys.stderr)
for path in missing:
print(f" {path}", file=sys.stderr)
return 1
print(f"all {total} source files carry a module doc")
return 0
if __name__ == "__main__":
sys.exit(main())