Mahonia is a domain specific language (DSL) for defining, evaluating, saving, and serializing binary expressions.
Project description
Mahonia
Mahonia is a domain specific language (DSL) for defining, evaluating, saving, and serializing binary expressions within a Python interpreter.
Motivation
Say that you are writing an application that conducts some assembly line testing at a manufacturing facility. While the primary requirement is to flag those units that do not meet expectations, a secondary requirement is to record what, why, and how a test has failed.
First, define what is being measured - the "context".
from typing import NamedTuple
from mahonia import Approximately, PlusMinus, Predicate, Var
class Measurements(NamedTuple):
voltage: float
Next, for each "variable" of the context, we declare a matching Mahonia Var type.
voltage = Var[float, Measurements]("voltage")
Now we can write an expression. This expression defines a named predicate that
will evaluate to True if the evaluated voltage is within 0.05 of 5.0.
expr = Predicate(
"Voltage OK",
Approximately(
voltage, PlusMinus("Nominal", 5.0, plus_minus=0.05)
)
)
Then we'll take the measurement and bind it:
from my_app import get_voltage
voltage_check = expr.bind(MyContext(voltage=get_voltage()))
This creates an immutable expression that Mahonia calls a BoundExpr. We can
evaluate it as many times as we like:
voltage_check.unwrap() # True
voltage_check.unwrap() # True
We can inspect the evaluation context:
print(voltage_check.ctx) # Measurements(voltage=5.03)
As well as serialize it for the logs:
str(voltage_check) # or voltage_check.to_string()
# If it was success, for example:
# Voltage OK: True (voltage:5.03 ≈ Nominal:5.0 ± 0.05 -> True)
# Or a fail:
# Voltage OK: False (voltage:4.90 ≈ Nominal:5.0 ± 0.05 -> False)
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 mahonia-0.2.0.tar.gz.
File metadata
- Download URL: mahonia-0.2.0.tar.gz
- Upload date:
- Size: 54.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67f1f6afc21e05e01ead31093d82aad50ef2db4f4c99651e744cc98976523593
|
|
| MD5 |
a23d491059d68ab7e438fc4690bf6de7
|
|
| BLAKE2b-256 |
ea52a5965cbb2983ec7d646c919977fc8e3ede28ef0cb279fb611602a3f5bdfd
|
Provenance
The following attestation bundles were made for mahonia-0.2.0.tar.gz:
Publisher:
publish.yaml on JPHutchins/mahonia
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mahonia-0.2.0.tar.gz -
Subject digest:
67f1f6afc21e05e01ead31093d82aad50ef2db4f4c99651e744cc98976523593 - Sigstore transparency entry: 437351345
- Sigstore integration time:
-
Permalink:
JPHutchins/mahonia@e77db7e871d422bbbb84e216e3d4a2b80edc3291 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/JPHutchins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e77db7e871d422bbbb84e216e3d4a2b80edc3291 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mahonia-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mahonia-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d980c96863c79a1f2b8acde6c795ce4530aa7620888ea18fedbe24a4d89c4a9c
|
|
| MD5 |
b0394eb9ea40a84cf68a1481d0b71b2e
|
|
| BLAKE2b-256 |
cb6f4e1e38bdb0820596100f4c242d14fda775e7bcae9341417831aaa74afbf8
|
Provenance
The following attestation bundles were made for mahonia-0.2.0-py3-none-any.whl:
Publisher:
publish.yaml on JPHutchins/mahonia
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mahonia-0.2.0-py3-none-any.whl -
Subject digest:
d980c96863c79a1f2b8acde6c795ce4530aa7620888ea18fedbe24a4d89c4a9c - Sigstore transparency entry: 437351380
- Sigstore integration time:
-
Permalink:
JPHutchins/mahonia@e77db7e871d422bbbb84e216e3d4a2b80edc3291 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/JPHutchins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e77db7e871d422bbbb84e216e3d4a2b80edc3291 -
Trigger Event:
push
-
Statement type: