This repository was archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Add -c help WIP #363
Merged
Merged
Add -c help WIP #363
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
46226d9
Add -c help to declare WIP
mike0sv 30c8fcb
extrapolate for other commands
mike0sv 869c4ea
some field docs and little improvements
mike0sv 9dd465d
cli utils
mike0sv e929c5e
add simple_parsing
mike0sv ad6ff49
Merge branch 'main' into feature/cli-conf-help
mike0sv 36de86e
fix tests
mike0sv b9bb837
fix tests
mike0sv 5f6ba80
lazy help
mike0sv ae6be81
ooopsie
mike0sv 61faf1d
class and fields docstrings
mike0sv 93e96d8
reparsing cli params for nested complex objects
mike0sv 751169f
fix for py37
mike0sv aa68263
support lists in build_model
mike0sv ffc012a
support lists in cli
mike0sv 346f0f5
nested options WIP
mike0sv 470902b
very nested options WIP
mike0sv 9d6cbc1
all but flat nested WIP
mike0sv 4ef61e6
lil refactoring
mike0sv b9a9fe2
flat nested stuff DONE
mike0sv 27aa37d
Update mlem/contrib/heroku/build.py
mike0sv 8f2800e
Update mlem/cli/declare.py
mike0sv cb9ad77
get rid of --conf, add mlem abc to declare
mike0sv 460b889
fix tests
mike0sv 18f30f9
fix lazyness
mike0sv 7025fbd
fix serialization
mike0sv 51f4865
fix tests
mike0sv e36fcaf
fix tests
mike0sv fa79e69
Update bitbucketfs.py
aguschin 9348694
Apply suggestions from code review
aguschin 72ed848
Merge branch 'main' into feature/cli-conf-help
mike0sv 51926f2
fix comments and disable failfast for gh actions
mike0sv f7920c7
backport docs from mlem.ai
mike0sv 0fd0bcf
sort import choices
mike0sv ee30197
merge
mike0sv ae26778
make run_cmd optional instead of bool
mike0sv 5be78bf
docs for torch import
mike0sv 645c0b6
allow --load for groups
mike0sv 661c8c6
fix windows bugs
mike0sv f25630b
suddenly fix dockerhub requests
mike0sv cc8dc50
suddenly fix dockerhub requests
mike0sv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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. | ||
jorgeorpinel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
Comment on lines
+31
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These As per https://github.com/iterative/mlem/issues/335, we need to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, let's do this separately |
||
""", | ||
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"), | ||
jorgeorpinel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.