Fetches git repo by SSH 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 specified
(
cls,
git_host: str,
repo_info: str,
use_cache: bool = False,
commit: str = None,
silent: bool = True,
)
| 88 | @classmethod |
| 89 | @synchronized |
| 90 | def fetch( |
| 91 | cls, |
| 92 | git_host: str, |
| 93 | repo_info: str, |
| 94 | use_cache: bool = False, |
| 95 | commit: str = None, |
| 96 | silent: bool = True, |
| 97 | ) -> str: |
| 98 | """Fetches git repo by SSH protocol |
| 99 | |
| 100 | Args: |
| 101 | git_host: host address of git repo. Eg: github.com |
| 102 | repo_info: a string with format ``"repo_owner/repo_name[:tag_name/:branch_name]"`` with an optional |
| 103 | tag/branch. The default branch is ``master`` if not specified. Eg: ``"brain_sdk/MegBrain[:hub]"`` |
| 104 | use_cache: whether to use locally fetched code or completely re-fetch. |
| 105 | commit: commit id on github or gitlab. |
| 106 | silent: whether to accept the stdout and stderr of the subprocess with PIPE, instead of |
| 107 | displaying on the screen. |
| 108 | |
| 109 | Returns: |
| 110 | directory where the repo code is stored. |
| 111 | """ |
| 112 | if not cls._check_git_host(git_host): |
| 113 | raise InvalidGitHost("git_host: '{}' is malformed.".format(git_host)) |
| 114 | |
| 115 | repo_owner, repo_name, branch_info = cls._parse_repo_info(repo_info) |
| 116 | normalized_branch_info = branch_info.replace("/", "_") |
| 117 | repo_dir_raw = "{}_{}_{}".format( |
| 118 | repo_owner, repo_name, normalized_branch_info |
| 119 | ) + ("_{}".format(commit) if commit else "") |
| 120 | repo_dir = ( |
| 121 | "_".join(__version__.split(".")) + "_" + cls._gen_repo_dir(repo_dir_raw) |
| 122 | ) |
| 123 | git_url = "git@{}:{}/{}.git".format(git_host, repo_owner, repo_name) |
| 124 | |
| 125 | if use_cache and os.path.exists(repo_dir): # use cache |
| 126 | logger.debug("Cache Found in %s", repo_dir) |
| 127 | return repo_dir |
| 128 | |
| 129 | if is_distributed(): |
| 130 | logger.warning( |
| 131 | "When using `hub.load` or `hub.list` to fetch git repositories\n" |
| 132 | " in DISTRIBUTED mode for the first time, processes are synchronized to\n" |
| 133 | " ensure that target repository is ready to use for each process.\n" |
| 134 | " Users are expected to see this warning no more than ONCE, otherwise\n" |
| 135 | " (very little chance) you may need to remove corrupt cache\n" |
| 136 | " `%s` and fetch again.", |
| 137 | repo_dir, |
| 138 | ) |
| 139 | |
| 140 | shutil.rmtree(repo_dir, ignore_errors=True) # ignore and clear cache |
| 141 | |
| 142 | logger.debug( |
| 143 | "Git Clone from Repo:%s Branch: %s to %s", |
| 144 | git_url, |
| 145 | normalized_branch_info, |
| 146 | repo_dir, |
| 147 | ) |
no test coverage detected