Move
move
Atomic move pipeline: relocate top-level symbols between modules.
ImportCycleError
Bases: Exception
Raised when a move would introduce a new import cycle.
Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
MoveValidationError
Bases: Exception
Raised when a rendered module fails to parse post-transform.
Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
OverloadPartialMoveError
SymbolAlreadyExistsError
SymbolNotFoundError
batch_edit(path, operations)
Apply a batch of file operations atomically via axm-edit.
Accepts dict-shaped operations ({op, file, edits|content}) and
delegates to :func:axm_edit.core.engine.batch_apply. Raises on any
validation error so callers can trigger rollback.
Source code in packages/axm-anvil/src/axm_anvil/core/move.py
detect_fixture_dependencies(blocks, local_names)
Return the pytest fixture names a set of moved blocks depend on.
A fixture dependency is a parameter name on a def test_* function or a
@pytest.fixture-decorated function (including methods of a moved
class), excluding self/cls, defaulted parameters, the pytest
builtin fixtures in :data:PYTEST_BUILTIN_FIXTURES, and any name already
resolvable as a local definition or import (local_names). Pure,
in-memory CST analysis; no filesystem access.
Source code in packages/axm-anvil/src/axm_anvil/core/move.py
move_symbols(source_path, target_path, symbol_names, dry_run=False, workspace_root=None, shared_helpers='duplicate', shared_helpers_module=None, reexport=False, rename=None, check=False, strict=False, insert_after=None, include_helpers=True, side_effect_decorators=None)
Move top-level symbols from source_path to target_path.
Pipeline: parse → expand overloads → extract blocks → gather deps →
build new target (imports + constants + symbols) → remove from source
→ classify shared helpers → validate parseability → atomic write via
batch_edit → ruff fix.
shared_helpers selects the strategy when a helper is used by both a
moved symbol and a remaining source symbol: "duplicate" copies and
keeps the helper (emitting a warning); "error" aborts with
:class:SharedHelpersError; "extract" is reserved for Phase 3.
When reexport=True, callers are left untouched and a
from new_module import <names> # re-export for backwards compat line
is appended to the source module. Incompatible with rename=.
When check=True, the move is simulated (no files written) and any
newly introduced import cycle raises :class:ImportCycleError. A
normal (non-dry_run) write also performs this check; dry_run=True
alone preserves its historical "preview without enforcement" contract.
A requested name that is absent from the source module's top-level
symbols is skipped with a warning on :attr:MovePlan.warnings
rather than aborting the whole plan. Pass strict=True to restore
the legacy behaviour of raising :class:SymbolNotFoundError on the
first absent name.
insert_after controls where the moved blocks land in the target
module body: when it names an existing top-level symbol the blocks are
spliced immediately after it; when None (default) the blocks append
at the end (unchanged contract); when it names an absent symbol the
blocks append at the end and a warning is added to
:attr:MovePlan.warnings. Imports and constants keep their historical
placement regardless of insert_after.
include_helpers (default True) preserves the historical
behaviour of copying transitively-referenced local helpers and
constants into the target. When False those helpers/constants are
not copied (the moved code is left referencing them), a warning
enumerating the un-copied local helper names is added to
:attr:MovePlan.warnings, and the shared_helpers classification is
short-circuited (nothing is duplicated or extracted). Imports required
by the moved code are always copied regardless of this flag.
Source code in packages/axm-anvil/src/axm_anvil/core/move.py
| Python | |
|---|---|
2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 | |