fix(consumers): remove self-imports from migration

The migration commit (8f11340b) replaced 'from src.models import X'
with 'from src.<destination> import X' in EVERY file including the
destination files themselves. This created self-imports like
'from src.external_editor import ExternalEditorConfig' in
src/external_editor.py (which defines ExternalEditorConfig locally).

This fix removes the spurious self-imports from the 5 destination
files that were affected:
 - src/external_editor.py (3 lines removed: 1 top-level + 2 in
                                 function bodies that my migration
                                 missed on the first pass)
 - src/personas.py (1 line removed)
 - src/tool_bias.py (1 line removed)
 - src/tool_presets.py (1 line removed)
 - src/workspace_manager.py (1 line removed)

The migration in non-destination files is correct and unchanged.

After this fix, the next merge of origin/tier2/module_taxonomy_refactor_20260627
(bringing in the v2 SHIPPED work) will not conflict on these files
because the self-imports are gone; the merge will apply v2's class
definitions cleanly.

The fix was performed by
scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/fix_self_imports.py
which removes 'from src.<module> import X' lines from files where
<module> matches the file's destination module name.
This commit is contained in:
ed
2026-06-26 13:35:24 -04:00
parent 8f11340b38
commit 6b0668f1a9
6 changed files with 70 additions and 7 deletions
@@ -0,0 +1,70 @@
"""Fix script: remove spurious self-imports from migration commit.
The previous commit (8f11340b) migrated 'from src.models import X'
to 'from src.<destination> import X' for ALL files, including the
destination files themselves. This created self-imports like
'from src.external_editor import ExternalEditorConfig' in
src/external_editor.py (which defines ExternalEditorConfig locally).
This script removes these self-imports:
- src/external_editor.py
- src/mcp_client.py
- src/personas.py
- src/project.py
- src/project_files.py
- src/tool_bias.py
- src/tool_presets.py
- src/workspace_manager.py
For each file, remove any 'from src.<module> import X' line where
<module> matches the destination module name.
"""
from __future__ import annotations
import re
import sys
from pathlib import Path
DESTINATION_FILES: dict[str, str] = {
"src/external_editor.py": "external_editor",
"src/mcp_client.py": "mcp_client",
"src/personas.py": "personas",
"src/project.py": "project",
"src/project_files.py": "project_files",
"src/tool_bias.py": "tool_bias",
"src/tool_presets.py": "tool_presets",
"src/workspace_manager.py": "workspace_manager",
}
def fix_file(rel_path: str, module: str) -> int:
path = Path(rel_path)
if not path.exists():
return 0
content = path.read_text(encoding="utf-8")
pattern = re.compile(
rf"^[ \t]*from\s+src\.{re.escape(module)}\s+import\s+.+?[ \t]*$\n?",
re.MULTILINE,
)
matches = pattern.findall(content)
if not matches:
return 0
new_content = pattern.sub("", content)
path.write_text(new_content, encoding="utf-8", newline="")
return len(matches)
def main() -> int:
total = 0
for rel_path, module in DESTINATION_FILES.items():
count = fix_file(rel_path, module)
if count > 0:
print(f" {rel_path}: removed {count} self-import line(s)")
total += count
print(f"\nTotal: {total} self-import line(s) removed")
return 0
if __name__ == "__main__":
sys.exit(main())