Browse Source

Merge pull request #21 from Learnware-LAMDA/fix_learnware_import_path

[MNT] do not add learnware path to sys.path
tags/v0.3.2
Gene GitHub 2 years ago
parent
commit
8a2ef257c1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 14 deletions
  1. +3
    -1
      examples/dataset_pfs_workflow/pfs/pfs_cross_transfer.py
  2. +0
    -12
      learnware/utils.py
  3. +1
    -1
      tests/test_learnware_client/test_load_docker.py

+ 3
- 1
examples/dataset_pfs_workflow/pfs/pfs_cross_transfer.py View File

@@ -85,7 +85,9 @@ def get_split_errs(algo):
split = train_xs.shape[0] - proportion_list[tmp]
model.fit(
train_xs[split:,],
train_xs[
split:,
],
train_ys[split:],
eval_set=[(val_xs, val_ys)],
early_stopping_rounds=50,


+ 0
- 12
learnware/utils.py View File

@@ -21,23 +21,11 @@ def get_module_by_module_path(module_path: Union[str, ModuleType]):
module = module_path
else:
if module_path.endswith(".py"):
module_parent_path = os.path.dirname(module_path)
delete_parent_path = False
if module_parent_path not in sys.path:
sys.path.append(module_parent_path)
delete_parent_path = True
pass

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)

if delete_parent_path:
sys.path.remove(module_parent_path)
pass
pass
else:
module = importlib.import_module(module_path)
return module


+ 1
- 1
tests/test_learnware_client/test_load_docker.py View File

@@ -7,7 +7,7 @@ import learnware
from learnware.learnware import get_learnware_from_dirpath
from learnware.client import LearnwareClient
from learnware.client.container import ModelCondaContainer, LearnwaresContainer
from learnware.learnware.reuse import AveragingReuser
from learnware.reuse import AveragingReuser


class TestLearnwareLoad(unittest.TestCase):


Loading…
Cancel
Save