This repository has been archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add -c help to declare WIP * extrapolate for other commands * some field docs and little improvements * cli utils * add simple_parsing * fix tests * fix tests * lazy help * ooopsie * class and fields docstrings * reparsing cli params for nested complex objects rewrite get_field_docstring for 9000x speed fix build_model bug * fix for py37 * support lists in build_model * support lists in cli * nested options WIP * very nested options WIP * all but flat nested WIP * lil refactoring * flat nested stuff DONE * Update mlem/contrib/heroku/build.py Co-authored-by: Alexander Guschin <[email protected]> * Update mlem/cli/declare.py Co-authored-by: Alexander Guschin <[email protected]> * get rid of --conf, add mlem abc to declare * fix tests * fix lazyness * fix serialization * fix tests * fix tests * Update bitbucketfs.py * Apply suggestions from code review * fix comments and disable failfast for gh actions * backport docs from mlem.ai * sort import choices * make run_cmd optional instead of bool * docs for torch import * allow --load for groups add server config into docker build * fix windows bugs * suddenly fix dockerhub requests * suddenly fix dockerhub requests Co-authored-by: Alexander Guschin <[email protected]>
- Loading branch information
Showing
70 changed files
with
2,844 additions
and
649 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,98 @@ | ||
from typing import List, Optional | ||
|
||
from typer import Argument | ||
from typer import Option, Typer | ||
|
||
from mlem.cli.main import ( | ||
config_arg, | ||
app, | ||
mlem_command, | ||
option_conf, | ||
mlem_group, | ||
mlem_group_callback, | ||
option_file_conf, | ||
option_load, | ||
option_project, | ||
option_rev, | ||
) | ||
from mlem.cli.utils import ( | ||
abc_fields_parameters, | ||
config_arg, | ||
for_each_impl, | ||
lazy_class_docstring, | ||
) | ||
from mlem.core.metadata import load_meta | ||
from mlem.core.objects import MlemBuilder, MlemModel | ||
from mlem.utils.entrypoints import list_implementations | ||
|
||
build = Typer( | ||
name="build", | ||
help=""" | ||
Build models to create re-usable, ship-able entities such as a Docker image or | ||
Python package. | ||
Examples: | ||
Build docker image from model | ||
$ mlem build mymodel docker -c server.type=fastapi -c image.name=myimage | ||
Create build docker_dir declaration and build it | ||
$ mlem declare builder docker_dir -c server=fastapi -c target=build build_dock | ||
$ mlem build mymodel --load build_dock | ||
""", | ||
cls=mlem_group("runtime", aliases=["export"]), | ||
subcommand_metavar="builder", | ||
) | ||
app.add_typer(build) | ||
|
||
|
||
@mlem_command("build", section="runtime", aliases=["export"]) | ||
def build( | ||
model: str = Argument(..., help="Path to model"), | ||
subtype: str = Argument( | ||
"", | ||
help=f"Type of build. Choices: {list_implementations(MlemBuilder)}", | ||
show_default=False, | ||
), | ||
@mlem_group_callback(build, required=["model", "load"]) | ||
def build_load( | ||
model: str = Option(None, "-m", "--model", help="Path to model"), | ||
project: Optional[str] = option_project, | ||
rev: Optional[str] = option_rev, | ||
load: Optional[str] = option_load("builder"), | ||
conf: List[str] = option_conf("builder"), | ||
file_conf: List[str] = option_file_conf("builder"), | ||
load: str = option_load("builder"), | ||
): | ||
""" | ||
Build/export model | ||
Examples: | ||
Build docker image from model | ||
$ mlem build mymodel docker -c server.type=fastapi -c image.name=myimage | ||
Create build docker_dir declaration and build it | ||
$ mlem declare builder docker_dir -c server=fastapi -c target=build build_dock | ||
$ mlem build mymodel --load build_dock | ||
""" | ||
from mlem.api.commands import build | ||
|
||
build( | ||
config_arg(MlemBuilder, load, subtype, conf, file_conf), | ||
config_arg( | ||
MlemBuilder, | ||
load, | ||
None, | ||
conf=None, | ||
file_conf=None, | ||
), | ||
load_meta(model, project, rev, force_type=MlemModel), | ||
) | ||
|
||
|
||
@for_each_impl(MlemBuilder) | ||
def create_build_command(type_name): | ||
@mlem_command( | ||
type_name, | ||
section="builders", | ||
parent=build, | ||
dynamic_metavar="__kwargs__", | ||
dynamic_options_generator=abc_fields_parameters( | ||
type_name, MlemBuilder | ||
), | ||
hidden=type_name.startswith("_"), | ||
lazy_help=lazy_class_docstring(MlemBuilder.abs_name, type_name), | ||
no_pass_from_parent=["file_conf"], | ||
) | ||
def build_type( | ||
model: str = Option(..., "-m", "--model", help="Path to model"), | ||
project: Optional[str] = option_project, | ||
rev: Optional[str] = option_rev, | ||
file_conf: List[str] = option_file_conf("builder"), | ||
**__kwargs__ | ||
): | ||
from mlem.api.commands import build | ||
|
||
build( | ||
config_arg( | ||
MlemBuilder, | ||
None, | ||
type_name, | ||
conf=None, | ||
file_conf=file_conf, | ||
**__kwargs__ | ||
), | ||
load_meta(model, project, rev, force_type=MlemModel), | ||
) |
Oops, something went wrong.