necoherence 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- necoherence-0.2.2/PKG-INFO +82 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/pyproject.toml +7 -1
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/signature_values.py +28 -2
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_lean_value_decisions.py +65 -0
- necoherence-0.2.0/PKG-INFO +0 -11
- {necoherence-0.2.0 → necoherence-0.2.2}/.gitignore +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/LICENSE +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/README-ja.md +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/README.md +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/examples/01_fold_arithmetic.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/examples/02_recurse_gcd.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/examples/03_closure_reachability.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/__init__.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/call.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/core.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/dynamic_admission.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/files.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/iteration.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/network_effect.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/reconcile.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/record.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/request_progression.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/signature_support.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/store.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/transition.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/src/necoherence/type_signatures.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_call.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_core.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_default_materialization.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_dynamic_admission.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_examples.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_files.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_format_rule_inclusion.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_iteration.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_mutation_detection.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_network_effect.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_network_effect_progression.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_profile_artifact_admission.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_profile_predicate_vectors.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_profile_wire_vectors.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_reconcile.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_record.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_recursive_values.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_representation_acceptance.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_request_progression.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_semantic_discriminator.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_semantic_grapheme.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_store.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_transition.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_type_signatures.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/test_wrapper_base64_vectors.py +0 -0
- {necoherence-0.2.0 → necoherence-0.2.2}/tests/v4_samples.py +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: necoherence
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Revision-aware state transition utilities for Python
|
|
5
|
+
Project-URL: Homepage, https://github.com/barineco/necoherence
|
|
6
|
+
Project-URL: Repository, https://github.com/barineco/necoherence
|
|
7
|
+
Project-URL: Issues, https://github.com/barineco/necoherence/issues
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: hypothesis; extra == 'dev'
|
|
13
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
14
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Necoherence for Python
|
|
18
|
+
|
|
19
|
+
[Project overview](https://github.com/barineco/necoherence/blob/publish/README.md) | [日本語](README-ja.md)
|
|
20
|
+
|
|
21
|
+
This package is the Python implementation of Necoherence, for Python 3.12 or later.
|
|
22
|
+
It uses only the standard library at run time.
|
|
23
|
+
|
|
24
|
+
## Accepting a semantic profile
|
|
25
|
+
|
|
26
|
+
The caller passes a versioned semantic profile when decoding declarations and when accepting a generated library.
|
|
27
|
+
The accepted profile defines the wire format used by validation, encoding and decoding, and execution.
|
|
28
|
+
|
|
29
|
+
The expected profile reference, the sources, and the trusted bytes are passed as arguments separate from the input bytes.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from necoherence.signature_values import ValueContext
|
|
33
|
+
from necoherence.type_signatures import checkLibrary, decode_profile_artifact
|
|
34
|
+
|
|
35
|
+
def decide(expected, sources, trusted, input_bytes, library, type_id, value):
|
|
36
|
+
profile = decode_profile_artifact(expected, sources, trusted, input_bytes)
|
|
37
|
+
checked = checkLibrary({**library, "profile": profile})
|
|
38
|
+
context = ValueContext({
|
|
39
|
+
"profile": checked.value["profile"], "nodes": checked.value["nodes"],
|
|
40
|
+
})
|
|
41
|
+
return context.validate(type_id, value)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Failures are returned as the following types, one for each cause:
|
|
45
|
+
|
|
46
|
+
- `WireFailure`: the profile's wire value is malformed
|
|
47
|
+
- `DeclarationFailure`: the profile or the library violates a declaration condition
|
|
48
|
+
- `AdmissionFailure`: the profile differs from the expected reference or sources
|
|
49
|
+
- `MeaningFailure`: a type lacks a definition of its meaning
|
|
50
|
+
- `ValueFailure`: validation rejected the value
|
|
51
|
+
|
|
52
|
+
## Other features
|
|
53
|
+
|
|
54
|
+
Besides the features listed in the [project overview](https://github.com/barineco/necoherence/blob/publish/README.md), the package provides the following:
|
|
55
|
+
|
|
56
|
+
- Declaration checking: detects errors in declarations of types and operations, such as duplicate identifiers and references to undeclared types or definitions
|
|
57
|
+
- Runtime for generated code: the shared value validation and codec routines that generated Python code calls at run time
|
|
58
|
+
|
|
59
|
+
The optional [HTTP adapter](../python-http-adapter/) is distributed separately as `necoherence-http-adapter`. It executes network-effect commands and returns observations to the core ledger.
|
|
60
|
+
|
|
61
|
+
## Tools
|
|
62
|
+
|
|
63
|
+
The generator, which produces Python types and codecs from declarations of types and operations, is in [tools/](https://github.com/barineco/necoherence/tree/publish/tools).
|
|
64
|
+
Its license is AGPL-3.0-only.
|
|
65
|
+
|
|
66
|
+
## Examples
|
|
67
|
+
|
|
68
|
+
Examples are in [examples/](https://github.com/barineco/necoherence/tree/publish/python/examples).
|
|
69
|
+
|
|
70
|
+
## Testing and type checking
|
|
71
|
+
|
|
72
|
+
The following commands run the tests and the type checks:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
python3 -m pip install ".[dev]"
|
|
76
|
+
python3 -m pytest -q
|
|
77
|
+
python3 -m mypy src tests
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
[MIT](LICENSE)
|
|
@@ -7,13 +7,19 @@ build-backend = "hatchling.build"
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "necoherence"
|
|
10
|
-
version = "0.2.
|
|
10
|
+
version = "0.2.2"
|
|
11
11
|
description = "Revision-aware state transition utilities for Python"
|
|
12
|
+
readme = "README.md"
|
|
12
13
|
license = "MIT"
|
|
13
14
|
license-files = ["LICENSE"]
|
|
14
15
|
requires-python = ">=3.12"
|
|
15
16
|
dependencies = []
|
|
16
17
|
|
|
18
|
+
[project.urls]
|
|
19
|
+
Homepage = "https://github.com/barineco/necoherence"
|
|
20
|
+
Repository = "https://github.com/barineco/necoherence"
|
|
21
|
+
Issues = "https://github.com/barineco/necoherence/issues"
|
|
22
|
+
|
|
17
23
|
[project.optional-dependencies]
|
|
18
24
|
dev = ["pytest", "hypothesis", "mypy"]
|
|
19
25
|
|
|
@@ -21,6 +21,11 @@ class DecimalLiteral:
|
|
|
21
21
|
spelling: str
|
|
22
22
|
|
|
23
23
|
def __post_init__(self):
|
|
24
|
+
if not isinstance(self.spelling, str) or re.fullmatch(
|
|
25
|
+
r"-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?",
|
|
26
|
+
self.spelling,
|
|
27
|
+
) is None:
|
|
28
|
+
raise ValueError("invalid decimal literal")
|
|
24
29
|
try:
|
|
25
30
|
value = Decimal(self.spelling)
|
|
26
31
|
except InvalidOperation as error:
|
|
@@ -978,10 +983,31 @@ class ValueContext:
|
|
|
978
983
|
def _validate_data(self, reference, value, path, trace):
|
|
979
984
|
def reject(condition, observed=value, at=path):
|
|
980
985
|
raise ValueFailure(reference, at, condition, observed, trace)
|
|
981
|
-
if type(value) is int
|
|
986
|
+
if type(value) is int:
|
|
982
987
|
_, failure = _integer_value(self.profile, {}, value)
|
|
983
988
|
if failure:
|
|
984
|
-
reject("IntegerDomain"
|
|
989
|
+
reject("IntegerDomain")
|
|
990
|
+
elif isinstance(value, (float, DecimalLiteral, Decimal)):
|
|
991
|
+
text = value.spelling if isinstance(value, DecimalLiteral) else str(value)
|
|
992
|
+
if re.fullmatch(r"-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?", text) is None:
|
|
993
|
+
reject("InvalidDataModel")
|
|
994
|
+
decimal_value = Decimal(text)
|
|
995
|
+
if not decimal_value.is_finite():
|
|
996
|
+
reject("InvalidDataModel")
|
|
997
|
+
default_name = self.profile.get("default_integer_domain")
|
|
998
|
+
binding = _named(self.profile.get("integer_domains", ()), default_name)
|
|
999
|
+
integral_form = binding is not None and "IntegralDecimal" in {
|
|
1000
|
+
_unit(form) for form in binding.get("forms", ())
|
|
1001
|
+
}
|
|
1002
|
+
if integral_form and decimal_value == decimal_value.to_integral_value():
|
|
1003
|
+
domain = binding.get("range", {"tag": "Unbounded"})
|
|
1004
|
+
if sum_tag(domain) == "Inclusive":
|
|
1005
|
+
bounds = payload(domain)
|
|
1006
|
+
if decimal_value < Decimal(integer(bounds["minimum"])) or decimal_value > Decimal(integer(bounds["maximum"])):
|
|
1007
|
+
reject("IntegerDomain")
|
|
1008
|
+
return
|
|
1009
|
+
if not self.profile.get("numbers", {}).get("decimals", False):
|
|
1010
|
+
reject("InvalidDataModel")
|
|
985
1011
|
elif type(value) is str:
|
|
986
1012
|
if not _unicode_scalar_text(value):
|
|
987
1013
|
reject("InvalidDataModel")
|
|
@@ -124,3 +124,68 @@ def test_element_contract_null_is_decided_by_nullable_or_child_type():
|
|
|
124
124
|
assert context.validate("unknown-map-required", {"x": None}) == {"x": None}
|
|
125
125
|
with pytest.raises(ValueFailure):
|
|
126
126
|
context.validate("integer-map-required", {"x": None})
|
|
127
|
+
@pytest.mark.parametrize("value", [1.25, -1.25, 6.02e23])
|
|
128
|
+
def test_unknown_any_accepts_profile_admitted_decimals(value):
|
|
129
|
+
graph = representative_graph()
|
|
130
|
+
graph["profile"]["integer_domains"][0]["forms"] = [variant("Number")]
|
|
131
|
+
context = ValueContext(graph)
|
|
132
|
+
assert context.validate("unknown-any", value) == value
|
|
133
|
+
assert context.validate("unknown-array-required", [value]) == [value]
|
|
134
|
+
assert context.validate("unknown-map-required", {"nested": [value]}) == {"nested": [value]}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def test_unknown_any_integral_decimal_precedes_decimal_admission():
|
|
138
|
+
from necoherence.signature_values import DecimalLiteral
|
|
139
|
+
|
|
140
|
+
graph = representative_graph()
|
|
141
|
+
graph["profile"]["integer_domains"][0]["range"] = variant("Inclusive", fields={"minimum": "-10", "maximum": "10"})
|
|
142
|
+
context = ValueContext(graph)
|
|
143
|
+
assert context.validate("unknown-any", DecimalLiteral("1.0")) == DecimalLiteral("1.0")
|
|
144
|
+
assert context.validate("unknown-any", DecimalLiteral("1.25")) == DecimalLiteral("1.25")
|
|
145
|
+
with pytest.raises(ValueFailure) as caught:
|
|
146
|
+
context.validate("unknown-any", DecimalLiteral("11.0"))
|
|
147
|
+
assert caught.value.condition == "IntegerDomain"
|
|
148
|
+
with pytest.raises(ValueFailure) as caught:
|
|
149
|
+
context.validate("unknown-any", DecimalLiteral("1e999999"))
|
|
150
|
+
assert caught.value.condition == "IntegerDomain"
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_unknown_any_rejects_decimals_when_profile_disables_them():
|
|
154
|
+
graph = representative_graph()
|
|
155
|
+
graph["profile"]["numbers"]["decimals"] = False
|
|
156
|
+
graph["profile"]["integer_domains"][0]["range"] = variant("Inclusive", fields={"minimum": "-10", "maximum": "10"})
|
|
157
|
+
context = ValueContext(graph)
|
|
158
|
+
from necoherence.signature_values import DecimalLiteral
|
|
159
|
+
|
|
160
|
+
assert context.validate("unknown-any", DecimalLiteral("10.0")) == DecimalLiteral("10.0")
|
|
161
|
+
with pytest.raises(ValueFailure) as caught:
|
|
162
|
+
context.validate("unknown-any", DecimalLiteral("11.0"))
|
|
163
|
+
assert caught.value.condition == "IntegerDomain"
|
|
164
|
+
for value in (1.25, -1.25):
|
|
165
|
+
with pytest.raises(ValueFailure) as caught:
|
|
166
|
+
context.validate("unknown-any", value)
|
|
167
|
+
assert caught.value.condition == "InvalidDataModel"
|
|
168
|
+
with pytest.raises(ValueFailure) as caught:
|
|
169
|
+
context.validate("unknown-any", 6.02e23)
|
|
170
|
+
assert caught.value.condition == "IntegerDomain"
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@pytest.mark.parametrize("text", ["01.2", "1.", "1e", "+1.0"])
|
|
174
|
+
def test_unknown_any_rejects_malformed_decimal_json(text):
|
|
175
|
+
from necoherence.signature_values import decode_wire_json
|
|
176
|
+
|
|
177
|
+
with pytest.raises(ValueError):
|
|
178
|
+
decode_wire_json(text)
|
|
179
|
+
|
|
180
|
+
from necoherence.signature_values import DecimalLiteral
|
|
181
|
+
|
|
182
|
+
for text in ("01.2", "1.", "1e", "+1.0", "NaN", "Infinity"):
|
|
183
|
+
with pytest.raises(ValueError):
|
|
184
|
+
DecimalLiteral(text)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
@pytest.mark.parametrize("value", [float("nan"), float("inf")])
|
|
188
|
+
def test_unknown_any_rejects_non_json_native_floats(value):
|
|
189
|
+
with pytest.raises(ValueFailure) as caught:
|
|
190
|
+
ValueContext(representative_graph()).validate("unknown-any", value)
|
|
191
|
+
assert caught.value.condition == "InvalidDataModel"
|
necoherence-0.2.0/PKG-INFO
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: necoherence
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: Revision-aware state transition utilities for Python
|
|
5
|
-
License-Expression: MIT
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Requires-Python: >=3.12
|
|
8
|
-
Provides-Extra: dev
|
|
9
|
-
Requires-Dist: hypothesis; extra == 'dev'
|
|
10
|
-
Requires-Dist: mypy; extra == 'dev'
|
|
11
|
-
Requires-Dist: pytest; extra == 'dev'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|