Skip to content

Commit 389ecde

Browse files
committed
fix(edges): skip non-package prefixes in Python backward dependency discovery
1 parent 52139e9 commit 389ecde

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • src/treemapper/diffctx/edges/semantic

src/treemapper/diffctx/edges/semantic/python.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,19 @@ def _collect_changed_modules(self, py_changed: list[Path], repo_root: Path | Non
136136
if module:
137137
changed_modules.add(module)
138138
parts = module.split(".")
139-
for i in range(1, len(parts) + 1):
140-
changed_modules.add(".".join(parts[:i]))
139+
for i in range(1, len(parts)):
140+
prefix = ".".join(parts[:i])
141+
if self._is_real_package(parts[:i], repo_root):
142+
changed_modules.add(prefix)
141143
return changed_modules
142144

145+
@staticmethod
146+
def _is_real_package(parts: list[str], repo_root: Path | None) -> bool:
147+
if repo_root is None:
148+
return True
149+
pkg_dir = repo_root.joinpath(*parts)
150+
return (pkg_dir / "__init__.py").exists()
151+
143152
def _find_files_importing_modules(
144153
self, all_candidate_files: list[Path], changed_set: set[Path], changed_modules: set[str], repo_root: Path | None = None
145154
) -> list[Path]:

0 commit comments

Comments
 (0)