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

Commit

Permalink
Add no-deploy option for Flyio app creation (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike0sv authored Feb 8, 2023
1 parent f6b5c14 commit 0c6f03c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
21 changes: 20 additions & 1 deletion mlem/contrib/docker/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import glob
import json
import logging
import os
import posixpath
Expand All @@ -7,11 +8,13 @@
import tempfile
from abc import abstractmethod
from contextlib import contextmanager
from json import JSONDecodeError
from pathlib import Path
from typing import Any, Callable, ClassVar, Dict, List, Optional, Union

from fsspec import AbstractFileSystem
from fsspec.implementations.local import LocalFileSystem
from importlib_metadata import Distribution, PackageNotFoundError
from pydantic import BaseModel
from yaml import safe_dump

Expand Down Expand Up @@ -141,13 +144,18 @@ def get_install_command(self, args: "DockerBuildArgs"):
class GitSource(MlemSource):
type = "git"

def __init__(self, rev: str = ""):
self.rev = rev

def build(self, path):
pass

def get_install_command(self, args: "DockerBuildArgs"):
rev = ""
if LOCAL_DOCKER_CONFIG.git_rev is not None:
rev = f"@{LOCAL_DOCKER_CONFIG.git_rev}"
if self.rev:
rev = f"@{self.rev}"
return (
f"RUN {args.package_install_cmd} git {args.package_clean_cmd}\n"
f"RUN pip install git+https://github.com/iterative/mlem{rev}#egg=mlem"
Expand Down Expand Up @@ -175,7 +183,18 @@ def get_mlem_source() -> MlemSource:
raise ValueError(f"unknown mlem source '{source}'")
# if source is not specified
if "dev" in mlem.__version__:
return WhlSource()
mlem_src_path = os.path.dirname(os.path.dirname(mlem.__file__))
if os.path.exists(os.path.join(mlem_src_path, "setup.py")): # dev env
return WhlSource()
# installed from git branch (probably)
rev = ""
try:
rev = json.loads(
Distribution.from_name("mlem").read_text("direct_url.json")
)["vcs_info"]["commit_id"]
except (PackageNotFoundError, JSONDecodeError, TypeError, KeyError):
pass
return GitSource(rev=rev)
return PipSource()


Expand Down
2 changes: 2 additions & 0 deletions mlem/contrib/flyio/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def _create_app(self, state: FlyioAppState):
"region": self.region
or self.get_env().region
or project_config("", section=FlyioConfig).region,
"no-deploy": True,
}
if self.app_name:
args["name"] = self.app_name
Expand Down Expand Up @@ -144,6 +145,7 @@ def _build_in_dir(self, model: MlemModel, state: FlyioAppState):
state.fly_toml = read_fly_toml(tempdir)
state.update_model(model)
self.update_state(state)
ui.echo(f"Model deployed to https://{state.hostname}")

def deploy(self, model: MlemModel):
check_flyctl_exec()
Expand Down
4 changes: 2 additions & 2 deletions mlem/utils/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ def get_package_name(mod: Union[ModuleType, str]) -> str:
packages = packages_distributions()
fix_suggestion = "If that's incorrect, fix metadata manually, either in `.mlem` file or in your MLEM Python object."
if mod not in packages or len(packages[mod]) == 0:
logger.warning(
logger.debug(
"Fail to determine package name for module '%s', using module name instead. %s",
mod,
fix_suggestion,
)
return mod
if len(set(packages[mod])) > 1:
logger.warning(
logger.debug(
"Found multiple packages for '%s' module: %s. Using first one. %s",
mod,
packages[mod],
Expand Down

0 comments on commit 0c6f03c

Please sign in to comment.