scjson 0.4.2__tar.gz → 0.4.3__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 (100) hide show
  1. {scjson-0.4.2/scjson.egg-info → scjson-0.4.3}/PKG-INFO +20 -15
  2. {scjson-0.4.2 → scjson-0.4.3}/README.md +15 -11
  3. {scjson-0.4.2 → scjson-0.4.3}/exec_compare.py +34 -45
  4. {scjson-0.4.2 → scjson-0.4.3}/exec_sweep.py +25 -119
  5. {scjson-0.4.2 → scjson-0.4.3}/pyproject.toml +7 -6
  6. scjson-0.4.3/scion_support.py +112 -0
  7. {scjson-0.4.2 → scjson-0.4.3}/scjson/SCXMLDocumentHandler.py +91 -12
  8. {scjson-0.4.2 → scjson-0.4.3}/scjson/cli.py +35 -16
  9. {scjson-0.4.2 → scjson-0.4.3}/scjson/comment_promotion.py +21 -6
  10. {scjson-0.4.2 → scjson-0.4.3}/scjson/context.py +365 -410
  11. {scjson-0.4.2/scjson/dataclasses_strict → scjson-0.4.3/scjson/dataclasses}/generated.py +38 -9
  12. {scjson-0.4.2/scjson/dataclasses → scjson-0.4.3/scjson/dataclasses_strict}/generated.py +45 -2
  13. scjson-0.4.3/scjson/ecmascript_array.py +104 -0
  14. {scjson-0.4.2 → scjson-0.4.3}/scjson/ecmascript_normalizer.py +55 -33
  15. {scjson-0.4.2 → scjson-0.4.3}/scjson/events.py +10 -0
  16. {scjson-0.4.2 → scjson-0.4.3}/scjson/exec_ir.py +287 -234
  17. scjson-0.4.3/scjson/executable_keys.py +68 -0
  18. scjson-0.4.3/scjson/execution_order.py +289 -0
  19. scjson-0.4.3/scjson/inline_data.py +28 -0
  20. {scjson-0.4.2 → scjson-0.4.3}/scjson/jinja_gen.py +19 -2
  21. {scjson-0.4.2 → scjson-0.4.3}/scjson/pydantic/generated.py +193 -30
  22. {scjson-0.4.2 → scjson-0.4.3}/scjson/pydantic_strict/generated.py +193 -30
  23. scjson-0.4.3/scjson/state_tree.py +46 -0
  24. {scjson-0.4.2 → scjson-0.4.3}/scjson/templates/scjson_props.rb.jinja2 +5 -4
  25. {scjson-0.4.2 → scjson-0.4.3}/scjson/templates/scjson_props.rs.jinja2 +3 -3
  26. {scjson-0.4.2 → scjson-0.4.3}/scjson/templates/scjson_props.swift.jinja2 +18 -3
  27. {scjson-0.4.2 → scjson-0.4.3}/scjson/templates/scjson_props.ts.jinja2 +5 -3
  28. scjson-0.4.3/scjson/xml_payload.py +37 -0
  29. {scjson-0.4.2 → scjson-0.4.3/scjson.egg-info}/PKG-INFO +20 -15
  30. {scjson-0.4.2 → scjson-0.4.3}/scjson.egg-info/SOURCES.txt +24 -0
  31. {scjson-0.4.2 → scjson-0.4.3}/scjson.egg-info/requires.txt +3 -2
  32. {scjson-0.4.2 → scjson-0.4.3}/scjson.egg-info/top_level.txt +2 -0
  33. scjson-0.4.3/scjson_argv.py +53 -0
  34. scjson-0.4.3/tests/fixtures/compound_initial.scxml +34 -0
  35. scjson-0.4.3/tests/fixtures/parallel_region_order.scxml +45 -0
  36. scjson-0.4.3/tests/test_action_errors.py +137 -0
  37. {scjson-0.4.2 → scjson-0.4.3}/tests/test_cli.py +5 -5
  38. {scjson-0.4.2 → scjson-0.4.3}/tests/test_conv_h.py +4 -1
  39. scjson-0.4.3/tests/test_ecmascript_concat.py +68 -0
  40. {scjson-0.4.2 → scjson-0.4.3}/tests/test_ecmascript_normalizer.py +39 -0
  41. {scjson-0.4.2 → scjson-0.4.3}/tests/test_engine.py +101 -1
  42. {scjson-0.4.2 → scjson-0.4.3}/tests/test_engine_cli.py +4 -0
  43. {scjson-0.4.2 → scjson-0.4.3}/tests/test_exec_compare_advanced.py +6 -5
  44. {scjson-0.4.2 → scjson-0.4.3}/tests/test_exec_compare_integration.py +4 -2
  45. {scjson-0.4.2 → scjson-0.4.3}/tests/test_exec_ir.py +120 -74
  46. scjson-0.4.3/tests/test_exec_sweep_corpus.py +90 -0
  47. {scjson-0.4.2 → scjson-0.4.3}/tests/test_exec_sweep_integration.py +41 -1
  48. scjson-0.4.3/tests/test_executable_keys.py +126 -0
  49. scjson-0.4.3/tests/test_execution_order.py +243 -0
  50. scjson-0.4.3/tests/test_initial_state_order.py +137 -0
  51. scjson-0.4.3/tests/test_mixed_payload.py +145 -0
  52. scjson-0.4.3/tests/test_parallel_exit_order.py +66 -0
  53. scjson-0.4.3/tests/test_parallel_region_order.py +160 -0
  54. scjson-0.4.3/tests/test_platform_paths.py +64 -0
  55. scjson-0.4.3/tests/test_processor_location.py +73 -0
  56. scjson-0.4.3/tests/test_region_execution.py +102 -0
  57. scjson-0.4.3/tests/test_ruby_trace_parity.py +46 -0
  58. {scjson-0.4.2 → scjson-0.4.3}/tests/test_safe_eval.py +4 -3
  59. scjson-0.4.3/tests/test_state_membership.py +199 -0
  60. scjson-0.4.3/tests/test_state_order_interchange.py +151 -0
  61. {scjson-0.4.2 → scjson-0.4.3}/tests/test_uber_conv_corpus.py +51 -1
  62. {scjson-0.4.2 → scjson-0.4.3}/tests/test_vector_gen.py +74 -2
  63. {scjson-0.4.2 → scjson-0.4.3}/vector_gen.py +24 -23
  64. {scjson-0.4.2 → scjson-0.4.3}/vector_lib/analyzer.py +7 -6
  65. scjson-0.4.2/tests/test_exec_sweep_corpus.py +0 -57
  66. {scjson-0.4.2 → scjson-0.4.3}/LEGAL.md +0 -0
  67. {scjson-0.4.2 → scjson-0.4.3}/LICENSE +0 -0
  68. {scjson-0.4.2 → scjson-0.4.3}/MANIFEST.in +0 -0
  69. {scjson-0.4.2 → scjson-0.4.3}/scjson/CaseStyle.py +0 -0
  70. {scjson-0.4.2 → scjson-0.4.3}/scjson/__init__.py +0 -0
  71. {scjson-0.4.2 → scjson-0.4.3}/scjson/__main__.py +0 -0
  72. {scjson-0.4.2 → scjson-0.4.3}/scjson/activation.py +0 -0
  73. {scjson-0.4.2 → scjson-0.4.3}/scjson/dataclasses/__init__.py +0 -0
  74. {scjson-0.4.2 → scjson-0.4.3}/scjson/dataclasses_strict/__init__.py +0 -0
  75. {scjson-0.4.2 → scjson-0.4.3}/scjson/engine.py +0 -0
  76. {scjson-0.4.2 → scjson-0.4.3}/scjson/invoke.py +0 -0
  77. {scjson-0.4.2 → scjson-0.4.3}/scjson/json_stream.py +0 -0
  78. {scjson-0.4.2 → scjson-0.4.3}/scjson/pydantic/__init__.py +0 -0
  79. {scjson-0.4.2 → scjson-0.4.3}/scjson/pydantic_strict/__init__.py +0 -0
  80. {scjson-0.4.2 → scjson-0.4.3}/scjson/safe_eval.py +0 -0
  81. {scjson-0.4.2 → scjson-0.4.3}/scjson/templates/base.rb.jinja2 +0 -0
  82. {scjson-0.4.2 → scjson-0.4.3}/scjson/templates/base.rs.jinja2 +0 -0
  83. {scjson-0.4.2 → scjson-0.4.3}/scjson/templates/base.swift.jinja2 +0 -0
  84. {scjson-0.4.2 → scjson-0.4.3}/scjson/templates/base.ts.jinja2 +0 -0
  85. {scjson-0.4.2 → scjson-0.4.3}/scjson.egg-info/dependency_links.txt +0 -0
  86. {scjson-0.4.2 → scjson-0.4.3}/scjson.egg-info/entry_points.txt +0 -0
  87. {scjson-0.4.2 → scjson-0.4.3}/setup.cfg +0 -0
  88. {scjson-0.4.2 → scjson-0.4.3}/tests/fixtures/ecmascript_simple.scxml +0 -0
  89. {scjson-0.4.2 → scjson-0.4.3}/tests/test_comment_promotion.py +0 -0
  90. {scjson-0.4.2 → scjson-0.4.3}/tests/test_ecmascript_engine.py +0 -0
  91. {scjson-0.4.2 → scjson-0.4.3}/tests/test_engine_root_activation.py +0 -0
  92. {scjson-0.4.2 → scjson-0.4.3}/tests/test_help_text_round_trip.py +0 -0
  93. {scjson-0.4.2 → scjson-0.4.3}/tests/test_json_stream.py +0 -0
  94. {scjson-0.4.2 → scjson-0.4.3}/tests/test_other_attributes_metadata.py +0 -0
  95. {scjson-0.4.2 → scjson-0.4.3}/tests/test_vector_analyzer.py +0 -0
  96. {scjson-0.4.2 → scjson-0.4.3}/tests/test_vector_coverage.py +0 -0
  97. {scjson-0.4.2 → scjson-0.4.3}/tests/test_vector_invoke.py +0 -0
  98. {scjson-0.4.2 → scjson-0.4.3}/tests/test_vector_search.py +0 -0
  99. {scjson-0.4.2 → scjson-0.4.3}/vector_lib/coverage.py +0 -0
  100. {scjson-0.4.2 → scjson-0.4.3}/vector_lib/search.py +0 -0
@@ -1,20 +1,21 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scjson
3
- Version: 0.4.2
3
+ Version: 0.4.3
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
7
- Requires-Python: >=3.8
7
+ Requires-Python: >=3.10
8
8
  Description-Content-Type: text/markdown
9
9
  License-File: LICENSE
10
- Requires-Dist: pydantic
10
+ Requires-Dist: pydantic<3,>=2.6
11
11
  Requires-Dist: lxml
12
12
  Requires-Dist: jsonschema
13
13
  Requires-Dist: click
14
14
  Requires-Dist: py-sandboxed
15
15
  Requires-Dist: jinja2
16
16
  Requires-Dist: xmlschema
17
- Requires-Dist: xsdata
17
+ Requires-Dist: xsdata>=24.5
18
+ Requires-Dist: xsdata-pydantic>=24.5
18
19
  Dynamic: license-file
19
20
 
20
21
  <p align="center"><img src="https://raw.githubusercontent.com/SoftOboros/scjson/main/scjson.png" alt="scjson logo" width="200"/></p>
@@ -36,6 +37,8 @@ For language status and parity notes, see
36
37
 
37
38
  ## Installation
38
39
 
40
+ The Python package requires Python 3.10 or later.
41
+
39
42
  ```bash
40
43
  pip install scjson
41
44
  ```
@@ -68,21 +71,23 @@ Online: https://github.com/SoftOboros/scjson/blob/main/docs/ENGINE-PY.md
68
71
 
69
72
  ## SCION Reference Dependency
70
73
 
71
- Several comparison tests (`py/tests/test_exec_compare_advanced.py`) and the
72
- `exec_compare` tooling invoke the Node-based [SCION](https://www.npmjs.com/package/scion) runner bundled under
73
- `tools/scion-runner`. Node.js must be able to resolve the [SCION](https://www.npmjs.com/package/scion) packages
74
- (`scxml`, `jsdom`, and `regenerator-runtime`) via its module loader. Install
75
- them once before running comparisons:
74
+ To compare the Python engine with SCION from outside a checkout, install the
75
+ matching `scjson` npm package and put its `scjson-scion-trace` executable on
76
+ `PATH`. For a local npm installation, pass its entry point directly:
76
77
 
77
78
  ```bash
78
- cd tools/scion-runner
79
- npm ci # or npm install
79
+ npm install scjson@0.4.3
80
+ scjson-exec-sweep ./charts --reference "node ./node_modules/scjson/dist/harness.js" --generate-vectors --workdir ./traces
80
81
  ```
81
82
 
82
- When running the Python tests or CLI comparisons, ensure `node` can load these
83
- modules (for example by keeping the installation above in place or by adding
84
- their location to `NODE_PATH`). Without the [SCION](https://www.npmjs.com/package/scion) packages, comparisons fall
85
- back to the Python engine.
83
+ In a source checkout, run `npm ci` under `tools/scion-runner` to use the
84
+ repository's SCION script. Both `scjson-exec-compare` and
85
+ `scjson-exec-sweep` accept another reference command through `--reference`
86
+ or `SCJSON_REF_ENGINE_CMD`. The command receives `-I` for the chart,
87
+ `-e` for events, and `-o` for its JSONL trace. XML charts also receive
88
+ `--xml`. An unavailable reference, a missing trace, or a disagreement
89
+ exits unsuccessfully. Select `--reference "python -m scjson.cli engine-trace"`
90
+ explicitly when exercising a Python-only workflow.
86
91
 
87
92
  ## Command Line Usage
88
93
 
@@ -17,6 +17,8 @@ For language status and parity notes, see
17
17
 
18
18
  ## Installation
19
19
 
20
+ The Python package requires Python 3.10 or later.
21
+
20
22
  ```bash
21
23
  pip install scjson
22
24
  ```
@@ -49,21 +51,23 @@ Online: https://github.com/SoftOboros/scjson/blob/main/docs/ENGINE-PY.md
49
51
 
50
52
  ## SCION Reference Dependency
51
53
 
52
- Several comparison tests (`py/tests/test_exec_compare_advanced.py`) and the
53
- `exec_compare` tooling invoke the Node-based [SCION](https://www.npmjs.com/package/scion) runner bundled under
54
- `tools/scion-runner`. Node.js must be able to resolve the [SCION](https://www.npmjs.com/package/scion) packages
55
- (`scxml`, `jsdom`, and `regenerator-runtime`) via its module loader. Install
56
- them once before running comparisons:
54
+ To compare the Python engine with SCION from outside a checkout, install the
55
+ matching `scjson` npm package and put its `scjson-scion-trace` executable on
56
+ `PATH`. For a local npm installation, pass its entry point directly:
57
57
 
58
58
  ```bash
59
- cd tools/scion-runner
60
- npm ci # or npm install
59
+ npm install scjson@0.4.3
60
+ scjson-exec-sweep ./charts --reference "node ./node_modules/scjson/dist/harness.js" --generate-vectors --workdir ./traces
61
61
  ```
62
62
 
63
- When running the Python tests or CLI comparisons, ensure `node` can load these
64
- modules (for example by keeping the installation above in place or by adding
65
- their location to `NODE_PATH`). Without the [SCION](https://www.npmjs.com/package/scion) packages, comparisons fall
66
- back to the Python engine.
63
+ In a source checkout, run `npm ci` under `tools/scion-runner` to use the
64
+ repository's SCION script. Both `scjson-exec-compare` and
65
+ `scjson-exec-sweep` accept another reference command through `--reference`
66
+ or `SCJSON_REF_ENGINE_CMD`. The command receives `-I` for the chart,
67
+ `-e` for events, and `-o` for its JSONL trace. XML charts also receive
68
+ `--xml`. An unavailable reference, a missing trace, or a disagreement
69
+ exits unsuccessfully. Select `--reference "python -m scjson.cli engine-trace"`
70
+ explicitly when exercising a Python-only workflow.
67
71
 
68
72
  ## Command Line Usage
69
73
 
@@ -15,7 +15,8 @@ from __future__ import annotations
15
15
  import argparse
16
16
  import json
17
17
  import os
18
- import shlex
18
+ from scjson_argv import split_command
19
+ from scion_support import reference_command
19
20
  import subprocess
20
21
  import sys
21
22
  from pathlib import Path
@@ -34,10 +35,6 @@ except Exception: # pragma: no cover - fallback when package not importable
34
35
 
35
36
  PYTHON_TRACE_CMD = [sys.executable, "-m", "scjson.cli", "engine-trace"]
36
37
 
37
- _SCION_SCRIPT = (
38
- Path(__file__).resolve().parent.parent / "tools" / "scion-runner" / "scion-trace.cjs"
39
- )
40
-
41
38
 
42
39
  def _default_events_path(chart: Path) -> Path | None:
43
40
  candidate = chart.with_suffix(".events.jsonl")
@@ -106,6 +103,8 @@ def _load_trace(path: Path) -> List[dict]:
106
103
  if not raw:
107
104
  continue
108
105
  lines.append(json.loads(raw))
106
+ if not lines:
107
+ raise SystemExit(f"Engine produced an empty trace: {path}")
109
108
  return lines
110
109
 
111
110
 
@@ -288,26 +287,6 @@ def _diff_steps(py_steps: List[dict], ref_steps: List[dict]) -> Tuple[bool, List
288
287
  return mismatch, notes, (py_len, ref_len, compared, mismatching_keys)
289
288
 
290
289
 
291
- def _default_reference_cmd() -> List[str]:
292
- if _SCION_SCRIPT.exists():
293
- return ["node", str(_SCION_SCRIPT)]
294
- return []
295
-
296
-
297
- def _resolve_reference_cmd(args: argparse.Namespace) -> List[str]:
298
- if args.reference:
299
- return shlex.split(args.reference)
300
- env_cmd = os.environ.get("SCJSON_REF_ENGINE_CMD")
301
- if env_cmd:
302
- return shlex.split(env_cmd)
303
- default = _default_reference_cmd()
304
- if default:
305
- return default
306
- raise SystemExit(
307
- "Reference command not provided. Use --reference, set SCJSON_REF_ENGINE_CMD, or install tools/scion-runner."
308
- )
309
-
310
-
311
290
  def _build_trace_cmd(
312
291
  base: Iterable[str],
313
292
  chart: Path,
@@ -355,6 +334,21 @@ def _run(cmd: List[str], cwd: Path | None = None) -> None:
355
334
  )
356
335
 
357
336
 
337
+ def _command_trace(
338
+ cmd: List[str], chart: Path, events: Path, out: Path, xml: bool,
339
+ flags: Iterable[str] = (),
340
+ ) -> List[dict]:
341
+ # A reused workdir may already contain a successful trace for another run.
342
+ with TemporaryDirectory(dir=out.parent) as directory:
343
+ fresh = Path(directory) / out.name
344
+ _run(_build_trace_cmd(cmd, chart, events, fresh, xml, flags))
345
+ if not fresh.is_file():
346
+ raise SystemExit(f"Engine command did not write {out.name}")
347
+ steps = _load_trace(fresh)
348
+ fresh.replace(out)
349
+ return steps
350
+
351
+
358
352
  def _write_python_trace_inline(
359
353
  chart: Path,
360
354
  events: Path | None,
@@ -369,14 +363,10 @@ def _write_python_trace_inline(
369
363
  out.parent.mkdir(parents=True, exist_ok=True)
370
364
  execution_mode = ExecutionMode.LAX if treat_as_xml else ExecutionMode.STRICT
371
365
  ctx = (
372
- DocumentContext.from_xml_file(chart, execution_mode=execution_mode)
366
+ DocumentContext.from_xml_file(chart, execution_mode=execution_mode, ordering_mode=ordering)
373
367
  if treat_as_xml
374
- else DocumentContext.from_json_file(chart, execution_mode=execution_mode)
368
+ else DocumentContext.from_json_file(chart, execution_mode=execution_mode, ordering_mode=ordering)
375
369
  )
376
- try:
377
- ctx.ordering_mode = (ordering or "tolerant").lower()
378
- except Exception:
379
- pass
380
370
  with out.open("w", encoding="utf-8") as sink:
381
371
  # Step 0 snapshot
382
372
  config = sorted(ctx._filter_states(ctx.configuration), key=ctx._activation_order_key)
@@ -519,7 +509,7 @@ def main() -> None:
519
509
  type=str,
520
510
  choices=["tolerant", "strict", "scion"],
521
511
  default="tolerant",
522
- help="Ordering policy for child→parent emissions (finalize, etc.)",
512
+ help="Ordering policy for child-to-parent emissions (finalize, etc.)",
523
513
  )
524
514
  parser.add_argument(
525
515
  "--norm",
@@ -600,7 +590,7 @@ def main() -> None:
600
590
  args.keep_step0_states = False
601
591
  args.ordering = "scion"
602
592
 
603
- ref_cmd = _resolve_reference_cmd(args)
593
+ ref_cmd = reference_command(args.reference)
604
594
 
605
595
  # If not explicitly specified, auto-set step-0 state normalization when using SCION as reference
606
596
  if args.keep_step0_states is None:
@@ -623,7 +613,7 @@ def main() -> None:
623
613
 
624
614
  # Build python trace command (supports extra flags for size/determinism)
625
615
  py_cmd = (
626
- shlex.split(args.python_cmd) if args.python_cmd else list(PYTHON_TRACE_CMD)
616
+ split_command(args.python_cmd) if args.python_cmd else list(PYTHON_TRACE_CMD)
627
617
  )
628
618
  py_flags: list[str] = []
629
619
  if args.leaf_only:
@@ -645,18 +635,18 @@ def main() -> None:
645
635
  workdir = Path(os.environ["WORKDIR_OVERRIDE"]) # type: ignore
646
636
  workdir.mkdir(parents=True, exist_ok=True)
647
637
  py_trace = workdir / "python.trace.jsonl"
648
- _run(_build_trace_cmd(py_cmd, chart, events, py_trace, treat_as_xml, py_flags))
638
+ py_steps = _command_trace(py_cmd, chart, events, py_trace, treat_as_xml, py_flags)
649
639
  except SystemExit:
640
+ if args.python_cmd:
641
+ raise
650
642
  # Fallback to inline generation when package CLI is unavailable
651
643
  _write_python_trace_inline(chart, events, py_trace, treat_as_xml, ordering=args.ordering)
644
+ py_steps = _load_trace(py_trace)
652
645
  if os.environ.get("WORKDIR_OVERRIDE"):
653
646
  workdir = Path(os.environ["WORKDIR_OVERRIDE"]) # type: ignore
654
647
  workdir.mkdir(parents=True, exist_ok=True)
655
648
  ref_trace = workdir / "reference.trace.jsonl"
656
- _run(_build_trace_cmd(ref_cmd, chart, events, ref_trace, treat_as_xml))
657
-
658
- py_steps = _load_trace(py_trace)
659
- ref_steps = _load_trace(ref_trace)
649
+ ref_steps = _command_trace(ref_cmd, chart, events, ref_trace, treat_as_xml)
660
650
  # Normalize states to leaf-only (optional)
661
651
  if args.leaf_only:
662
652
  leaf_ids = _leaf_ids_from_chart(chart, treat_as_xml)
@@ -699,13 +689,13 @@ def main() -> None:
699
689
  print(f"Artifacts retained in {workdir}")
700
690
  sys.exit(1)
701
691
 
702
- print("✔ Python vs reference traces match")
692
+ print("Python vs reference traces match")
703
693
 
704
694
  if args.secondary:
705
- secondary_cmd = shlex.split(args.secondary)
695
+ secondary_cmd = split_command(args.secondary)
706
696
  else:
707
697
  secondary_env = os.environ.get("SCJSON_SECONDARY_ENGINE_CMD")
708
- secondary_cmd = shlex.split(secondary_env) if secondary_env else []
698
+ secondary_cmd = split_command(secondary_env) if secondary_env else []
709
699
 
710
700
  if secondary_cmd:
711
701
  secondary_trace = workdir / "secondary.trace.jsonl"
@@ -714,8 +704,7 @@ def main() -> None:
714
704
  workdir = Path(os.environ["WORKDIR_OVERRIDE"]) # type: ignore
715
705
  workdir.mkdir(parents=True, exist_ok=True)
716
706
  secondary_trace = workdir / "secondary.trace.jsonl"
717
- _run(_build_trace_cmd(secondary_cmd, chart, events, secondary_trace, treat_as_xml))
718
- secondary_steps = _load_trace(secondary_trace)
707
+ secondary_steps = _command_trace(secondary_cmd, chart, events, secondary_trace, treat_as_xml)
719
708
  # Apply normalization to secondary to align with ref_steps
720
709
  if args.leaf_only:
721
710
  leaf_ids = _leaf_ids_from_chart(chart, treat_as_xml)
@@ -742,7 +731,7 @@ def main() -> None:
742
731
  if temp_dir:
743
732
  print(f"Artifacts retained in {workdir}")
744
733
  sys.exit(2)
745
- print("✔ Reference vs secondary traces match")
734
+ print("Reference vs secondary traces match")
746
735
  if temp_dir:
747
736
  temp_dir.cleanup()
748
737
 
@@ -19,37 +19,17 @@ from __future__ import annotations
19
19
  import argparse
20
20
  import json
21
21
  import os
22
- import re
23
- import shlex
24
22
  import subprocess
23
+ from scjson_argv import format_command
25
24
  import sys
26
25
  from pathlib import Path
27
26
  from tempfile import TemporaryDirectory
28
27
  from typing import Iterable, List, Tuple
29
28
 
30
- from scion_support import augment_node_path, ensure_scion_runner
29
+ from scion_support import reference_command
31
30
 
32
- ROOT = Path(__file__).resolve().parent.parent
33
-
34
-
35
- _SCION_KNOWN_BUGS = {
36
- (ROOT / "tests" / "sweep_corpus" / "parallel_history_deep.scxml").resolve(): (
37
- "SCION reference exits sibling parallel regions when replaying deep history targets."
38
- ),
39
- }
40
-
41
-
42
- _SCXML_NOT_RE = re.compile(r"cond\s*=\s*['\"][^'\"]*\bnot\b[^'\"]*['\"]", re.IGNORECASE)
43
- _SCJSON_NOT_RE = re.compile(r'"cond"\s*:\s*"[^"]*\bnot\b[^"]*"', re.IGNORECASE)
44
- _SCXML_IN_RE = re.compile(r"cond\s*=\s*['\"][^'\"]*\bin\b[^'\"]*['\"]", re.IGNORECASE)
45
- _SCJSON_IN_RE = re.compile(r'"cond"\s*:\s*"[^"]*\bin\b[^"]*"', re.IGNORECASE)
46
-
47
- _SCION_EXPR_PATTERNS = [
48
- (_SCXML_NOT_RE, "SCION reference lacks support for Python datamodel expressions using 'not'."),
49
- (_SCJSON_NOT_RE, "SCION reference lacks support for Python datamodel expressions using 'not'."),
50
- (_SCXML_IN_RE, "SCION reference lacks support for Python datamodel membership tests using 'in'."),
51
- (_SCJSON_IN_RE, "SCION reference lacks support for Python datamodel membership tests using 'in'."),
52
- ]
31
+ MODULE_DIR = Path(__file__).resolve().parent
32
+ SOURCE_TUTORIAL = MODULE_DIR.parent / "tutorial"
53
33
 
54
34
 
55
35
  def _default_events_path(chart: Path) -> Path | None:
@@ -81,8 +61,8 @@ def main() -> None:
81
61
  "root",
82
62
  type=Path,
83
63
  nargs="?",
84
- default=ROOT / "tutorial",
85
- help="Root directory to search for charts (default: tutorial)",
64
+ default=SOURCE_TUTORIAL if MODULE_DIR.name == "py" and SOURCE_TUTORIAL.is_dir() else Path.cwd(),
65
+ help="Directory of charts (defaults to the checkout tutorial or the current directory)",
86
66
  )
87
67
  parser.add_argument(
88
68
  "--glob",
@@ -161,7 +141,7 @@ def main() -> None:
161
141
  type=str,
162
142
  choices=["tolerant", "strict", "scion"],
163
143
  default="tolerant",
164
- help="Ordering policy for child→parent emissions (finalize, etc.)",
144
+ help="Ordering policy for child-to-parent emissions (finalize, etc.)",
165
145
  )
166
146
  opts = parser.parse_args()
167
147
 
@@ -173,23 +153,11 @@ def main() -> None:
173
153
  continue
174
154
  opts.skip.append(line)
175
155
 
176
- repo_root = ROOT
177
156
  common_env = dict(os.environ)
178
- py_path = str(repo_root / "py")
179
- if common_env.get("PYTHONPATH"):
180
- common_env["PYTHONPATH"] = py_path + os.pathsep + common_env["PYTHONPATH"]
181
- else:
182
- common_env["PYTHONPATH"] = py_path
183
- scion_script = (repo_root / "tools" / "scion-runner" / "scion-trace.cjs").resolve()
184
- scion_ready = False
185
- if scion_script.exists() and not opts.reference:
186
- scion_ready = ensure_scion_runner(repo_root)
187
- if scion_ready:
188
- common_env["NODE_PATH"] = augment_node_path(common_env.get("NODE_PATH"), repo_root)
189
-
190
- python_reference = f"{sys.executable} -m scjson.cli engine-trace"
191
- scion_reference = f"node {scion_script}"
192
- default_reference = opts.reference or (scion_reference if scion_ready else python_reference)
157
+ if MODULE_DIR.name == "py":
158
+ common_env["PYTHONPATH"] = os.pathsep.join(
159
+ filter(None, [str(MODULE_DIR), common_env.get("PYTHONPATH")])
160
+ )
193
161
 
194
162
  charts: List[Path] = []
195
163
  for c in _iter_charts(opts.root, opts.glob):
@@ -198,17 +166,16 @@ def main() -> None:
198
166
  continue
199
167
  charts.append(c)
200
168
  if not charts:
201
- print("No charts found.")
202
- sys.exit(0)
169
+ raise SystemExit(f"No charts found under {opts.root} matching {opts.glob}.")
203
170
 
204
171
  mismatches: List[Tuple[Path, str]] = []
205
172
  total = 0
206
173
  cov_total = {"enteredStates": 0, "firedTransitions": 0, "doneEvents": 0, "errorEvents": 0}
207
174
  cov_count = 0
208
175
  cov_by_chart: dict[str, dict] = {}
209
- reference_notes: List[Tuple[Path, str]] = []
210
176
 
211
- base_cmd = [sys.executable, str((ROOT / "py" / "exec_compare.py").resolve()), "--reference", default_reference]
177
+ reference = format_command(reference_command(opts.reference))
178
+ base_cmd = [sys.executable, str(MODULE_DIR / "exec_compare.py"), "--reference", reference]
212
179
  if opts.workdir:
213
180
  artifacts_root = Path(opts.workdir)
214
181
  artifacts_root.mkdir(parents=True, exist_ok=True)
@@ -238,10 +205,7 @@ def main() -> None:
238
205
  temp_dir: TemporaryDirectory[str] | None = None
239
206
  try:
240
207
  for chart in charts:
241
- try:
242
- chart_text = chart.read_text(encoding="utf-8")
243
- except Exception:
244
- chart_text = ""
208
+ total += 1
245
209
  events = _default_events_path(chart)
246
210
  # Generate vector + coverage when requested and no events exist
247
211
  if events is None and opts.generate_vectors:
@@ -256,7 +220,7 @@ def main() -> None:
256
220
  vec_dir.mkdir(parents=True, exist_ok=True)
257
221
  vg_cmd = [
258
222
  sys.executable,
259
- str((ROOT / "py" / "vector_gen.py").resolve()),
223
+ str(MODULE_DIR / "vector_gen.py"),
260
224
  str(chart),
261
225
  "--out",
262
226
  str(vec_dir),
@@ -271,9 +235,15 @@ def main() -> None:
271
235
  vg_cmd.extend(["--limit", str(opts.gen_limit)])
272
236
  if opts.gen_variants_per_event:
273
237
  vg_cmd.extend(["--variants-per-event", str(opts.gen_variants_per_event)])
274
- _run(vg_cmd, env=common_env)
238
+ generated = _run(vg_cmd, env=common_env)
239
+ if generated.returncode:
240
+ mismatches.append((chart, generated.stdout + "\n" + generated.stderr))
241
+ continue
275
242
  gen_events = vec_dir / f"{chart.stem}.events.jsonl"
276
- events = gen_events if gen_events.exists() else None
243
+ if not gen_events.is_file():
244
+ mismatches.append((chart, "Vector generator did not produce an events file."))
245
+ continue
246
+ events = gen_events
277
247
  # Adopt recommended advance time from vector metadata when user did not pass one
278
248
  try:
279
249
  if (not opts.advance_time) or opts.advance_time <= 0:
@@ -304,7 +274,6 @@ def main() -> None:
304
274
  tmp.parent.mkdir(parents=True, exist_ok=True)
305
275
  tmp.write_text("")
306
276
  events = tmp
307
- total += 1
308
277
  cmd = list(base_cmd)
309
278
  if artifacts_root:
310
279
  rel = chart.relative_to(opts.root)
@@ -322,65 +291,7 @@ def main() -> None:
322
291
  cmd.append(str(chart))
323
292
  if events:
324
293
  cmd.extend(["--events", str(events)])
325
- override_reason: str | None = None
326
- if not opts.reference and default_reference == scion_reference:
327
- if chart_text:
328
- for pattern, message in _SCION_EXPR_PATTERNS:
329
- if pattern.search(chart_text):
330
- override_reason = message
331
- break
332
- if override_reason is None:
333
- bug_reason = _SCION_KNOWN_BUGS.get(chart.resolve())
334
- if bug_reason:
335
- override_reason = bug_reason
336
- if override_reason:
337
- try:
338
- ref_idx = cmd.index("--reference") + 1
339
- except ValueError:
340
- ref_idx = None
341
- if ref_idx is not None and cmd[ref_idx] == default_reference:
342
- cmd[ref_idx] = python_reference
343
- note = (
344
- f"{override_reason} Falling back to Python reference for {chart}."
345
- )
346
- print(note)
347
- reference_notes.append((chart, f"{override_reason} Using Python reference."))
348
294
  result = _run(cmd, env=common_env)
349
- if (
350
- result.returncode != 0
351
- and not opts.reference
352
- and scion_ready
353
- and default_reference == scion_reference
354
- and (
355
- "Command failed:" in result.stdout
356
- or "Command failed:" in result.stderr
357
- )
358
- ):
359
- try:
360
- ref_idx = cmd.index("--reference") + 1
361
- except ValueError:
362
- ref_idx = None
363
- if ref_idx is not None and cmd[ref_idx] == scion_reference:
364
- fallback_cmd = list(cmd)
365
- fallback_cmd[ref_idx] = python_reference
366
- fallback = _run(fallback_cmd, env=common_env)
367
- if fallback.returncode == 0:
368
- print(f"SCION reference failed for {chart}; fell back to Python reference.")
369
- result = fallback
370
- cmd = fallback_cmd
371
- else:
372
- combined = (
373
- "SCION reference failed:\n"
374
- + result.stdout
375
- + "\n"
376
- + result.stderr
377
- + "\nFallback to Python reference also failed:\n"
378
- + fallback.stdout
379
- + "\n"
380
- + fallback.stderr
381
- )
382
- mismatches.append((chart, combined))
383
- continue
384
295
  if result.returncode != 0:
385
296
  mismatches.append((chart, result.stdout + "\n" + result.stderr))
386
297
  # Keep going; summarize later
@@ -388,11 +299,6 @@ def main() -> None:
388
299
  if temp_dir is not None:
389
300
  temp_dir.cleanup()
390
301
 
391
- if reference_notes:
392
- print("Reference overrides applied for Python-specific conditions:")
393
- for path, reason in reference_notes:
394
- print(f"- {path}: {reason}")
395
-
396
302
  if mismatches:
397
303
  print(f"Mismatches: {len(mismatches)} of {total}")
398
304
  for path, out in mismatches[:10]:
@@ -416,7 +322,7 @@ def main() -> None:
416
322
  pass
417
323
  sys.exit(1)
418
324
 
419
- print(f"✔ All charts matched reference ({total} compared)")
325
+ print(f"All charts matched reference ({total} compared)")
420
326
  if cov_count:
421
327
  print(
422
328
  f"Coverage (generated vectors): charts={cov_count} entered={cov_total['enteredStates']} fired={cov_total['firedTransitions']} done={cov_total['doneEvents']} error={cov_total['errorEvents']}"
@@ -1,20 +1,21 @@
1
1
  [project]
2
2
  name = "scjson"
3
- version = "0.4.2"
3
+ version = "0.4.3"
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
- requires-python = ">=3.8"
6
+ requires-python = ">=3.10"
7
7
  license = "BSD-1-Clause"
8
8
  authors = [{name = "Ira Abbott", email = "ira@mycloud.blue"}]
9
9
  dependencies = [
10
- "pydantic",
10
+ "pydantic>=2.6,<3",
11
11
  "lxml",
12
12
  "jsonschema",
13
13
  "click",
14
14
  "py-sandboxed",
15
15
  "jinja2",
16
16
  "xmlschema",
17
- "xsdata",
17
+ "xsdata>=24.5",
18
+ "xsdata-pydantic>=24.5",
18
19
  ] # runtime + tooling for CLI, engine, and vector utilities
19
20
 
20
21
  [project.scripts]
@@ -24,13 +25,13 @@ scjson-exec-sweep = "exec_sweep:main"
24
25
  scjson-vector-gen = "vector_gen:main"
25
26
 
26
27
  [build-system]
27
- requires = ["setuptools>=61.0"]
28
+ requires = ["setuptools>=77.0.3"]
28
29
  build-backend = "setuptools.build_meta"
29
30
 
30
31
  [tool.setuptools]
31
32
  include-package-data = true
32
33
  # Install top-level helper modules used by CLI workflows as importable modules
33
- py-modules = ["exec_compare", "exec_sweep", "vector_gen"]
34
+ py-modules = ["exec_compare", "exec_sweep", "vector_gen", "scjson_argv", "scion_support"]
34
35
 
35
36
  [tool.setuptools.packages.find]
36
37
  include = ["scjson", "scjson.*", "vector_lib"]