Private
Public Access
0
0

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:
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())
-3
View File
@@ -9,7 +9,6 @@ import tempfile
from pathlib import Path
from typing import Optional, List, Dict, Any
from src.external_editor import ExternalEditorConfig, TextEditorConfig
from src.result_types import ErrorInfo, ErrorKind, Result
@@ -24,7 +23,6 @@ class ExternalEditorLauncher:
"""
[C: tests/test_external_editor.py:TestExternalEditorLauncher.test_get_editor_by_name, tests/test_external_editor.py:TestExternalEditorLauncher.test_get_editor_returns_default, tests/test_external_editor.py:TestExternalEditorLauncher.test_get_editor_unknown_name]
"""
from src.external_editor import EMPTY_TEXT_EDITOR_CONFIG
if editor_name:
return self.config.editors.get(editor_name) or EMPTY_TEXT_EDITOR_CONFIG
return self.config.get_default()
@@ -96,7 +94,6 @@ def _find_vscode_common_paths() -> str:
def auto_detect_vscode() -> TextEditorConfig:
from src.external_editor import EMPTY_TEXT_EDITOR_CONFIG
global _cached_vscode_config
if _cached_vscode_config is not None:
return _cached_vscode_config
-1
View File
@@ -4,7 +4,6 @@ import tomli_w
from pathlib import Path
from typing import Dict, Any, Optional
from src.personas import Persona
from src import paths
class PersonaManager:
-1
View File
@@ -1,6 +1,5 @@
from typing import List, Dict, Any, Optional
from src.tool_bias import BiasProfile
from src.tool_presets import Tool, ToolPreset
-1
View File
@@ -6,7 +6,6 @@ from typing import Dict, List, Optional, Union, Any
from src import paths
from src.tool_bias import BiasProfile
from src.tool_presets import ToolPreset
class ToolPresetManager:
-1
View File
@@ -4,7 +4,6 @@ import tomli_w
from pathlib import Path
from typing import Dict, Any, Optional, Union
from src.workspace_manager import WorkspaceProfile
from src import paths