Fetches git repo by HTTPS protocol. Args: git_host: host address of git repo. Eg: github.com repo_info: a string with format ``"repo_owner/repo_name[:tag_name/:branch_name]"`` with an optional tag/branch. The default branch is ``master`` if not specif
(
cls,
git_host: str,
repo_info: str,
use_cache: bool = False,
commit: str = None,
silent: bool = True,
)
| 197 | @classmethod |
| 198 | @synchronized |
| 199 | def fetch( |
| 200 | cls, |
| 201 | git_host: str, |
| 202 | repo_info: str, |
| 203 | use_cache: bool = False, |
| 204 | commit: str = None, |
| 205 | silent: bool = True, |
| 206 | ) -> str: |
| 207 | """Fetches git repo by HTTPS protocol. |
| 208 | |
| 209 | Args: |
| 210 | git_host: host address of git repo. Eg: github.com |
| 211 | repo_info: a string with format ``"repo_owner/repo_name[:tag_name/:branch_name]"`` with an optional |
| 212 | tag/branch. The default branch is ``master`` if not specified. Eg: ``"brain_sdk/MegBrain[:hub]"`` |
| 213 | use_cache: whether to use locally cached code or completely re-fetch. |
| 214 | commit: commit id on github or gitlab. |
| 215 | silent: whether to accept the stdout and stderr of the subprocess with PIPE, instead of |
| 216 | displaying on the screen. |
| 217 | |
| 218 | |
| 219 | Returns: |
| 220 | directory where the repo code is stored. |
| 221 | """ |
| 222 | if not cls._check_git_host(git_host): |
| 223 | raise InvalidGitHost("git_host: '{}' is malformed.".format(git_host)) |
| 224 | |
| 225 | repo_owner, repo_name, branch_info = cls._parse_repo_info(repo_info) |
| 226 | normalized_branch_info = branch_info.replace("/", "_") |
| 227 | repo_dir_raw = "{}_{}_{}".format( |
| 228 | repo_owner, repo_name, normalized_branch_info |
| 229 | ) + ("_{}".format(commit) if commit else "") |
| 230 | repo_dir = ( |
| 231 | "_".join(__version__.split(".")) + "_" + cls._gen_repo_dir(repo_dir_raw) |
| 232 | ) |
| 233 | archive_url = cls._git_archive_link( |
| 234 | git_host, repo_owner, repo_name, branch_info, commit |
| 235 | ) |
| 236 | |
| 237 | if use_cache and os.path.exists(repo_dir): # use cache |
| 238 | logger.debug("Cache Found in %s", repo_dir) |
| 239 | return repo_dir |
| 240 | |
| 241 | if is_distributed(): |
| 242 | logger.warning( |
| 243 | "When using `hub.load` or `hub.list` to fetch git repositories " |
| 244 | "in DISTRIBUTED mode for the first time, processes are synchronized to " |
| 245 | "ensure that target repository is ready to use for each process.\n" |
| 246 | "Users are expected to see this warning no more than ONCE, otherwise" |
| 247 | "(very little chance) you may need to remove corrupt hub cache %s and fetch again." |
| 248 | ) |
| 249 | |
| 250 | shutil.rmtree(repo_dir, ignore_errors=True) # ignore and clear cache |
| 251 | |
| 252 | logger.debug("Downloading from %s to %s", archive_url, repo_dir) |
| 253 | cls._download_zip_and_extract(archive_url, repo_dir) |
| 254 | |
| 255 | return repo_dir |
| 256 |
nothing calls this directly
no test coverage detected