1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-10 06:20:57 +08:00

Merge remote-tracking branch 'microsoft/main' into online_srv

This commit is contained in:
lzh222333
2021-05-24 05:10:15 +00:00
3 changed files with 21 additions and 16 deletions

View File

@@ -8,6 +8,7 @@ from __future__ import print_function
import os
import pickle
import re
import sys
import copy
import json
import yaml
@@ -178,8 +179,10 @@ def get_module_by_module_path(module_path: Union[str, ModuleType]):
module = module_path
else:
if module_path.endswith(".py"):
module_spec = importlib.util.spec_from_file_location("", module_path)
module_name = re.sub("^[^a-zA-Z_]+", "", re.sub("[^0-9a-zA-Z_]", "", module_path[:-3].replace("/", "_")))
module_spec = importlib.util.spec_from_file_location(module_name, module_path)
module = importlib.util.module_from_spec(module_spec)
sys.modules[module_name] = module
module_spec.loader.exec_module(module)
else:
module = importlib.import_module(module_path)