Skip to content

Commit 7a14816

Browse files
Fix for unpicklable components
1 parent e07df98 commit 7a14816

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

hwcomponents/find_models.py

100644100755
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,16 @@ def get_models(
227227
logging.info(
228228
f"Loading models from {path}. Errors below are likely due to the model."
229229
)
230-
prev_sys_path = copy.deepcopy(sys.path)
231-
sys.path.append(os.path.dirname(os.path.abspath(path)))
232-
python_module = SourceFileLoader(f"model{n_models}", path).load_module()
230+
abs_dir = os.path.dirname(os.path.abspath(path))
231+
base_name = os.path.splitext(os.path.basename(path))[0]
232+
module_name = f"_hwc_model_{base_name}_{n_models}"
233+
if abs_dir not in sys.path:
234+
sys.path.append(abs_dir)
235+
python_module = SourceFileLoader(module_name, path).load_module()
236+
sys.modules[module_name] = python_module
233237
new_models += get_models_in_module(
234238
python_module, model_ids, _return_wrappers
235239
)
236-
sys.path = prev_sys_path
237240
n_models += 1
238241

239242
if not new_models:

0 commit comments

Comments
 (0)