[Fix] Fix studio cli (#1742)

This commit is contained in:
Xingjun.Wang
2026-06-23 16:42:49 +08:00
committed by GitHub
parent cecb699cd0
commit cf08fb242d
4 changed files with 20 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ plugins_manager = PluginsManager()
class PluginsCMD(CLICommand):
name = 'plugin'
name = 'plugins'
@staticmethod
def register(subparsers: ArgumentParser) -> None:

View File

@@ -90,9 +90,19 @@ class HubApi(_LegacyHubApi):
# ------------------------------------------------------------------
# Legacy method shims missing from LegacyHubApi
# ------------------------------------------------------------------
def create_model(self, model_id: str, **kwargs) -> None:
"""Create a model repo — delegates to ``create_repo`` (model type)."""
return self.create_repo(model_id, repo_type='model', **kwargs)
def create_model(self, model_id: str, **kwargs) -> str:
"""Create a model repo — delegates to ``create_repo`` (model type).
Returns the model repository URL for backward compatibility.
Authentication errors are converted to ``ValueError`` by the compat layer.
"""
# LegacyHubApi.create_model handles exception conversion;
# override endpoint in the returned URL with local self.endpoint.
result = super().create_model(model_id, **kwargs)
# Replace endpoint in URL with the one resolved at __init__ time
if result and self.endpoint and self.endpoint not in result:
return f'{self.endpoint}/models/{model_id}'
return result
def get_model_url(self, model_id: str) -> str:
"""Return the model page URL ``{endpoint}/{model_id}``."""

View File

@@ -147,10 +147,12 @@ def check_model_from_owner_group(model_dir: str,
if group in owner_group:
return True
# Also check cache path pattern: {cache_root}/{owner}--{model_name}/snapshots/{revision}
# Only check the grandparent directory to avoid path traversal attacks
# Require exactly "{owner}--{name}" format (2 segments split by --)
# to prevent spoofing via accounts like "iic--hacked" which would
# produce paths like "iic--hacked--evil" and bypass the check.
grandparent = os.path.basename(os.path.dirname(parent_dir))
if '--' in grandparent:
prefix = grandparent.split('--', 1)[0]
if prefix in owner_group:
parts = grandparent.split('--')
if len(parts) == 2 and parts[0] in owner_group:
return True
return False

View File

@@ -34,6 +34,7 @@ plugins = "modelscope.cli.plugins:PluginsCMD"
skills = "modelscope.cli.skills:SkillsCMD"
llamafile = "modelscope.cli.llamafile:LlamafileCMD"
modelcard = "modelscope.cli.modelcard:ModelCardCMD"
studio = "modelscope.cli.studio:StudioCMD"
[build-system]
requires = ["setuptools>=69", "wheel"]