Detect files changed since the last documentation generation. Reads the commit_id from metadata.json and compares with current HEAD using git diff. When running inside a subdirectory of a monorepo, only files under that subdirectory are returned. Returns list of changed file p
(
repo_path: Path,
output_dir: Path,
logger,
verbose: bool,
compare_to: Optional[str] = None
)
| 40 | """Parse comma-separated patterns into a list.""" |
| 41 | if not patterns_str: |
| 42 | return [] |
| 43 | return [p.strip() for p in patterns_str.split(",") if p.strip()] |
| 44 | |
| 45 | |
| 46 | def _read_stored_language_state(output_dir: Path) -> tuple[bool, str | None]: |
| 47 | """Return ``(known, language)`` recorded in ``metadata.json``. |
| 48 | |
| 49 | ``known`` is False when ``metadata.json`` has no ``generation_info`` or no |
| 50 | ``language`` key (e.g., legacy docs or an incomplete run that only |
| 51 | persisted usage stats), so ``--update`` does not misread an unknown |
| 52 | language as English. |
| 53 | """ |
| 54 | import json |
| 55 | |
| 56 | try: |
| 57 | metadata = json.loads((output_dir / "metadata.json").read_text(encoding="utf-8")) |
| 58 | info = metadata.get("generation_info") |
| 59 | if not isinstance(info, dict) or "language" not in info: |
| 60 | return False, None |
| 61 | return True, info.get("language") |
| 62 | except (OSError, json.JSONDecodeError, AttributeError): |
| 63 | return False, None |
| 64 | |
| 65 | |
| 66 | def _read_stored_language(output_dir: Path) -> str | None: |
| 67 | """Language recorded in metadata.json by the previous generation (None = English).""" |
| 68 | _, stored = _read_stored_language_state(output_dir) |
| 69 | return stored |
| 70 | |
| 71 | |
| 72 | def _detect_changed_files( |
| 73 | repo_path: Path, output_dir: Path, logger, verbose: bool, compare_to: str | None = None |
| 74 | ) -> list[str] | None: |
| 75 | """ |
| 76 | Detect files changed since the last documentation generation. |
| 77 | |
| 78 | Reads the commit_id from metadata.json and compares with current HEAD |
| 79 | using git diff. When running inside a subdirectory of a monorepo, |
| 80 | only files under that subdirectory are returned. |
| 81 | |
| 82 | Returns list of changed file paths relative to repo_path, or None if |
| 83 | unable to determine (e.g., no metadata, not a git repo). |
| 84 | """ |
| 85 | import json |
| 86 | |
| 87 | prev_commit = None |
| 88 | if compare_to: |
| 89 | prev_commit = compare_to |
| 90 | else: |
| 91 | metadata_path = output_dir / "metadata.json" |
| 92 | if not metadata_path.exists(): |
| 93 | if verbose: |
| 94 | logger.debug( |
| 95 | "No metadata.json found — cannot detect changes, running full generation." |
| 96 | ) |
| 97 | return None |
| 98 | |
| 99 | try: |
no test coverage detected