Skip to content

Commit

Permalink
Add with block to open_module
Browse files Browse the repository at this point in the history
  • Loading branch information
enekomartinmartinez committed Sep 28, 2021
1 parent 2a70275 commit 7f853f9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pysd/py_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,9 @@ def load_model_data(root_dir, model_name):
return namespace, subscripts, modules


def open_module(root_dir, model_name, module, submodule=None):
def open_module(root_dir, model_name, module, submodule=None): # pragma: no cover
"""
This function will be deprecated from release 2.0.
Used to load model modules from the main model file, when
split_views=True in the read_vensim function.
Expand All @@ -873,20 +874,21 @@ def open_module(root_dir, model_name, module, submodule=None):
-------
str:
Model file content.
"""
"""
warnings.warn(
"open_module function will be deprecated from release 2.0. Use "
+ "load_modules instead.",
+ "load_modules instead or translate the model again.",
FutureWarning
)
if not submodule:
rel_file_path = module + ".py"
else:
rel_file_path = os.path.join(module, submodule + ".py")

return open(
os.path.join(root_dir, "modules_" + model_name, rel_file_path)).read()
with open(os.path.join(root_dir, "modules_" + model_name, rel_file_path),
"r") as mod:
return mod.read()


def load_modules(module_name, module_content, work_dir, submodules):
Expand Down Expand Up @@ -922,8 +924,8 @@ def load_modules(module_name, module_content, work_dir, submodules):
"""
if isinstance(module_content, list):
with open(os.path.join(work_dir, module_name + ".py"), "r") as file:
submodules.append(file.read())
with open(os.path.join(work_dir, module_name + ".py"), "r") as mod:
submodules.append(mod.read())
else:
for submod_name, submod_content in module_content.items():
load_modules(
Expand Down

0 comments on commit 7f853f9

Please sign in to comment.