Remove cached module documentation for modules that contain changed files. Reads module_tree.json to find which modules contain changed files, then deletes their .md files so they get regenerated.
(
output_dir: Path,
changed_files: List[str],
logger,
verbose: bool
)
| 146 | |
| 147 | |
| 148 | def _invalidate_affected_modules( |
| 149 | output_dir: Path, |
| 150 | changed_files: List[str], |
| 151 | logger, |
| 152 | verbose: bool |
| 153 | ): |
| 154 | """ |
| 155 | Remove cached module documentation for modules that contain changed files. |
| 156 | |
| 157 | Reads module_tree.json to find which modules contain changed files, |
| 158 | then deletes their .md files so they get regenerated. |
| 159 | """ |
| 160 | import json |
| 161 | |
| 162 | module_tree_path = output_dir / "module_tree.json" |
| 163 | if not module_tree_path.exists(): |
| 164 | return |
| 165 | |
| 166 | try: |
| 167 | module_tree = json.loads(module_tree_path.read_text()) |
| 168 | except (json.JSONDecodeError, OSError): |
| 169 | return |
| 170 | |
| 171 | changed_set = set(changed_files) |
| 172 | modules_to_invalidate = set() |
| 173 | |
| 174 | def _find_affected(tree, parent_names=None): |
| 175 | if parent_names is None: |
| 176 | parent_names = [] |
| 177 | for mod_name, mod_info in tree.items(): |
| 178 | components = mod_info.get("components", []) |
| 179 | # Check if any component path overlaps with changed files |
| 180 | for comp in components: |
| 181 | # Component IDs may be class names, check if they match any changed file path |
| 182 | if any(changed_file in comp or comp in changed_file for changed_file in changed_set): |
| 183 | modules_to_invalidate.add(mod_name) |
| 184 | # Also invalidate parent modules |
| 185 | for parent in parent_names: |
| 186 | modules_to_invalidate.add(parent) |
| 187 | break |
| 188 | |
| 189 | children = mod_info.get("children", {}) |
| 190 | if isinstance(children, dict) and children: |
| 191 | _find_affected(children, parent_names + [mod_name]) |
| 192 | |
| 193 | _find_affected(module_tree) |
| 194 | |
| 195 | # Also remove overview.md since it depends on child docs |
| 196 | if modules_to_invalidate: |
| 197 | modules_to_invalidate.add("overview") |
| 198 | |
| 199 | # Delete affected module docs |
| 200 | for mod_name in modules_to_invalidate: |
| 201 | doc_path = output_dir / f"{mod_name}.md" |
| 202 | if doc_path.exists(): |
| 203 | doc_path.unlink() |
| 204 | if verbose: |
| 205 | logger.debug(f"Invalidated: {doc_path.name}") |
no test coverage detected