Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(client): add only_standalone decorator for cli view #1258

Merged
merged 1 commit into from
Sep 20, 2022
Merged
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
1 change: 0 additions & 1 deletion client/starwhale/base/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def when_exit() -> None:
yaml_name = yaml_name or self.yaml_name
self.buildImpl(workdir, yaml_name, **kw)

@abstractmethod
def buildImpl(self, workdir: Path, yaml_name: str, **kw: t.Any) -> None:
raise NotImplementedError

Expand Down
17 changes: 16 additions & 1 deletion client/starwhale/base/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
sort_obj_list,
snake_to_camel,
)
from starwhale.consts import UserRoleType, SHORT_VERSION_CNT
from starwhale.consts import UserRoleType, SHORT_VERSION_CNT, STANDALONE_INSTANCE
from starwhale.base.uri import URI
from starwhale.base.type import URIType
from starwhale.utils.error import FileFormatError
Expand Down Expand Up @@ -70,6 +70,21 @@ def _print() -> None:

return _wrapper

@staticmethod
def _only_standalone(func: t.Callable) -> t.Callable:
@wraps(func)
def _wrapper(*args: t.Any, **kwargs: t.Any) -> None:
sw = SWCliConfigMixed()
if sw.current_instance != STANDALONE_INSTANCE:
console.print(
":see_no_evil: This command only supports running in the standalone instance."
)
sys.exit(1)

return func(*args, **kwargs) # type: ignore

return _wrapper

@staticmethod
def _simple_action_print(func: t.Callable) -> t.Callable:
@wraps(func)
Expand Down
2 changes: 1 addition & 1 deletion client/starwhale/core/dataset/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,5 @@ def summary(self) -> DatasetSummary:
_manifest: t.Dict[str, t.Any] = yaml.safe_load(r["data"].get("versionMeta", {}))
return DatasetSummary(**_manifest.get("dataset_summary", {}))

def buildImpl(self, workdir: Path, yaml_name: str, **kw: t.Any) -> None:
def build(self, workdir: Path, yaml_name: str = "", **kw: t.Any) -> None:
raise NoSupportError("no support build dataset in the cloud instance")
1 change: 1 addition & 0 deletions client/starwhale/core/dataset/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def list(
return _data, _pager

@classmethod
@BaseTermView._only_standalone
def build(
cls,
workdir: str,
Expand Down
1 change: 1 addition & 0 deletions client/starwhale/core/eval/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def pause(self, force: bool = False) -> None:
def _do_action(self, action: str, force: bool = False) -> t.Tuple[bool, str]:
return self._action_run_map[action](force)

@BaseTermView._only_standalone
@BaseTermView._header
def compare(self, job_uris: t.List[str]) -> None:
if self.uri.instance_type != InstanceType.STANDALONE:
Expand Down
2 changes: 1 addition & 1 deletion client/starwhale/core/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,5 +515,5 @@ def list(
crm = CloudRequestMixed()
return crm._fetch_bundle_all_list(project_uri, URIType.MODEL, page, size)

def buildImpl(self, workdir: Path, yaml_name: str, **kw: t.Any) -> None:
def build(self, workdir: Path, yaml_name: str = "", **kw: t.Any) -> None:
raise NoSupportError("no support build model in the cloud instance")
3 changes: 3 additions & 0 deletions client/starwhale/core/model/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ def history(self, fullname: bool = False) -> t.List[t.Dict[str, t.Any]]:
title="Model History List", history=self.model.history(), fullname=fullname
)

@BaseTermView._only_standalone
def extract(self, force: bool = False, target_dir: str = "") -> None:
console.print(":oncoming_police_car: try to extract ...")
path = self.model.extract(force, target_dir)
console.print(f":clap: extracted @ {path.resolve()} :tada:")

@classmethod
@BaseTermView._only_standalone
def eval(
cls,
project: str,
Expand Down Expand Up @@ -107,6 +109,7 @@ def list(
return _data, _pager

@classmethod
@BaseTermView._only_standalone
def build(
cls,
workdir: str,
Expand Down
2 changes: 1 addition & 1 deletion client/starwhale/core/runtime/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,5 +1246,5 @@ def list(
crm = CloudRequestMixed()
return crm._fetch_bundle_all_list(project_uri, URIType.RUNTIME, page, size)

def buildImpl(self, workdir: Path, yaml_name: str, **kw: t.Any) -> None:
def build(self, workdir: Path, yaml_name: str = "", **kw: t.Any) -> None:
raise NoSupportError("no support build runtime in the cloud instance")
8 changes: 8 additions & 0 deletions client/starwhale/core/runtime/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def info(self, fullname: bool = False) -> None:
self._print_info(self.runtime.info(), fullname=fullname)

@classmethod
@BaseTermView._only_standalone
def activate(cls, path: str = "", uri: str = "") -> None:
Runtime.activate(path, uri)

@BaseTermView._only_standalone
def dockerize(
self,
tags: t.List[str],
Expand All @@ -69,6 +71,7 @@ def dockerize(
)

@classmethod
@BaseTermView._only_standalone
def lock(
cls,
target_dir: str,
Expand All @@ -92,6 +95,7 @@ def lock(
)

@classmethod
@BaseTermView._only_standalone
def build(
cls,
workdir: str,
Expand Down Expand Up @@ -126,6 +130,7 @@ def build(
env_name=env_name,
)

@BaseTermView._only_standalone
def extract(self, force: bool = False, target: t.Union[str, Path] = "") -> None:
console.print(":oncoming_police_car: try to extract ...")
path = self.runtime.extract(force, target)
Expand All @@ -147,6 +152,7 @@ def list(
return _data, _pager

@classmethod
@BaseTermView._only_standalone
def quickstart_from_uri(
cls,
workdir: Path,
Expand All @@ -165,6 +171,7 @@ def quickstart_from_uri(
console.print(":clap: Starwhale Runtime environment is ready to use :tada:")

@classmethod
@BaseTermView._only_standalone
def quickstart_from_ishell(
cls,
workdir: t.Union[Path, str],
Expand All @@ -183,6 +190,7 @@ def quickstart_from_ishell(
console.print(":clap: Starwhale Runtime environment is ready to use :tada:")

@classmethod
@BaseTermView._only_standalone
def restore(cls, target: str) -> None:
if in_production() or (os.path.exists(target) and os.path.isdir(target)):
workdir = Path(target)
Expand Down