Index
core
Core module for axm-edit.
Contains the batch editing engine and git checkpoint logic.
batch_apply(root, operations)
Validate and apply a batch of file operations.
Atomicity contract:
- Validation is the gate. All operations are validated first; if any
fails the batch is rejected wholesale (
success=False) before a single byte is written — a true all-or-nothing guarantee. Validation includes the syntax gate: a batch that would leave a parseable Python, TOML or JSON file unparseable is refused (:mod:axm_edit.core.syntax_gate). JSON comments and trailing commas are tolerated; new JSON files are unchecked. - Apply is best-effort with automatic rollback. Once validation
passes, a targeted checkpoint of every touched path is captured and the
operations are applied. If any exception occurs mid-apply (anchor
drift, a
write_text/unlink/mkdirfailure, a permission error, …) the partial work is rolled back to that checkpoint — touched files are restored to their pre-batch bytes and batch-created files (and the empty directories created for them) are removed — and a failingBatchResultis returned. The filesystem is not made transactional at the OS level; the rollback restores only the snapshotted paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Project root directory (all paths are relative to this). |
required |
operations
|
Sequence[Operation]
|
List of replace, create, rewrite and delete operations. |
required |
Returns:
| Type | Description |
|---|---|
BatchResult
|
BatchResult with success status, a targeted-path snapshot |
BatchResult
|
( |
Source code in packages/axm-edit/src/axm_edit/core/engine.py
| Python | |
|---|---|
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
create_checkpoint(root, operations)
Snapshot every path operations will touch, before they are applied.
For each operation's target path the snapshot records whether the file
currently exists and, if so, its original bytes. The result is a JSON
string keyed by resolved relative path, suitable for storage on
BatchResult.checkpoint and for passing back to :func:rollback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Project root directory (all paths are relative to this). |
required |
operations
|
Sequence[Operation]
|
The batch about to be applied — replace, create and
delete operations whose |
required |
Returns:
| Type | Description |
|---|---|
str
|
A JSON snapshot string. Always returned (never |
str
|
there are operations, in git and non-git directories alike. |
Source code in packages/axm-edit/src/axm_edit/core/checkpoint.py
rollback(root, checkpoint)
Restore exactly the paths captured by checkpoint to their prior state.
Rollback is a strict inverse of the batch and best-effort: for each snapshotted path a file that existed is rewritten with its original bytes, a file that did not exist before is removed, and only the directories the batch itself created (recorded in the snapshot) are pruned — a pre-existing directory is never removed. Every captured path is attempted even if an earlier one fails, so a partial rollback is fully reported. No git command is run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Project root directory. |
required |
checkpoint
|
str
|
The JSON snapshot returned by :func: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
RollbackResult
|
class: |
RollbackResult
|
paths restored and those that could not be restored. |
|
RollbackResult
|
is |
|
RollbackResult
|
a malformed snapshot yields |