okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221An old Terminal that cannot hand over to a new Control is told to run the install command once more (TUI stress #4, H03)c924d3c9d

main
1.7 KiB43 linesraw
1"""Strata's small, dependency-free terminal entry point.
2
3Run ``python strata.py --help`` from a source checkout. Optional terminal UI
4dependencies are imported only by ``monitor``.
5"""
6
7import importlib.util
8import sys
9
10#: What the API server (serve, bench) imports. Everything else in the CLI is standard library.
11SERVER_PACKAGES = ("jinja2", "yaml", "regex", "psutil", "requests", "numpy", "PIL")
12
13
14def _preflight(argv):
15    """A missing package is a typed, actionable error, never an install: starting does not run pip."""
16    command = next((a for a in argv if not a.startswith("-")), "")
17    if command not in ("serve", "bench"):
18        return 0
19    missing = [m for m in SERVER_PACKAGES if importlib.util.find_spec(m) is None]
20    if not missing:
21        return 0
22    sys.stderr.write(
23        "strata: the interpreter %s is missing packages the API server needs: %s.\n"
24        "        Starting and serving never install anything. Use the Strata terminal archive (it carries them),\n"
25        "        or install them yourself: python -m pip install -r requirements.txt\n"
26        "        (status, monitor, timeskip and tune plan do not need them)\n" % (sys.executable, ", ".join(missing)))
27    return 5
28
29
30if __name__ == "__main__":
31    # a newer Control installed by `strata update` takes over before anything heavy is imported (stdlib only)
32    from strata_cli.handover import maybe_hand_over, refuse_old_updater
33    refused = refuse_old_updater(sys.argv[1:])
34    if refused is not None:
35        raise SystemExit(refused)
36    handed = maybe_hand_over(sys.argv[1:])
37    if handed is not None:
38        raise SystemExit(handed)
39    code = _preflight(sys.argv[1:])
40    if code:
41        raise SystemExit(code)
42    from strata_cli.cli import main
43    raise SystemExit(main())