A minimal framework for explicit phase structuring around the main action (inspired by AAA pattern and Design by Contract)
Project description
metamk
A minimal framework for defining phase structure around a main action.
Inspired by Arrange–Act–Assert testing pattern and Design by Contract,
metamk structures execution into clear, explicit phases without adding control logic.
It separates the main processing phase from setup, checks, and cleanup,
and provides both synchronous and asynchronous APIs.
from metamk import Mark
mark = Mark()
async with mark.a.as_block():
mark.a.setup(async_setup())
mark.a.before(async_check())
result = mark.MAIN(await async_action())
mark.a.after(async_validate())
mark.a.final(async_cleanup())
The main action (MAIN) always belongs to Mark,
while async phase methods are available under Mark.a.
Synchronous use is also supported:
with mark.as_block():
mark.setup(lambda: print("setup"))
mark.before(lambda: True)
result = mark.MAIN("main action")
mark.after(lambda: True)
mark.final(lambda: print("done"))
When you want to group multiple operations within the same phase,
you can use the corresponding as_*_block() context instead of a single method call.
async with mark.a.as_block():
async with mark.a.as_setup_block():
await obj.setup()
async with mark.a.as_before_block():
await obj.pre_check()
async with mark.a.as_MAIN_block():
result = await obj.main_action()
print(f"MAIN result: {result}")
async with mark.a.as_after_block():
await obj.validate()
async with mark.a.as_final_block():
await obj.cleanup()
Phase Management
This module provides a safe and flexible mechanism for managing the execution state (phase) of a process.
Phases generally progress in the following order:
INIT → SETUP → BEFORE → MAIN → CLEANUP → AFTER → FINAL → TERMINATED
However, strict sequential progression is not enforced.
While phases are expected to move “forward” in order,
it is allowed to call the same phase method or block multiple times in succession,
or to skip intermediate phases — for example, jumping directly to FINAL if necessary.
Additionally, the CLEANUP and AFTER phases require that the MAIN phase has already been executed.
If this condition is not met, or if the phase order is reversed, a PhaseError will be raised.
The INVARIANT phase is a flexible phase that can be invoked after any phase,
as long as the process has not reached the TERMINATED state.
Furthermore, by using Mark.invoke, you can perform a simple, standalone call
that is completely independent of the phase system.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file metamk-0.0.2.tar.gz.
File metadata
- Download URL: metamk-0.0.2.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3a6298009b3c1b78b86c1d1ff5eed359119dd9dccd94ec1d5785e86904181da
|
|
| MD5 |
ebf84171b32839ea4185b82296e113f3
|
|
| BLAKE2b-256 |
ac7e288f098e3fc2d9e52e65631c88e0cff7d324a248a4fd42beee6d59bc1300
|
File details
Details for the file metamk-0.0.2-py3-none-any.whl.
File metadata
- Download URL: metamk-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b70160ba009ec810b90662a72ba941ecac28e0042ba8c3f901426606c10cc61
|
|
| MD5 |
8a8d8b279dd276b3a69a36d4c9b6b781
|
|
| BLAKE2b-256 |
771273464f610d138509cfab5d40c99350f9450856de6bfb78a47b618330a294
|