MCPcopy Create free account
hub / github.com/modelscope/modelscope / __init__

Method __init__

modelscope/hub/repository.py:58–102  ·  view source on GitHub ↗
(self,
                 model_dir: str,
                 clone_from: str,
                 revision: Optional[str] = DEFAULT_REPOSITORY_REVISION,
                 git_token: Optional[str] = None,
                 git_path: Optional[str] = None,
                 endpoint: Optional[str] = None,
                 auth_token: Optional[str] = None)

Source from the content-addressed store, hash-verified

56 """A local representation of a model Git repository on ModelScope Hub."""
57
58 def __init__(self,
59 model_dir: str,
60 clone_from: str,
61 revision: Optional[str] = DEFAULT_REPOSITORY_REVISION,
62 git_token: Optional[str] = None,
63 git_path: Optional[str] = None,
64 endpoint: Optional[str] = None,
65 auth_token: Optional[str] = None):
66 if auth_token is not None and git_token is None:
67 import warnings
68 warnings.warn(
69 'Repository(auth_token=...) is deprecated, '
70 'use Repository(git_token=...) instead.',
71 DeprecationWarning,
72 stacklevel=2)
73 git_token = auth_token
74
75 if not revision:
76 raise InvalidParameter(
77 'a non-default value of revision cannot be empty.')
78
79 self._endpoint = endpoint
80 self.model_dir = model_dir
81 self.model_base_dir = os.path.dirname(model_dir)
82 self.model_repo_name = os.path.basename(model_dir)
83 self.git_token = _resolve_git_token(git_token)
84
85 self.git_wrapper = GitCommandWrapper(git_path)
86 if not self.git_wrapper.is_lfs_installed():
87 logger.error('git lfs is not installed, please install.')
88
89 url = self._get_model_id_url(clone_from)
90 cloned = _clone_if_needed(self.git_wrapper, self.model_base_dir,
91 self.model_repo_name, self.model_dir, url,
92 self.git_token, revision)
93 if not cloned:
94 return
95
96 if self.git_wrapper.is_lfs_installed():
97 self.git_wrapper.git_lfs_install(self.model_dir)
98
99 self.git_wrapper.add_user_info(self.model_base_dir,
100 self.model_repo_name)
101 if self.git_token:
102 self.git_wrapper.config_git_token(self.model_dir, self.git_token)
103
104 def _get_model_id_url(self, model_id: str) -> str:
105 endpoint = self._endpoint or get_endpoint()

Callers

nothing calls this directly

Calls 8

_get_model_id_urlMethod · 0.95
_resolve_git_tokenFunction · 0.85
GitCommandWrapperClass · 0.85
_clone_if_neededFunction · 0.85
is_lfs_installedMethod · 0.80
git_lfs_installMethod · 0.80
add_user_infoMethod · 0.80
config_git_tokenMethod · 0.80

Tested by

no test coverage detected