okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c924d3c9d
main
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.""" 16command = next ((a for a in argv if not a .startswith ("-" )),"" ) 17if command not in ("serve" ,"bench" ): 18return 0 19missing = [m for m in SERVER_PACKAGES if importlib .util .find_spec (m )is None ] 20if not missing : 21return 0 22sys .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 ))) 27return 5 28 29 30if __name__ == "__main__" : 31# a newer Control installed by `strata update` takes over before anything heavy is imported (stdlib only) 32from strata_cli .handover import maybe_hand_over ,refuse_old_updater 33refused = refuse_old_updater (sys .argv [1 :]) 34if refused is not None : 35raise SystemExit (refused ) 36handed = maybe_hand_over (sys .argv [1 :]) 37if handed is not None : 38raise SystemExit (handed ) 39code = _preflight (sys .argv [1 :]) 40if code : 41raise SystemExit (code ) 42from strata_cli .cli import main 43raise SystemExit (main ())