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 class

  • src/things/foo.pyclass Foo and its required imports

  • src/things/bar.pyclass Bar and 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

ExtractResult

Outcome of :func:extract_to_folder.

Functions

extract_to_folder

Extract every top-level class from file_path into a sibling folder.

Data

log

API

simvx.editor.refactor_extract.log

‘getLogger(…)’

exception simvx.editor.refactor_extract.ExtractRefused[source]

Bases: ValueError

Raised 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_path into a sibling folder.

The folder is created at file_path.parent / file_path.stem. The original file_path is 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_index is refreshed at the end so downstream callers see the new layout. May be None for one-shot scripted use.

Raises :class:ExtractRefused on failure with a message pointing at the offending construct.