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

Remove cli examples #407

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/check-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
# no HDF5 support installed for tables
- os: windows-latest
python: "3.9"
fail-fast: true
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -92,6 +92,9 @@ jobs:
pip install pre-commit .[tests]
- run: pre-commit run pylint -a -v --show-diff-on-failure
if: matrix.python != '3.7'
- name: Start minikube
if: matrix.os == 'ubuntu-latest' && matrix.python == '3.9'
uses: medyagh/setup-minikube@master
- name: Run tests
timeout-minutes: 40
run: pytest
Expand Down
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ indent-string=' '
max-line-length=100

# Maximum number of lines in a module.
max-module-lines=1000
max-module-lines=2000

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
Expand All @@ -389,7 +389,7 @@ ignore-comments=yes
ignore-docstrings=yes

# Ignore imports when computing similarities.
ignore-imports=no
ignore-imports=yes

# Ignore function signatures when computing similarities.
ignore-signatures=no
Expand Down
33 changes: 22 additions & 11 deletions mlem/api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
WrongMethodError,
)
from mlem.core.import_objects import ImportAnalyzer, ImportHook
from mlem.core.meta_io import MLEM_DIR, Location, UriResolver, get_fs
from mlem.core.meta_io import MLEM_DIR, Location, get_fs
from mlem.core.metadata import load_meta, save
from mlem.core.objects import (
MlemBuilder,
Expand Down Expand Up @@ -367,7 +367,7 @@ def ls( # pylint: disable=too-many-locals
include_links: bool = True,
ignore_errors: bool = False,
) -> Dict[Type[MlemObject], List[MlemObject]]:
loc = UriResolver.resolve(
loc = Location.resolve(
"", project=project, rev=rev, fs=fs, find_project=True
)
_validate_ls_project(loc, project)
Expand All @@ -392,7 +392,7 @@ def import_object(
"""Try to load an object as MLEM model (or data) and return it,
optionally saving to the specified target location
"""
loc = UriResolver.resolve(path, project, rev, fs)
loc = Location.resolve(path, project, rev, fs)
echo(EMOJI_LOAD + f"Importing object from {loc.uri_repr}")
if type_ is not None:
type_, modifier = parse_import_type_modifier(type_)
Expand Down Expand Up @@ -420,9 +420,11 @@ def deploy(
fs: Optional[AbstractFileSystem] = None,
external: bool = None,
index: bool = None,
env_kwargs: Dict[str, Any] = None,
**deploy_kwargs,
) -> MlemDeployment:
deploy_path = None
update = False
if isinstance(deploy_meta_or_path, str):
deploy_path = deploy_meta_or_path
try:
Expand All @@ -432,13 +434,13 @@ def deploy(
fs=fs,
force_type=MlemDeployment,
)
update = True
except MlemObjectNotFound:
deploy_meta = None

else:
deploy_meta = deploy_meta_or_path
if model is not None:
deploy_meta.replace_model(get_model_meta(model))
update = True

if deploy_meta is None:
if model is None or env is None:
Expand All @@ -448,15 +450,24 @@ def deploy(
if not deploy_path:
raise MlemError("deploy_path cannot be empty")
model_meta = get_model_meta(model)
env_meta = ensure_meta(MlemEnv, env)
deploy_meta = env_meta.deploy_type(
model=model_meta,
env=env_meta,
env_link=env_meta.make_link(),
model_link=model_meta.make_link(),
env_meta = ensure_meta(MlemEnv, env, allow_typename=True)
if isinstance(env_meta, type):
env = None
if env_kwargs:
env = env_meta(**env_kwargs)
deploy_type = env_meta.deploy_type
deploy_meta = deploy_type(
model_cache=model_meta,
model=model_meta.make_link(),
env=env,
**deploy_kwargs,
)
deploy_meta.dump(deploy_path, fs, project, index, external)
else:
if model is not None:
deploy_meta.replace_model(get_model_meta(model, load_value=False))
if update:
pass # todo update from deploy_args and env_args
# ensuring links are working
deploy_meta.get_env()
deploy_meta.get_model()
Expand Down
44 changes: 39 additions & 5 deletions mlem/api/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import re
from typing import Any, Optional, Tuple, Type, TypeVar, Union
from typing import Any, Optional, Tuple, Type, TypeVar, Union, overload

from mlem.core.base import MlemABC, build_mlem_object
from mlem.core.errors import InvalidArgumentError
from typing_extensions import Literal

from mlem.core.base import MlemABC, build_mlem_object, load_impl_ext
from mlem.core.errors import InvalidArgumentError, MlemObjectNotFound
from mlem.core.metadata import load, load_meta
from mlem.core.objects import MlemData, MlemModel, MlemObject

Expand Down Expand Up @@ -45,9 +47,41 @@ def get_model_meta(
MM = TypeVar("MM", bound=MlemObject)


def ensure_meta(as_class: Type[MM], obj_or_path: Union[str, MM]) -> MM:
@overload
def ensure_meta(
as_class: Type[MM],
obj_or_path: Union[str, MM],
allow_typename: bool = False,
) -> Union[MM, Type[MM]]:
pass


@overload
def ensure_meta(
as_class: Type[MM],
obj_or_path: Union[str, MM],
allow_typename: Literal[False] = False,
) -> MM:
pass


def ensure_meta(
as_class: Type[MM],
obj_or_path: Union[str, MM],
allow_typename: bool = False,
) -> Union[MM, Type[MM]]:
if isinstance(obj_or_path, str):
return load_meta(obj_or_path, force_type=as_class)
try:
return load_meta(obj_or_path, force_type=as_class)
except MlemObjectNotFound:
if allow_typename:
impl = load_impl_ext(
as_class.abs_name, obj_or_path, raise_on_missing=False
)
if impl is None or not issubclass(impl, as_class):
raise
return impl
raise
if isinstance(obj_or_path, as_class):
return obj_or_path
raise ValueError(f"Cannot get {as_class} from '{obj_or_path}'")
Expand Down
Loading