r"""Imports hubmodule like python import. Args: 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. Eg: ``"brain_sdk/MegBrain[:hub]"`` git_host: host addres
(
repo_info: str,
git_host: str,
use_cache: bool = True,
commit: str = None,
protocol: str = DEFAULT_PROTOCOL,
)
| 79 | |
| 80 | |
| 81 | def _init_hub( |
| 82 | repo_info: str, |
| 83 | git_host: str, |
| 84 | use_cache: bool = True, |
| 85 | commit: str = None, |
| 86 | protocol: str = DEFAULT_PROTOCOL, |
| 87 | ): |
| 88 | r"""Imports hubmodule like python import. |
| 89 | |
| 90 | Args: |
| 91 | repo_info: a string with format ``"repo_owner/repo_name[:tag_name/:branch_name]"`` with an optional |
| 92 | tag/branch. The default branch is ``master`` if not specified. Eg: ``"brain_sdk/MegBrain[:hub]"`` |
| 93 | git_host: host address of git repo. Eg: github.com |
| 94 | use_cache: whether to use locally cached code or completely re-fetch. |
| 95 | commit: commit id on github or gitlab. |
| 96 | protocol: which protocol to use to get the repo, and HTTPS protocol only supports public repo on github. |
| 97 | The value should be one of HTTPS, SSH. |
| 98 | |
| 99 | Returns: |
| 100 | a python module. |
| 101 | """ |
| 102 | cache_dir = os.path.expanduser(os.path.join(_get_megengine_home(), "hub")) |
| 103 | os.makedirs(cache_dir, exist_ok=True) |
| 104 | absolute_repo_dir = _get_repo( |
| 105 | git_host, repo_info, use_cache=use_cache, commit=commit, protocol=protocol |
| 106 | ) |
| 107 | sys.path.insert(0, absolute_repo_dir) |
| 108 | hubmodule = load_module(HUBCONF, os.path.join(absolute_repo_dir, HUBCONF)) |
| 109 | sys.path.remove(absolute_repo_dir) |
| 110 | |
| 111 | return hubmodule |
| 112 | |
| 113 | |
| 114 | @functools.wraps(_init_hub) |
no test coverage detected