simvx.editor.refactor_extract¶
Extract classes from a single .py file into a sibling folder/package.
The “Extract classes to folder” refactoring takes a multi-class scene
file like src/things.py (containing classes Foo, Bar) and
splits it into:
src/things/__init__.py— re-exports each extracted classsrc/things/foo.py—class Fooand its required importssrc/things/bar.py—class Barand its required imports
Importers like from src.things import Foo keep working transparently
through Python’s package resolution (the new __init__.py provides
the names).
Refusal cases (raise :class:ExtractRefused):
The file has fewer than two top-level classes — extraction is a no-op.
The file has top-level statements that are neither classes nor imports (free functions, module-level state, etc.) — these have nowhere clean to land. The user must inline or relocate them before extraction.
A folder of the target name already exists.
Module Contents¶
Classes¶
Outcome of :func: |
Functions¶
Extract every top-level class from |
Data¶
API¶
- simvx.editor.refactor_extract.log¶
‘getLogger(…)’
- exception simvx.editor.refactor_extract.ExtractRefused[source]¶
Bases:
ValueErrorRaised when a file cannot be cleanly extracted to a folder.
Initialization
Initialize self. See help(type(self)) for accurate signature.
- class __cause__¶
- class __context__¶
- __delattr__()¶
- __dir__()¶
- __eq__()¶
- __format__()¶
- __ge__()¶
- __getattribute__()¶
- __getstate__()¶
- __gt__()¶
- __hash__()¶
- __le__()¶
- __lt__()¶
- __ne__()¶
- __new__()¶
- __reduce__()¶
- __reduce_ex__()¶
- __repr__()¶
- __setattr__()¶
- __setstate__()¶
- __sizeof__()¶
- __str__()¶
- __subclasshook__()¶
- class __suppress_context__¶
- class __traceback__¶
- add_note()¶
- class args¶
- with_traceback()¶
- class simvx.editor.refactor_extract.ExtractResult[source]¶
Outcome of :func:
extract_to_folder.- folder: pathlib.Path¶
None
- created_files: tuple[pathlib.Path, ...]¶
None
- original_path: pathlib.Path¶
None
- simvx.editor.refactor_extract.extract_to_folder(file_path: pathlib.Path, project_index: simvx.editor.project_classes.ProjectClassIndex | None = None) simvx.editor.refactor_extract.ExtractResult[source]¶
Extract every top-level class from
file_pathinto a sibling folder.The folder is created at
file_path.parent / file_path.stem. The originalfile_pathis deleted on success.Each extracted class file inherits the original file’s import block verbatim (lint may flag unused imports per file — the user can prune those manually). Inter-class dependencies (one extracted class subclasses another) are wired via a relative import inside the new folder.
project_indexis refreshed at the end so downstream callers see the new layout. May beNonefor one-shot scripted use.Raises :class:
ExtractRefusedon failure with a message pointing at the offending construct.