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
MovePathError
Bases: Exception
Raised when source and target paths share no usable common base.
Computing the relative paths handed to batch_edit requires a base
directory that contains both the source and the target. When the two
live in disjoint trees (e.g. different drives) no such base exists, so the
fallback raises this typed error instead of leaking a bare ValueError.
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 | |
|---|---|
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 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 | |