Skip to content

Commit fab861a

Browse files
authored
Fix reload modules in temporary folders - changes from Siegfried (#253)
1 parent 6e6f489 commit fab861a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pythonfmu/builder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ def update_model_parameters(src: Path, model: Fmi2Slave, newargs: dict) -> str:
122122

123123
init: FunctionType = None
124124
modulename = src.stem
125+
importlib.invalidate_caches()
125126
module = importlib.import_module(modulename)
127+
module = importlib.reload( module) # to avoid that the finder looks in temporary folders previously created
126128

127129
# Find the __init__ function in the module
128130
for name, obj in inspect.getmembers(model):
@@ -241,13 +243,13 @@ def build_FMU(
241243

242244
module_name = script_file.stem
243245
model_class = get_model_class(script_file)
246+
updated_code = update_model_parameters(script_file, model_class, newargs) if newargs else None
244247

245248
with tempfile.TemporaryDirectory(prefix="pythonfmu_") as tempd:
246249
temp_dir = Path(tempd)
247250

248251
if newargs:
249252
model_file = temp_dir / f"{module_name}.py"
250-
updated_code = update_model_parameters(script_file, model_class, newargs)
251253

252254
# Write the updated code to a new file
253255
model_file.write_text(updated_code)

0 commit comments

Comments
 (0)