bikes.scripts
Scripts for the CLI application.
1"""Scripts for the CLI application.""" 2 3# ruff: noqa: E402 4 5# %% WARNINGS 6 7import warnings 8 9# disable annoying mlflow warnings 10warnings.filterwarnings(action="ignore", category=UserWarning) 11 12# %% IMPORTS 13 14import argparse 15import json 16import sys 17 18from bikes import settings 19from bikes.io import configs 20 21# %% PARSERS 22 23parser = argparse.ArgumentParser(description="Run an AI/ML job from YAML/JSON configs.") 24parser.add_argument("files", nargs="*", help="Config files for the job (local path only).") 25parser.add_argument("-e", "--extras", nargs="*", default=[], help="Config strings for the job.") 26parser.add_argument("-s", "--schema", action="store_true", help="Print settings schema and exit.") 27 28# %% SCRIPTS 29 30 31def main(argv: list[str] | None = None) -> int: 32 """Main script for the application.""" 33 args = parser.parse_args(argv) 34 if args.schema: 35 schema = settings.MainSettings.model_json_schema() 36 json.dump(schema, sys.stdout, indent=4) 37 return 0 38 files = [configs.parse_file(file) for file in args.files] 39 strings = [configs.parse_string(string) for string in args.extras] 40 if len(files) == 0 and len(strings) == 0: 41 raise RuntimeError("No configs provided.") 42 config = configs.merge_configs([*files, *strings]) 43 object_ = configs.to_object(config) # python object 44 setting = settings.MainSettings.model_validate(object_) 45 with setting.job as runner: 46 runner.run() 47 return 0
parser =
ArgumentParser(prog='pdoc', usage=None, description='Run an AI/ML job from YAML/JSON configs.', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
def
main(argv: list[str] | None = None) -> int:
32def main(argv: list[str] | None = None) -> int: 33 """Main script for the application.""" 34 args = parser.parse_args(argv) 35 if args.schema: 36 schema = settings.MainSettings.model_json_schema() 37 json.dump(schema, sys.stdout, indent=4) 38 return 0 39 files = [configs.parse_file(file) for file in args.files] 40 strings = [configs.parse_string(string) for string in args.extras] 41 if len(files) == 0 and len(strings) == 0: 42 raise RuntimeError("No configs provided.") 43 config = configs.merge_configs([*files, *strings]) 44 object_ = configs.to_object(config) # python object 45 setting = settings.MainSettings.model_validate(object_) 46 with setting.job as runner: 47 runner.run() 48 return 0
Main script for the application.