scjson 0.3.6__tar.gz → 0.4.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.
Files changed (83) hide show
  1. {scjson-0.3.6/scjson.egg-info → scjson-0.4.0}/PKG-INFO +25 -7
  2. {scjson-0.3.6 → scjson-0.4.0}/README.md +24 -6
  3. {scjson-0.3.6 → scjson-0.4.0}/pyproject.toml +1 -1
  4. {scjson-0.3.6 → scjson-0.4.0}/scjson/SCXMLDocumentHandler.py +59 -4
  5. {scjson-0.3.6 → scjson-0.4.0}/scjson/cli.py +14 -2
  6. scjson-0.4.0/scjson/comment_promotion.py +853 -0
  7. {scjson-0.3.6 → scjson-0.4.0}/scjson/context.py +9 -1
  8. {scjson-0.3.6 → scjson-0.4.0}/scjson/dataclasses/generated.py +78 -0
  9. {scjson-0.3.6 → scjson-0.4.0}/scjson/dataclasses_strict/generated.py +78 -0
  10. {scjson-0.3.6 → scjson-0.4.0}/scjson/jinja_gen.py +34 -1
  11. {scjson-0.3.6 → scjson-0.4.0}/scjson/pydantic/generated.py +116 -28
  12. {scjson-0.3.6 → scjson-0.4.0}/scjson/pydantic_strict/generated.py +116 -28
  13. {scjson-0.3.6 → scjson-0.4.0/scjson.egg-info}/PKG-INFO +25 -7
  14. {scjson-0.3.6 → scjson-0.4.0}/scjson.egg-info/SOURCES.txt +7 -14
  15. {scjson-0.3.6 → scjson-0.4.0}/tests/test_cli.py +13 -3
  16. scjson-0.4.0/tests/test_comment_promotion.py +471 -0
  17. scjson-0.4.0/tests/test_conv_h.py +348 -0
  18. scjson-0.4.0/tests/test_engine_root_activation.py +51 -0
  19. {scjson-0.3.6 → scjson-0.4.0}/tests/test_exec_compare_advanced.py +35 -47
  20. scjson-0.4.0/tests/test_help_text_round_trip.py +386 -0
  21. scjson-0.4.0/tests/test_other_attributes_metadata.py +61 -0
  22. scjson-0.4.0/tests/test_uber_conv_corpus.py +112 -0
  23. scjson-0.3.6/tests/__pycache__/test_cli.cpython-311-pytest-8.4.1.pyc +0 -0
  24. scjson-0.3.6/tests/__pycache__/test_engine.cpython-311-pytest-8.4.1.pyc +0 -0
  25. scjson-0.3.6/tests/__pycache__/test_engine_cli.cpython-311-pytest-8.4.1.pyc +0 -0
  26. scjson-0.3.6/tests/__pycache__/test_exec_compare_advanced.cpython-311-pytest-8.4.1.pyc +0 -0
  27. scjson-0.3.6/tests/__pycache__/test_exec_compare_integration.cpython-311-pytest-8.4.1.pyc +0 -0
  28. scjson-0.3.6/tests/__pycache__/test_exec_sweep_corpus.cpython-311-pytest-8.4.1.pyc +0 -0
  29. scjson-0.3.6/tests/__pycache__/test_exec_sweep_integration.cpython-311-pytest-8.4.1.pyc +0 -0
  30. scjson-0.3.6/tests/__pycache__/test_json_stream.cpython-311-pytest-8.4.1.pyc +0 -0
  31. scjson-0.3.6/tests/__pycache__/test_safe_eval.cpython-311-pytest-8.4.1.pyc +0 -0
  32. scjson-0.3.6/tests/__pycache__/test_vector_analyzer.cpython-311-pytest-8.4.1.pyc +0 -0
  33. scjson-0.3.6/tests/__pycache__/test_vector_coverage.cpython-311-pytest-8.4.1.pyc +0 -0
  34. scjson-0.3.6/tests/__pycache__/test_vector_gen.cpython-311-pytest-8.4.1.pyc +0 -0
  35. scjson-0.3.6/tests/__pycache__/test_vector_invoke.cpython-311-pytest-8.4.1.pyc +0 -0
  36. scjson-0.3.6/tests/__pycache__/test_vector_search.cpython-311-pytest-8.4.1.pyc +0 -0
  37. {scjson-0.3.6 → scjson-0.4.0}/LEGAL.md +0 -0
  38. {scjson-0.3.6 → scjson-0.4.0}/LICENSE +0 -0
  39. {scjson-0.3.6 → scjson-0.4.0}/MANIFEST.in +0 -0
  40. {scjson-0.3.6 → scjson-0.4.0}/exec_compare.py +0 -0
  41. {scjson-0.3.6 → scjson-0.4.0}/exec_sweep.py +0 -0
  42. {scjson-0.3.6 → scjson-0.4.0}/scjson/CaseStyle.py +0 -0
  43. {scjson-0.3.6 → scjson-0.4.0}/scjson/__init__.py +0 -0
  44. {scjson-0.3.6 → scjson-0.4.0}/scjson/__main__.py +0 -0
  45. {scjson-0.3.6 → scjson-0.4.0}/scjson/activation.py +0 -0
  46. {scjson-0.3.6 → scjson-0.4.0}/scjson/dataclasses/__init__.py +0 -0
  47. {scjson-0.3.6 → scjson-0.4.0}/scjson/dataclasses_strict/__init__.py +0 -0
  48. {scjson-0.3.6 → scjson-0.4.0}/scjson/engine.py +0 -0
  49. {scjson-0.3.6 → scjson-0.4.0}/scjson/events.py +0 -0
  50. {scjson-0.3.6 → scjson-0.4.0}/scjson/invoke.py +0 -0
  51. {scjson-0.3.6 → scjson-0.4.0}/scjson/json_stream.py +0 -0
  52. {scjson-0.3.6 → scjson-0.4.0}/scjson/pydantic/__init__.py +0 -0
  53. {scjson-0.3.6 → scjson-0.4.0}/scjson/pydantic_strict/__init__.py +0 -0
  54. {scjson-0.3.6 → scjson-0.4.0}/scjson/safe_eval.py +0 -0
  55. {scjson-0.3.6 → scjson-0.4.0}/scjson/templates/base.rb.jinja2 +0 -0
  56. {scjson-0.3.6 → scjson-0.4.0}/scjson/templates/base.rs.jinja2 +0 -0
  57. {scjson-0.3.6 → scjson-0.4.0}/scjson/templates/base.swift.jinja2 +0 -0
  58. {scjson-0.3.6 → scjson-0.4.0}/scjson/templates/base.ts.jinja2 +0 -0
  59. {scjson-0.3.6 → scjson-0.4.0}/scjson/templates/scjson_props.rb.jinja2 +0 -0
  60. {scjson-0.3.6 → scjson-0.4.0}/scjson/templates/scjson_props.rs.jinja2 +0 -0
  61. {scjson-0.3.6 → scjson-0.4.0}/scjson/templates/scjson_props.swift.jinja2 +0 -0
  62. {scjson-0.3.6 → scjson-0.4.0}/scjson/templates/scjson_props.ts.jinja2 +0 -0
  63. {scjson-0.3.6 → scjson-0.4.0}/scjson.egg-info/dependency_links.txt +0 -0
  64. {scjson-0.3.6 → scjson-0.4.0}/scjson.egg-info/entry_points.txt +0 -0
  65. {scjson-0.3.6 → scjson-0.4.0}/scjson.egg-info/requires.txt +0 -0
  66. {scjson-0.3.6 → scjson-0.4.0}/scjson.egg-info/top_level.txt +0 -0
  67. {scjson-0.3.6 → scjson-0.4.0}/setup.cfg +0 -0
  68. {scjson-0.3.6 → scjson-0.4.0}/tests/test_engine.py +0 -0
  69. {scjson-0.3.6 → scjson-0.4.0}/tests/test_engine_cli.py +0 -0
  70. {scjson-0.3.6 → scjson-0.4.0}/tests/test_exec_compare_integration.py +0 -0
  71. {scjson-0.3.6 → scjson-0.4.0}/tests/test_exec_sweep_corpus.py +0 -0
  72. {scjson-0.3.6 → scjson-0.4.0}/tests/test_exec_sweep_integration.py +0 -0
  73. {scjson-0.3.6 → scjson-0.4.0}/tests/test_json_stream.py +0 -0
  74. {scjson-0.3.6 → scjson-0.4.0}/tests/test_safe_eval.py +0 -0
  75. {scjson-0.3.6 → scjson-0.4.0}/tests/test_vector_analyzer.py +0 -0
  76. {scjson-0.3.6 → scjson-0.4.0}/tests/test_vector_coverage.py +0 -0
  77. {scjson-0.3.6 → scjson-0.4.0}/tests/test_vector_gen.py +0 -0
  78. {scjson-0.3.6 → scjson-0.4.0}/tests/test_vector_invoke.py +0 -0
  79. {scjson-0.3.6 → scjson-0.4.0}/tests/test_vector_search.py +0 -0
  80. {scjson-0.3.6 → scjson-0.4.0}/vector_gen.py +0 -0
  81. {scjson-0.3.6 → scjson-0.4.0}/vector_lib/analyzer.py +0 -0
  82. {scjson-0.3.6 → scjson-0.4.0}/vector_lib/coverage.py +0 -0
  83. {scjson-0.3.6 → scjson-0.4.0}/vector_lib/search.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scjson
3
- Version: 0.3.6
3
+ Version: 0.4.0
4
4
  Summary: A JSON-based serialization of SCXML (State Chart XML) for modern tooling, interoperability, and education, with execution engine and trace tools for SCXML/SCML.
5
5
  Author-email: Ira Abbott <ira@mycloud.blue>
6
6
  License-Expression: BSD-1-Clause
@@ -23,10 +23,16 @@ Dynamic: license-file
23
23
 
24
24
  This directory contains the Python implementation of **scjson**, a format for representing SCXML state machines in JSON. The package provides a command line interface and utility functions to convert between `.scxml` and `.scjson` files and to validate documents against the project's schema.
25
25
 
26
- The package includes pydantic and dataclasses types for the associated objects / enums in both standard and strict forms.
26
+ The package includes generated Pydantic and dataclass model variants for the
27
+ schema objects and enumerations in both standard and strict forms.
27
28
 
28
- For details on how SCXML elements are inferred during conversion see [INFERENCE.md](https://github.com/SoftOboros/scjson/blob/main/INFERENCE.md). In python, inference for conversion is handled by the
29
- dataclasses models. See below.
29
+ For current SCJSON representation and converter authority, see the semantic
30
+ baseline and converter concepts docs:
31
+ [SCJSON-00-CONCEPTS.md](https://github.com/SoftOboros/scjson/blob/main/docs/concepts/SCJSON-00-CONCEPTS.md)
32
+ and
33
+ [SCJSON-CONV-00-CONCEPTS.md](https://github.com/SoftOboros/scjson/blob/main/docs/concepts/SCJSON-CONV-00-CONCEPTS.md).
34
+ For language status and parity notes, see
35
+ [docs/COMPATIBILITY.md](https://github.com/SoftOboros/scjson/blob/main/docs/COMPATIBILITY.md).
30
36
 
31
37
  ## Installation
32
38
 
@@ -183,7 +189,9 @@ python py/uber_test.py -l swift -s "Examples/Qt/StopWatch/*.scxml" --consensus-w
183
189
 
184
190
  - `-s/--subset` filters SCXML files by a glob relative to `tutorial/`.
185
191
  - `--consensus-warn` downgrades mismatches to warnings when reference languages (Python/JavaScript/Rust) match the canonical structure.
186
- - The harness normalizes structural differences (see INFERENCE.md) to produce actionable diffs and prints a triage line with a recommendation.
192
+ - The harness normalizes structural differences according to the active
193
+ converter and compatibility docs to produce actionable diffs and prints a
194
+ triage line with a recommendation.
187
195
 
188
196
  ## Model Variants
189
197
 
@@ -211,13 +219,23 @@ shown below mirror those defined in the SCJSON schema.
211
219
 
212
220
  Several generated classes share generic helper fields:
213
221
 
214
- - `other_attributes`: `dict[str, str]` capturing additional XML attributes from
215
- foreign namespaces.
222
+ - `other_attributes`: extension attributes from foreign namespaces. Pydantic
223
+ model variants use `dict[str, Any]` so JSON tooling can preserve typed
224
+ metadata; dataclass variants intentionally use `dict[str, str]` for XML
225
+ serialization.
216
226
  - `other_element`: `list[object]` allowing untyped child nodes from other
217
227
  namespaces to be preserved.
218
228
  - `content`: `list[object]` used when elements permit mixed or wildcard
219
229
  content.
220
230
 
231
+ ## Model Generation Maintenance
232
+
233
+ The checked-in generated models are refreshed from the repository checkout with
234
+ `py/gen_models.sh`, which applies `py/patch_scxml_forward_ref.py` and
235
+ `py/patch_other_attributes_any.py` after generation. These scripts are
236
+ repository maintenance tools, not installed runtime commands or Python package
237
+ entry points.
238
+
221
239
  ### `scjson.dataclasses`
222
240
 
223
241
  Plain Python dataclasses without runtime validation.
@@ -4,10 +4,16 @@
4
4
 
5
5
  This directory contains the Python implementation of **scjson**, a format for representing SCXML state machines in JSON. The package provides a command line interface and utility functions to convert between `.scxml` and `.scjson` files and to validate documents against the project's schema.
6
6
 
7
- The package includes pydantic and dataclasses types for the associated objects / enums in both standard and strict forms.
7
+ The package includes generated Pydantic and dataclass model variants for the
8
+ schema objects and enumerations in both standard and strict forms.
8
9
 
9
- For details on how SCXML elements are inferred during conversion see [INFERENCE.md](https://github.com/SoftOboros/scjson/blob/main/INFERENCE.md). In python, inference for conversion is handled by the
10
- dataclasses models. See below.
10
+ For current SCJSON representation and converter authority, see the semantic
11
+ baseline and converter concepts docs:
12
+ [SCJSON-00-CONCEPTS.md](https://github.com/SoftOboros/scjson/blob/main/docs/concepts/SCJSON-00-CONCEPTS.md)
13
+ and
14
+ [SCJSON-CONV-00-CONCEPTS.md](https://github.com/SoftOboros/scjson/blob/main/docs/concepts/SCJSON-CONV-00-CONCEPTS.md).
15
+ For language status and parity notes, see
16
+ [docs/COMPATIBILITY.md](https://github.com/SoftOboros/scjson/blob/main/docs/COMPATIBILITY.md).
11
17
 
12
18
  ## Installation
13
19
 
@@ -164,7 +170,9 @@ python py/uber_test.py -l swift -s "Examples/Qt/StopWatch/*.scxml" --consensus-w
164
170
 
165
171
  - `-s/--subset` filters SCXML files by a glob relative to `tutorial/`.
166
172
  - `--consensus-warn` downgrades mismatches to warnings when reference languages (Python/JavaScript/Rust) match the canonical structure.
167
- - The harness normalizes structural differences (see INFERENCE.md) to produce actionable diffs and prints a triage line with a recommendation.
173
+ - The harness normalizes structural differences according to the active
174
+ converter and compatibility docs to produce actionable diffs and prints a
175
+ triage line with a recommendation.
168
176
 
169
177
  ## Model Variants
170
178
 
@@ -192,13 +200,23 @@ shown below mirror those defined in the SCJSON schema.
192
200
 
193
201
  Several generated classes share generic helper fields:
194
202
 
195
- - `other_attributes`: `dict[str, str]` capturing additional XML attributes from
196
- foreign namespaces.
203
+ - `other_attributes`: extension attributes from foreign namespaces. Pydantic
204
+ model variants use `dict[str, Any]` so JSON tooling can preserve typed
205
+ metadata; dataclass variants intentionally use `dict[str, str]` for XML
206
+ serialization.
197
207
  - `other_element`: `list[object]` allowing untyped child nodes from other
198
208
  namespaces to be preserved.
199
209
  - `content`: `list[object]` used when elements permit mixed or wildcard
200
210
  content.
201
211
 
212
+ ## Model Generation Maintenance
213
+
214
+ The checked-in generated models are refreshed from the repository checkout with
215
+ `py/gen_models.sh`, which applies `py/patch_scxml_forward_ref.py` and
216
+ `py/patch_other_attributes_any.py` after generation. These scripts are
217
+ repository maintenance tools, not installed runtime commands or Python package
218
+ entry points.
219
+
202
220
  ### `scjson.dataclasses`
203
221
 
204
222
  Plain Python dataclasses without runtime validation.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "scjson"
3
- version = "0.3.6"
3
+ version = "0.4.0"
4
4
  description = "A JSON-based serialization of SCXML (State Chart XML) for modern tooling, interoperability, and education, with execution engine and trace tools for SCXML/SCML."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.8"
@@ -27,6 +27,12 @@ from xsdata.formats.dataclass.models.generics import AnyElement
27
27
  from . import dataclasses as dataclasses_module
28
28
  from .dataclasses import Scxml as Scxml
29
29
  from xml.etree import ElementTree as ET
30
+ from xml.etree import ElementInclude
31
+ from .comment_promotion import (
32
+ attach_help_text_to_model,
33
+ extract_help_text_from_xml,
34
+ inject_help_text_comments_into_xml,
35
+ )
30
36
 
31
37
  class SCXMLDocumentHandler:
32
38
  def __init__(
@@ -36,6 +42,8 @@ class SCXMLDocumentHandler:
36
42
  pretty: bool = True,
37
43
  omit_empty: bool = True,
38
44
  fail_on_unknown_properties: bool = True,
45
+ xinclude: str = "preserve",
46
+ xinclude_base_url: Optional[str] = None,
39
47
  ) -> None:
40
48
  """Create a new document handler.
41
49
 
@@ -52,6 +60,13 @@ class SCXMLDocumentHandler:
52
60
  fail_on_unknown_properties: bool, optional
53
61
  When ``True`` (default) unexpected XML elements raise an exception
54
62
  during parsing. Set ``False`` to ignore them.
63
+ xinclude: str, optional
64
+ ``"preserve"`` keeps unresolved ``xi:include`` extension elements
65
+ in ``other_element``. ``"resolve"`` applies XML XInclude before
66
+ model parsing.
67
+ xinclude_base_url: str | None, optional
68
+ Base URL or source file path used to resolve relative XInclude
69
+ ``href`` values when ``xinclude`` is ``"resolve"``.
55
70
 
56
71
  Returns
57
72
  -------
@@ -69,6 +84,10 @@ class SCXMLDocumentHandler:
69
84
  )
70
85
  self.schema = xmlschema.XMLSchema(schema_path) if schema_path else None
71
86
  self.omit_empty = omit_empty
87
+ if xinclude not in {"preserve", "resolve"}:
88
+ raise ValueError("xinclude must be 'preserve' or 'resolve'")
89
+ self.xinclude = xinclude
90
+ self.xinclude_base_url = xinclude_base_url
72
91
 
73
92
  @staticmethod
74
93
  def _resolve(cls: type) -> type:
@@ -126,13 +145,32 @@ class SCXMLDocumentHandler:
126
145
  ]
127
146
  return obj
128
147
 
129
- def xml_to_json(self, xml_str: str) -> str:
148
+ def xml_to_json(
149
+ self,
150
+ xml_str: str,
151
+ *,
152
+ xinclude: Optional[str] = None,
153
+ xinclude_base_url: Optional[str] = None,
154
+ ) -> str:
130
155
  """Convert SCXML string to canonical JSON.
131
156
 
132
157
  This method tolerates documents that omit the default SCXML namespace by
133
158
  inserting it prior to parsing. Such files are technically invalid but
134
159
  appear in the W3C test suite.
160
+
161
+ CONV-F: an SCXML comment-promotion pre-pass runs before namespace
162
+ insertion so element addresses stay stable across the mutation. The
163
+ pre-pass strips comments from the XML; the resulting model receives
164
+ ``help_text`` entries via :func:`attach_help_text_to_model`.
135
165
  """
166
+ xinclude_mode = self.xinclude if xinclude is None else xinclude
167
+ if xinclude_mode not in {"preserve", "resolve"}:
168
+ raise ValueError("xinclude must be 'preserve' or 'resolve'")
169
+ # CONV-F pre-pass: extract comments and rewrite ``xml_str`` to be
170
+ # comment-free. We do this BEFORE default-namespace insertion so the
171
+ # local-name-based addresses we compute aren't affected by namespace
172
+ # rewriting.
173
+ xml_str, address_help = extract_help_text_from_xml(xml_str)
136
174
  try:
137
175
  root = ET.fromstring(xml_str)
138
176
  except Exception:
@@ -141,7 +179,17 @@ class SCXMLDocumentHandler:
141
179
  if root is not None and root.tag == "scxml" and "xmlns" not in root.attrib:
142
180
  root.attrib["xmlns"] = "http://www.w3.org/2005/07/scxml"
143
181
  xml_str = ET.tostring(root, encoding="unicode")
182
+ if xinclude_mode == "resolve" and root is not None:
183
+ base_url = (
184
+ xinclude_base_url
185
+ if xinclude_base_url is not None
186
+ else self.xinclude_base_url
187
+ )
188
+ ElementInclude.include(root, base_url=base_url)
189
+ xml_str = ET.tostring(root, encoding="unicode")
144
190
  model = self.parser.from_string(xml_str, self.model_class)
191
+ # Attach help_text to the model nodes addressed by the pre-pass.
192
+ attach_help_text_to_model(model, address_help)
145
193
  if hasattr(model, "model_dump"):
146
194
  data = model.model_dump()
147
195
  else:
@@ -232,11 +280,18 @@ class SCXMLDocumentHandler:
232
280
  return data
233
281
 
234
282
  def json_to_xml(self, json_str: str) -> str:
235
- """Convert stored JSON string to SCXML."""
283
+ """Convert stored JSON string to SCXML.
284
+
285
+ CONV-F: after xsdata serializes the model, any non-empty
286
+ ``help_text`` entries are re-emitted as leading XML comments via
287
+ :func:`inject_help_text_comments_into_xml`. ``help_text`` itself
288
+ carries xsdata metadata ``{"type": "Ignore"}`` and is therefore not
289
+ serialized by xsdata directly.
290
+ """
236
291
  data = json.loads(json_str)
237
292
  if hasattr(self.model_class, "model_validate"):
238
293
  model = self.model_class.model_validate(data)
239
294
  else:
240
295
  model = self._to_dataclass(self.model_class, data)
241
- return self.to_string(model)
242
-
296
+ xml_str = self.to_string(model)
297
+ return inject_help_text_comments_into_xml(xml_str, model)
@@ -116,6 +116,13 @@ def xml(path: Path, output: Path | None, recursive: bool, verify: bool, keep_emp
116
116
  default=True,
117
117
  help="Fail on unknown XML elements when converting",
118
118
  )
119
+ @click.option(
120
+ "--xinclude",
121
+ type=click.Choice(["preserve", "resolve"]),
122
+ default="preserve",
123
+ show_default=True,
124
+ help="Preserve xi:include directives or resolve them before conversion",
125
+ )
119
126
  def json(
120
127
  path: Path,
121
128
  output: Path | None,
@@ -123,15 +130,20 @@ def json(
123
130
  verify: bool,
124
131
  keep_empty: bool,
125
132
  fail_unknown: bool,
133
+ xinclude: str,
126
134
  ):
127
135
  """Convert a single SCXML file or all SCXML files in a directory."""
128
- handler = SCXMLDocumentHandler(omit_empty=not keep_empty, fail_on_unknown_properties=fail_unknown)
136
+ handler = SCXMLDocumentHandler(
137
+ omit_empty=not keep_empty,
138
+ fail_on_unknown_properties=fail_unknown,
139
+ xinclude=xinclude,
140
+ )
129
141
 
130
142
  def convert_file(src: Path, dest: Path | None):
131
143
  try:
132
144
  with open(src, "r", encoding="utf-8") as f:
133
145
  xml_str = f.read()
134
- json_str = handler.xml_to_json(xml_str)
146
+ json_str = handler.xml_to_json(xml_str, xinclude_base_url=str(src))
135
147
  if verify:
136
148
  handler.json_to_xml(json_str)
137
149
  click.echo(f"Verified {src}")