Repository navigation
Expand file tree
/
Copy pathstrata.py
More file actions
40 lines (33 loc) · 1.62 KB
/
Copy pathstrata.py
File metadata and controls
40 lines (33 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""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())