diff --git a/scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/fix_self_imports.py b/scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/fix_self_imports.py new file mode 100644 index 00000000..698e9332 --- /dev/null +++ b/scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/fix_self_imports.py @@ -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. 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. import X' line where + 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()) diff --git a/src/external_editor.py b/src/external_editor.py index 46c46434..a97dc4d0 100644 --- a/src/external_editor.py +++ b/src/external_editor.py @@ -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 diff --git a/src/personas.py b/src/personas.py index 35c6bb30..dc3738b4 100644 --- a/src/personas.py +++ b/src/personas.py @@ -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: diff --git a/src/tool_bias.py b/src/tool_bias.py index 48f4e1ca..94cfbbfd 100644 --- a/src/tool_bias.py +++ b/src/tool_bias.py @@ -1,6 +1,5 @@ from typing import List, Dict, Any, Optional -from src.tool_bias import BiasProfile from src.tool_presets import Tool, ToolPreset diff --git a/src/tool_presets.py b/src/tool_presets.py index d4e3e40c..c119b9b3 100644 --- a/src/tool_presets.py +++ b/src/tool_presets.py @@ -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: diff --git a/src/workspace_manager.py b/src/workspace_manager.py index 4ea5ad37..bdab97c6 100644 --- a/src/workspace_manager.py +++ b/src/workspace_manager.py @@ -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