-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from WenjieDu/dev
Enabling to tune hyperparameters for outside models implemented with PyPOTS framework
- Loading branch information
Showing
2 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
Adding CLI utilities here. | ||
""" | ||
|
||
# Created by Wenjie Du <wenjay.du@gmail.com> | ||
# License: BSD-3-Clause | ||
|
||
|
||
import os | ||
import sys | ||
from importlib import util | ||
from types import ModuleType | ||
|
||
|
||
def load_package_from_path(pkg_path: str) -> ModuleType: | ||
"""Load a package from a given path. Please refer to https://stackoverflow.com/a/50395128""" | ||
init_path = os.path.join(pkg_path, "__init__.py") | ||
assert os.path.exists(init_path) | ||
|
||
name = os.path.basename(pkg_path) | ||
spec = util.spec_from_file_location(name, init_path) | ||
module = util.module_from_spec(spec) | ||
sys.modules[spec.name] = module | ||
spec.loader.exec_module(module) | ||
return module |