diff --git a/client/starwhale/base/bundle.py b/client/starwhale/base/bundle.py index c58ed27e7f..37f49ac83d 100644 --- a/client/starwhale/base/bundle.py +++ b/client/starwhale/base/bundle.py @@ -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 diff --git a/client/starwhale/base/view.py b/client/starwhale/base/view.py index d1c65c6672..0d04fd87ec 100644 --- a/client/starwhale/base/view.py +++ b/client/starwhale/base/view.py @@ -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 @@ -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) diff --git a/client/starwhale/core/dataset/model.py b/client/starwhale/core/dataset/model.py index 184dad5b5b..cc73dafb44 100644 --- a/client/starwhale/core/dataset/model.py +++ b/client/starwhale/core/dataset/model.py @@ -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") diff --git a/client/starwhale/core/dataset/view.py b/client/starwhale/core/dataset/view.py index 71b3467d07..f10e9f7f2f 100644 --- a/client/starwhale/core/dataset/view.py +++ b/client/starwhale/core/dataset/view.py @@ -145,6 +145,7 @@ def list( return _data, _pager @classmethod + @BaseTermView._only_standalone def build( cls, workdir: str, diff --git a/client/starwhale/core/eval/view.py b/client/starwhale/core/eval/view.py index fbb966f762..00bef16646 100644 --- a/client/starwhale/core/eval/view.py +++ b/client/starwhale/core/eval/view.py @@ -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: diff --git a/client/starwhale/core/model/model.py b/client/starwhale/core/model/model.py index fb85b9a776..baea8d5d20 100644 --- a/client/starwhale/core/model/model.py +++ b/client/starwhale/core/model/model.py @@ -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") diff --git a/client/starwhale/core/model/view.py b/client/starwhale/core/model/view.py index a7a6586c58..c38d7b41af 100644 --- a/client/starwhale/core/model/view.py +++ b/client/starwhale/core/model/view.py @@ -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, @@ -107,6 +109,7 @@ def list( return _data, _pager @classmethod + @BaseTermView._only_standalone def build( cls, workdir: str, diff --git a/client/starwhale/core/runtime/model.py b/client/starwhale/core/runtime/model.py index 754b0f0d40..0e76777a33 100644 --- a/client/starwhale/core/runtime/model.py +++ b/client/starwhale/core/runtime/model.py @@ -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") diff --git a/client/starwhale/core/runtime/view.py b/client/starwhale/core/runtime/view.py index 23132456a1..7a3feedb6f 100644 --- a/client/starwhale/core/runtime/view.py +++ b/client/starwhale/core/runtime/view.py @@ -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], @@ -69,6 +71,7 @@ def dockerize( ) @classmethod + @BaseTermView._only_standalone def lock( cls, target_dir: str, @@ -92,6 +95,7 @@ def lock( ) @classmethod + @BaseTermView._only_standalone def build( cls, workdir: str, @@ -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) @@ -147,6 +152,7 @@ def list( return _data, _pager @classmethod + @BaseTermView._only_standalone def quickstart_from_uri( cls, workdir: Path, @@ -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], @@ -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)