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

Class Repository

modelscope/hub/repository.py:55–177  ·  view source on GitHub ↗

A local representation of a model Git repository on ModelScope Hub.

Source from the content-addressed store, hash-verified

53
54
55class Repository:
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()
106 return f'{endpoint}/{model_id}.git'
107
108 def pull(self, remote: str = 'origin', branch: str = 'master'):
109 """Pull *remote*/*branch* into the local checkout."""
110 self.git_wrapper.pull(self.model_dir, remote=remote, branch=branch)
111
112 def add_lfs_type(self, file_name_suffix: str) -> None:

Callers 15

save_pretrainedMethod · 0.90
push_modelMethod · 0.90
_push_files_to_hubFunction · 0.90
prepare_caseMethod · 0.90
prepare_repo_dataMethod · 0.90
prepare_caseMethod · 0.90
prepare_caseMethod · 0.90
test_clone_repoMethod · 0.90
test_push_allMethod · 0.90

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…