Files
strata/strata.py
T
Niko1221 f39d951904 Terminal hands over to the Control that strata update installed
The Terminal on PATH ignored components/control/active.json, so after
strata update the old Control kept running. strata.py now checks the
pointer first (stdlib only) and runs the newer, whole Control with its
own interpreter; never an older one, never outside the control folder,
no loop (STRATA_HANDOVER), one warning and a fallback if it is broken.
strata update says the next command already runs the new Control.
2026-10-20 16:59:58 +02:00

41 lines
1.6 KiB
Python

"""Strata's small, dependency-free terminal entry point.
Run ``python strata.py --help`` from a source checkout. Optional terminal UI
dependencies are imported only by ``monitor``.
"""
import importlib.util
import sys
#: What the API server (serve, bench) imports. Everything else in the CLI is standard library.
SERVER_PACKAGES = ("jinja2", "yaml", "regex", "psutil", "requests", "numpy", "PIL")
def _preflight(argv):
"""A missing package is a typed, actionable error, never an install: starting does not run pip."""
command = next((a for a in argv if not a.startswith("-")), "")
if command not in ("serve", "bench"):
return 0
missing = [m for m in SERVER_PACKAGES if importlib.util.find_spec(m) is None]
if not missing:
return 0
sys.stderr.write(
"strata: the interpreter %s is missing packages the API server needs: %s.\n"
" Starting and serving never install anything. Use the Strata terminal archive (it carries them),\n"
" or install them yourself: python -m pip install -r requirements.txt\n"
" (status, monitor, timeskip and tune plan do not need them)\n" % (sys.executable, ", ".join(missing)))
return 5
if __name__ == "__main__":
# a newer Control installed by `strata update` takes over before anything heavy is imported (stdlib only)
from strata_cli.handover import maybe_hand_over
handed = maybe_hand_over(sys.argv[1:])
if handed is not None:
raise SystemExit(handed)
code = _preflight(sys.argv[1:])
if code:
raise SystemExit(code)
from strata_cli.cli import main
raise SystemExit(main())