MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / _invalidate_affected_modules

Function _invalidate_affected_modules

codewiki/cli/commands/generate.py:148–208  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

146 changed.append(diff.a_path)
147 if diff.b_path and diff.b_path != diff.a_path:
148 changed.append(diff.b_path)
149
150 # Filter to files under the current subdirectory and strip the prefix
151 # so paths align with module_tree.json component paths
152 filtered = []
153 if subpath_prefix == ".":
154 filtered = changed
155 else:
156 prefix = subpath_prefix + "/"
157 for path in changed:
158 if path.startswith(prefix):
159 filtered.append(path[len(prefix) :])
160
161 if verbose:
162 logger.debug(f"Changes between {prev_commit[:8]} and {current_commit[:8]}:")
163 if subpath_prefix != ".":
164 logger.debug(f" Scoped to subdirectory: {subpath_prefix}")
165 for f in filtered[:10]:
166 logger.debug(f" {f}")
167 if len(filtered) > 10:
168 logger.debug(f" ... and {len(filtered) - 10} more")
169
170 return filtered
171 except Exception as e: # noqa: BLE001 — fall back to regenerating everything
172 if verbose:
173 logger.debug(f"Git diff failed: {e} — running full generation.")
174 return None
175
176
177def _invalidate_affected_modules(output_dir: Path, changed_files: list[str], logger, verbose: bool):
178 """
179 Remove cached module documentation for modules that contain changed files.
180
181 Reads module_tree.json to find which modules contain changed files,
182 then deletes their .md files so they get regenerated.
183 """
184 import json
185
186 module_tree_path = output_dir / "module_tree.json"
187 if not module_tree_path.exists():
188 return
189
190 try:
191 module_tree = json.loads(module_tree_path.read_text())
192 except (json.JSONDecodeError, OSError):
193 return
194
195 changed_set = set(changed_files)
196 modules_to_invalidate = set()
197
198 def _find_affected(tree, parent_names=None):
199 if parent_names is None:
200 parent_names = []
201 for mod_name, mod_info in tree.items():
202 components = mod_info.get("components", [])
203 # Check if any component path overlaps with changed files
204 for comp in components:
205 # Component IDs may be class names, check if they match any changed file path

Callers 1

generate_commandFunction · 0.85

Calls 3

_find_affectedFunction · 0.85
addMethod · 0.80
debugMethod · 0.80

Tested by

no test coverage detected