Check for a root README without counting vendored documentation
Direct answer
A root README signal should answer one narrow question: does the selected project directory contain its own README.md? Build that path with root / "README.md" and call is_file; do not use a recursive match for the signal itself. Recursive matching changes the question because vendored packages, examples, and generated trees often include their own documentation.
The fixture contains two README files. The assertion deliberately proves that a recursive search sees both, while the reported signal is based only on the root path. That is the edge case that prevents a dependency’s README from making an undocumented project look complete.
This check is case-sensitive on filesystems where names are case-sensitive and only recognizes the stated spelling. It does not read the README, assess whether it is current, or decide whether documentation is required. Add alternative names only when the scanner’s contract explicitly supports them.
Complete example
from pathlib import Path
from tempfile import TemporaryDirectory
with TemporaryDirectory() as directory:
root = Path(directory)
(root / "README.md").write_text("root note", encoding="utf-8")
(root / "vendor").mkdir()
(root / "vendor" / "README.md").write_text("dependency note", encoding="utf-8")
root_readme = (root / "README.md").is_file()
nested_readmes = list(root.rglob("README.md"))
assert root_readme
assert len(nested_readmes) == 2
print("root_readme=yes nested_ignored=1")
Expected stdout:
root_readme=yes nested_ignored=1
Sources
Prepared with AI assistance. The example uses synthetic data; its stated limits apply.
Comments
Post a Comment