Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pythonfmu/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def update_model_parameters(src: Path, model: Fmi2Slave, newargs: dict) -> str:

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

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

module_name = script_file.stem
model_class = get_model_class(script_file)
updated_code = update_model_parameters(script_file, model_class, newargs) if newargs else None

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

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

# Write the updated code to a new file
model_file.write_text(updated_code)
Expand Down