itf-py 0.1.1__tar.gz → 0.2.0__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.
Potentially problematic release.
This version of itf-py might be problematic. Click here for more details.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: itf-py
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Python library to parse and emit Apalache ITF traces
|
|
5
5
|
Keywords: itf,trace,parser,tlaplus,apalache,quint
|
|
6
6
|
Author: Igor Konnov
|
|
@@ -9,6 +9,8 @@ Requires-Python: >=3.12,<4.0
|
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.12
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Requires-Dist: frozendict (>=2.4.6,<3.0.0)
|
|
13
|
+
Requires-Dist: frozenlist (>=1.7.0,<2.0.0)
|
|
12
14
|
Project-URL: Homepage, https://github.com/konnov/itf-py
|
|
13
15
|
Description-Content-Type: text/markdown
|
|
14
16
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "itf-py"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "Python library to parse and emit Apalache ITF traces"
|
|
5
5
|
homepage = "https://github.com/konnov/itf-py"
|
|
6
6
|
authors = ["Igor Konnov <igor@konnov.phd>"]
|
|
@@ -10,6 +10,8 @@ packages = [{include = "itf_py", from = "src"}]
|
|
|
10
10
|
|
|
11
11
|
[tool.poetry.dependencies]
|
|
12
12
|
python = "^3.12"
|
|
13
|
+
frozendict = "^2.4.6"
|
|
14
|
+
frozenlist = "^1.7.0"
|
|
13
15
|
|
|
14
16
|
[tool.poetry.group.dev.dependencies]
|
|
15
17
|
pytest = "^8.0.0"
|
|
@@ -18,6 +20,7 @@ black = "^24.0.0"
|
|
|
18
20
|
isort = "^5.13.0"
|
|
19
21
|
flake8 = "^7.0.0"
|
|
20
22
|
mypy = "^1.8.0"
|
|
23
|
+
markdown-pytest = "^0.3.2"
|
|
21
24
|
|
|
22
25
|
|
|
23
26
|
[build-system]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Python library to parse and emit Apalache ITF traces.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .itf import ITFState
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
8
|
+
__all__ = [
|
|
9
|
+
"ITFState",
|
|
10
|
+
"ITFTrace",
|
|
11
|
+
"value_to_json",
|
|
12
|
+
"value_from_json",
|
|
13
|
+
"state_to_json",
|
|
14
|
+
"state_from_json",
|
|
15
|
+
"trace_to_json",
|
|
16
|
+
"trace_from_json",
|
|
17
|
+
]
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
from collections import namedtuple
|
|
1
2
|
from dataclasses import dataclass
|
|
2
|
-
from types import SimpleNamespace
|
|
3
3
|
from typing import Any, Dict, List, Optional
|
|
4
4
|
|
|
5
|
+
from frozendict import frozendict
|
|
6
|
+
from frozenlist import FrozenList
|
|
7
|
+
|
|
5
8
|
|
|
6
9
|
@dataclass
|
|
7
10
|
class ITFState:
|
|
@@ -39,13 +42,17 @@ def value_from_json(val: Any) -> Any:
|
|
|
39
42
|
elif "#set" in val:
|
|
40
43
|
return frozenset(value_from_json(v) for v in val["#set"])
|
|
41
44
|
elif "#map" in val:
|
|
42
|
-
|
|
45
|
+
d = {value_from_json(k): value_from_json(v) for (k, v) in val["#map"]}
|
|
46
|
+
return frozendict(d) # immutable dictionary
|
|
43
47
|
elif "#unserializable" in val:
|
|
44
48
|
return ITFUnserializable(value=val["#unserializable"])
|
|
45
49
|
else:
|
|
46
|
-
|
|
50
|
+
tup_type = namedtuple("ITFRecord", val.keys()) # type: ignore
|
|
51
|
+
return tup_type(**{k: value_from_json(v) for k, v in val.items()})
|
|
47
52
|
elif isinstance(val, list):
|
|
48
|
-
|
|
53
|
+
lst = FrozenList([value_from_json(v) for v in val])
|
|
54
|
+
lst.freeze() # make it immutable
|
|
55
|
+
return lst
|
|
49
56
|
else:
|
|
50
57
|
return val # int, str, bool
|
|
51
58
|
|
|
@@ -56,16 +63,19 @@ def value_to_json(val: Any) -> Any:
|
|
|
56
63
|
return val
|
|
57
64
|
elif isinstance(val, int):
|
|
58
65
|
return {"#bigint": str(val)}
|
|
59
|
-
elif isinstance(val, tuple):
|
|
66
|
+
elif isinstance(val, tuple) and not hasattr(val, "_fields"):
|
|
60
67
|
return {"#tup": [value_to_json(v) for v in val]}
|
|
61
68
|
elif isinstance(val, frozenset):
|
|
62
69
|
return {"#set": [value_to_json(v) for v in val]}
|
|
63
70
|
elif isinstance(val, dict):
|
|
64
71
|
return {"#map": [[value_to_json(k), value_to_json(v)] for k, v in val.items()]}
|
|
65
|
-
elif isinstance(val, list):
|
|
72
|
+
elif isinstance(val, list) or isinstance(val, FrozenList):
|
|
66
73
|
return [value_to_json(v) for v in val]
|
|
67
74
|
elif hasattr(val, "__dict__"):
|
|
68
75
|
return {k: value_to_json(v) for k, v in val.__dict__.items()}
|
|
76
|
+
elif isinstance(val, tuple) and hasattr(val, "_fields"):
|
|
77
|
+
# namedtuple
|
|
78
|
+
return {k: value_to_json(v) for k, v in val._asdict().items()} # type: ignore
|
|
69
79
|
elif isinstance(val, str):
|
|
70
80
|
return val
|
|
71
81
|
else:
|
|
File without changes
|