Index
axm_anvil
Deterministic CST-based refactoring toolkit for Python.
Move, rename, and extract symbols atomically across files (split and merge are on the roadmap).
ExtractTool
Bases: AXMTool
Extract top-level symbols from a module into a brand-new module.
Registered as anvil_extract via the axm.tools entry point.
Delegates to :func:axm_anvil.core.extract.extract_symbols (itself a
thin adapter over the move pipeline) and adapts exceptions into
ToolResult(success=False). The result shape matches anvil_move.
Source code in packages/axm-anvil/src/axm_anvil/tools/extract.py
| Python | |
|---|---|
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
name
property
Return tool name for registry lookup.
execute(*, path='.', symbols='', from_file='', to_file='', dry_run=False, shared_helpers='duplicate', shared_helpers_module=None, rename=None, strict=False, insert_after=None, include_helpers=True, side_effect_decorators=None, **kwargs)
Extract symbols (CSV) from from_file into a new to_file.
Parameters
path:
Workspace root used to resolve relative from_file / to_file
and to constrain caller updates.
symbols:
Comma-separated list of top-level symbol names to extract. Empty
entries are ignored.
from_file:
Source Python file. Relative paths are resolved against path.
to_file:
Target Python file to create. Relative paths are resolved
against path; missing parent directories are created.
dry_run:
When True, compute the :class:MovePlan without writing (and
without leaving a scaffolded target on disk).
shared_helpers:
Policy for helpers used by both moved and remaining symbols:
"duplicate", "extract", or "error".
shared_helpers_module:
Target module path used when shared_helpers="extract".
rename:
Optional JSON object string mapping old symbol names to new ones
(e.g. '{"OldName": "NewName"}'). Invalid JSON yields a
success=False result.
strict:
When True, a requested symbol absent from the source module
raises (surfaced as success=False) instead of being skipped
with a warning.
insert_after:
Optional name of a top-level symbol in the target module after
which extracted blocks are spliced. None appends at the end.
include_helpers:
When True (default) transitively-referenced local helpers and
constants are copied into the target.
side_effect_decorators:
Optional comma-separated list of extra side-effect decorator
dotted-names extending the built-in whitelist.
Returns
ToolResult
success=True with a plan summary on success; otherwise
success=False with a message (missing symbol, collision,
shared helpers, validation error).
Source code in packages/axm-anvil/src/axm_anvil/tools/extract.py
| Python | |
|---|---|
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
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
MovePlan
dataclass
Result of a :func:move_symbols call.
Carries the rendered source and target texts, the names that were
actually moved, and the direct dependencies (imports, constants)
copied into the target. warnings aggregates non-fatal issues
such as ruff post-processing errors.
Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
MoveTool
Bases: AXMTool
Move top-level symbols between Python files atomically.
Registered as anvil_move via the axm.tools entry point.
Delegates to :func:axm_anvil.core.move.move_symbols and adapts
exceptions into ToolResult(success=False).
Source code in packages/axm-anvil/src/axm_anvil/tools/move.py
| Python | |
|---|---|
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
name
property
Return tool name for registry lookup.
execute(*, path='.', symbols='', from_file='', to_file='', dry_run=False, 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, **kwargs)
Move symbols (CSV) from from_file to to_file.
Parameters
path:
Workspace root used to resolve relative from_file / to_file
and to constrain caller updates.
symbols:
Comma-separated list of top-level symbol names to move. Empty
entries are ignored.
from_file:
Source Python file. Relative paths are resolved against path.
to_file:
Target Python file. Relative paths are resolved against path.
dry_run:
When True, compute the :class:MovePlan without writing.
shared_helpers:
Policy for helpers used by both moved and remaining symbols:
"duplicate", "extract", or "error".
shared_helpers_module:
Target module path used when shared_helpers="extract".
reexport:
When True, leave callers untouched and inject a re-export in
the source module. Incompatible with rename.
rename:
Optional JSON object string mapping old symbol names to new ones
(e.g. '{"OldName": "NewName"}'). Parsed to dict[str, str]
and forwarded to :func:move_symbols. Invalid JSON yields a
success=False result.
strict:
When True, a requested symbol absent from the source module
raises (surfaced as success=False) instead of being silently
skipped with a warning. When False (default) the current
skip-and-warn behaviour is preserved.
insert_after:
Optional name of a top-level symbol in the target module; moved
blocks are spliced immediately after it. When None blocks
append at the end; an absent name appends at the end with a
warning.
include_helpers:
When True (default) transitively-referenced local helpers and
constants are copied into the target. When False they are not
copied (a warning enumerates the un-copied names); imports are
still copied regardless.
side_effect_decorators:
Optional comma-separated list of extra side-effect decorator
dotted-names that extend the built-in SIDE_EFFECT_DECORATORS
whitelist. A moved symbol decorated with a matching decorator
yields a non-blocking warning on the plan.
Returns
ToolResult
success=True with a MovePlan summary on success; otherwise
success=False with a message describing the failure
(missing symbol, collision, shared helpers, validation error).
Source code in packages/axm-anvil/src/axm_anvil/tools/move.py
| Python | |
|---|---|
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
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
RenamePlan
dataclass
Result of a :func:rename_symbols call.
Carries the rewritten text of the defining module, the names that were
actually renamed (old -> new), the caller-file rewrites and any
non-fatal warnings (e.g. a requested symbol that was absent in
non-strict mode).
Source code in packages/axm-anvil/src/axm_anvil/core/rename.py
RenameTool
Bases: AXMTool
Rename top-level symbols in place, rewriting cross-file callers.
Registered as anvil_rename via the axm.tools entry point.
Delegates to :func:axm_anvil.core.rename.rename_symbols and adapts
exceptions into ToolResult(success=False). Mono-symbol renames use
--old/--new; batch renames pass a --mapping JSON object
(symmetric with the rename JSON of :class:MoveTool). reexport
is not exposed (incompatible with rename, per MoveTool.execute).
Source code in packages/axm-anvil/src/axm_anvil/tools/rename.py
| Python | |
|---|---|
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
name
property
Return tool name for registry lookup.
execute(*, path='.', file='', old='', new='', mapping=None, dry_run=False, strict=False, **kwargs)
Rename symbol(s) in file and rewrite cross-file callers.
Parameters
path:
Workspace root used to resolve a relative file and to
constrain caller discovery.
file:
Python file defining the symbols. Relative paths resolve against
path.
old / new:
Mono-symbol rename: rename old to new. Ignored when
mapping is provided.
mapping:
Optional JSON object string mapping old names to new ones
(e.g. '{"OldName": "NewName"}') for batch renames. Invalid
JSON yields a success=False result.
dry_run:
When True, compute the :class:RenamePlan without writing.
strict:
When True an absent symbol raises (surfaced as
success=False); when False (default) it is skipped with
a warning.
Returns
ToolResult
success=True with a rename summary (renamed,
callers_updated, warnings, files_modified) on
success; otherwise success=False with a failure message.
Source code in packages/axm-anvil/src/axm_anvil/tools/rename.py
SharedHelpersError
Bases: Exception
Raised in error mode when shared helpers would be duplicated.
Source code in packages/axm-anvil/src/axm_anvil/core/plan.py
SymbolAlreadyExistsError
SymbolNotFoundError
extract_symbols(source_path, target_path, symbol_names, *, dry_run=False, workspace_root=None, shared_helpers='duplicate', shared_helpers_module=None, rename=None, strict=False, insert_after=None, include_helpers=True, side_effect_decorators=None)
Extract symbol_names from source_path into a new module.
extract is the specialisation of :func:move_symbols where
target_path is created rather than amended. The moved blocks and
their transitive dependencies (imports, local helpers, constants) are
copied into the new module, and cross-file callers are rewritten to
import from it — all via the move pipeline.
When target_path does not exist it is scaffolded as an empty module
so the move pipeline can fill it. A pre-existing target that already
defines a requested symbol raises :class:SymbolAlreadyExistsError
(no silent overwrite).
With dry_run=True the :class:MovePlan is computed without leaving
any file on disk: a target scaffolded for the dry run is removed before
returning, so the source layout is byte-identical to before the call.
All other parameters mirror :func:move_symbols and are forwarded
verbatim. reexport and check are intentionally not exposed:
re-exporting from / cycle-checking against a freshly created module is
meaningless for an extract.
Source code in packages/axm-anvil/src/axm_anvil/core/extract.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 | |
rename_symbols(path, file, mapping, *, dry_run=False, workspace_root=None, strict=False)
Rename top-level symbols in file and rewrite cross-file callers.
Parameters
path:
Workspace root used to resolve a relative file and to constrain
caller discovery.
file:
Python file defining the symbols. Relative paths resolve against
path.
mapping:
{old_name: new_name} for the top-level symbols to rename.
dry_run:
When True, compute the :class:RenamePlan without writing.
workspace_root:
Explicit workspace root; falls back to the nearest ancestor with a
pyproject.toml when None.
strict:
When True a requested old name absent from the module raises
:class:SymbolNotFoundError; when False (default) it is skipped
with a warning on :attr:RenamePlan.warnings.
Returns
RenamePlan The rewritten module text, the active renames, caller rewrites and warnings. Caller rewriting is pattern-based on imports; see the module docstring for the uncovered cases.