Files
Strata/terminal/strata_cli/split_cmd.py
T
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
  changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
  Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
  repository paths inside tests.

engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.

No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
2026-11-17 13:19:21 +01:00

60 lines
3.0 KiB
Python

"""``strata split-engine apply``: the all-cards split engine for a run config the app wrote (the Terminal does the same inside ``strata launch``).
The desktop app builds its run config itself and starts it as a saved profile, so the step that turns a layer-split run config into the split engine's
(strata_control/split_engine.py ``apply_run_config``) is asked of Control here, with the rule, the engine package and the draft layer checked on this computer.
``--config`` is read and never changed; ``--out`` receives the split engine's run config only when the answer is yes. Nothing is downloaded.
"""
from __future__ import annotations
import json
import os
import sys
from pathlib import Path
def add_parser(sp) -> None:
p = sp.add_parser("split-engine", help="the all-cards split engine for a run config (the app's start asks it; the Terminal does the same in `strata launch`)")
s_sp = p.add_subparsers(dest="split_engine_command", required=True)
one = s_sp.add_parser("apply", help="write the split engine's run config for this one when the rule says yes; the config itself is not changed")
one.add_argument("--config", required=True, metavar="FILE", help="the run config the app is about to start")
one.add_argument("--out", metavar="FILE", help="where the split engine's run config goes when the answer is yes")
one.add_argument("--output", choices=("human", "json"), default="human")
def run(a) -> int:
machine = a.output == "json"
def fail(message: str) -> int:
if machine:
print(json.dumps({"schema_version": 1, "ok": False, "error": {"code": "split_engine_failed", "message": message}}, ensure_ascii=False))
else:
print(f"strata: {message}", file=sys.stderr)
return 5
try:
cfg = json.loads(Path(a.config).read_text(encoding="utf-8-sig"))
if not isinstance(cfg, dict):
raise ValueError("not an object")
except (OSError, ValueError) as exc:
return fail(f"The run config could not be read ({type(exc).__name__}).")
from strata_control import split_engine as SE
work = json.loads(json.dumps(cfg)) # a copy: apply_run_config rewrites it in place
decision, line, warn = SE.apply_run_config(work, allow_untested=os.environ.get("STRATA_SPLIT_ALLOW_UNTESTED") == "1")
wrote = None
if decision.use_split and a.out:
out = Path(a.out)
tmp = out.with_name(out.name + ".tmp")
fd = os.open(tmp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
with os.fdopen(fd, "w", encoding="utf-8") as f:
json.dump(work, f, indent=2)
f.write("\n")
os.replace(tmp, out)
wrote = str(out)
if machine:
print(json.dumps({"schema_version": 1, "ok": True, "split": bool(decision.use_split), "line": line, "warn": bool(warn), "reasons": list(decision.reasons),
"cards": decision.cards, "written": wrote}, ensure_ascii=False))
else:
print(line or ("Using the normal layer split." if not decision.use_split else decision.line))
return 0