Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into feature/new-state
Browse files Browse the repository at this point in the history
  • Loading branch information
mike0sv committed Aug 24, 2022
2 parents db8cfcb + 8a409c8 commit 8f4fe8b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mlem/api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def build(
Out-of-the-box supported string values are "docker_dir" and "docker".
model (Union[str, MlemModel]): The model to build.
"""
model = get_model_meta(model)
model = get_model_meta(model, load_value=False)
return ensure_mlem_object(MlemBuilder, builder, **builder_kwargs).build(
model
)
Expand Down
9 changes: 6 additions & 3 deletions mlem/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ def get_data_value(data: Any, batch_size: Optional[int] = None) -> Any:
return data


def get_model_meta(model: Union[str, MlemModel]) -> MlemModel:
def get_model_meta(
model: Union[str, MlemModel], load_value: bool = True
) -> MlemModel:
if isinstance(model, MlemModel):
if model.get_value() is None:
if load_value and model.get_value() is None:
model.load_value()
return model
if isinstance(model, str):
model = load_meta(model, force_type=MlemModel)
model.load_value()
if load_value:
model.load_value()
return model
raise InvalidArgumentError(
f"The object {model} is neither MlemModel nor path to it"
Expand Down
2 changes: 1 addition & 1 deletion mlem/contrib/pip/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def make_distr(self, obj: MlemModel, root: str, fs: AbstractFileSystem):
self.write(posixpath.join(root, "setup.py"), fs)

# TODO: methods with correct signatures
SourceTemplate(methods=list(obj.model_type.methods)).write(
SourceTemplate(methods=list(obj.model_type_raw["methods"])).write(
posixpath.join(path, "__init__.py"), fs
)
with no_echo():
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"tables",
"pyarrow",
"skl2onnx",
"dvc[s3]",
]

extras = {
Expand Down
11 changes: 10 additions & 1 deletion tests/api/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pytest_lazyfixture import lazy_fixture

from mlem.api import apply, apply_remote, link, load_meta
from mlem.api.commands import import_object, init, ls
from mlem.api.commands import build, import_object, init, ls
from mlem.config import CONFIG_FILE_NAME
from mlem.constants import PREDICT_METHOD_NAME
from mlem.core.artifacts import LocalArtifact
Expand Down Expand Up @@ -285,3 +285,12 @@ def test_import_model_pickle_remote_in_project(
)
_check_meta(meta, out_path, s3_storage_fs)
_check_load_artifact(meta, out_path, False, train)


def test_build_lazy(model_meta, tmp_path):
model_meta.dump(str(tmp_path / "model"))
model_meta.model_type_cache = model_meta.model_type_raw
model_meta.model_type_cache["type"] = "__lol__"
build(
"pip", model_meta, target=str(tmp_path / "build"), package_name="lol"
)

0 comments on commit 8f4fe8b

Please sign in to comment.