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