MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / _init_hub

Function _init_hub

imperative/python/megengine/hub/hub.py:81–111  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

79
80
81def _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)

Callers 4

import_moduleFunction · 0.85
listFunction · 0.85
loadFunction · 0.85
helpFunction · 0.85

Calls 6

_get_megengine_homeFunction · 0.85
_get_repoFunction · 0.85
load_moduleFunction · 0.85
joinMethod · 0.80
insertMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected