def execute(args: argparse.Namespace): config_file = os.path.join(args.dir, args.c) config = get_config(config_file) with tempfile.TemporaryDirectory(dir=os.path.abspath(args.dir)) as td: if config.deployment.mode == "batch": builder: ImageBuilder = BatchImageBuilder(source_dir=args.dir, target_dir=td) elif config.deployment.mode == "http": builder = FlaskImageBuilder(source_dir=args.dir, target_dir=td) else: raise NotImplementedError( f"Currently no support for mode {config.deployment.mode}") builder.generate_wrapper_files(config) builder.copy_client_files_to_build_dir() builder.build_image(config)
def test_get_config_default(tmp_path, generate_config) -> None: file = tmp_path / "file" file.write_text(generate_config()) config = get_config(file) assert isinstance(config, NervosumConfig) assert config.name == "a_name" assert config.deployment.mode == "batch" assert config.src == "a_src" assert config.tag == "a_tag" assert config.deployment.platform_tag is None assert isinstance(config.interface, Interface) assert config.interface.model_module == "a_module" assert config.interface.model_class == "a_class" assert config.requirements == "a_requirements_file" assert isinstance(config.input_schema, List) assert config.input_schema[0].name == "field" assert config.input_schema[0].type == "a_type" assert config.output_schema[0].name == "prediction" assert config.output_schema[0].type == "a_type"
def test_get_config_mode_unsupported(tmp_path, generate_config) -> None: file = tmp_path / "file" file.write_text(generate_config(mode="unsupported")) with pytest.raises(ValidationError): get_config(file)
def test_get_config_mode_http(tmp_path, generate_config) -> None: file = tmp_path / "file" file.write_text(generate_config(mode="http")) config = get_config(file) assert config.deployment.mode == "http"