Skip to content

Commit

Permalink
Correct memory bug
Browse files Browse the repository at this point in the history
  • Loading branch information
enekomartinmartinez committed Sep 27, 2021
1 parent c47ffdb commit 3d8e2d6
Show file tree
Hide file tree
Showing 4 changed files with 1,583 additions and 1,577 deletions.
3 changes: 2 additions & 1 deletion pysd/py_backend/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ def _build_main_module(elements, subscript_dict, file_name):
text += textwrap.dedent("""
# load modules from modules_%(outfile)s directory
for module_name, module_content in _modules.items():
exec(load_modules(module_name, module_content, _root, "%(outfile)s"))
exec(load_modules(module_name, module_content, _root,
"%(outfile)s", submodules=[]))
""" % {
"outfile": os.path.basename(file_name).split(".")[0],
Expand Down
5 changes: 3 additions & 2 deletions pysd/py_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,12 +891,13 @@ def open_module(root_dir, model_name, module, submodule=None):

def load_modules(module_name, module_content, root_dir, model_name,
work_dir=None, submodules=[]):
# TODO: document
if not work_dir:
work_dir = os.path.join(root_dir, "modules_" + model_name)

if isinstance(module_content, list):
submodules.append(
open(os.path.join(work_dir, module_name + ".py"), "r").read())
with open(os.path.join(work_dir, module_name + ".py"), "r") as file:
submodules.append(file.read())
else:
work_dir = os.path.join(work_dir, module_name)
for submod_name, submod_content in module_content.items():
Expand Down
4 changes: 3 additions & 1 deletion pysd/py_backend/vensim/vensim2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,9 @@ def translate_vensim(mdl_file, split_views, **kwargs):
else: # separate macro elements into their own files
section["py_name"] = utils.make_python_identifier(
section["name"])[0]
section["file_name"] = out_dir + "/" + section["py_name"] + ".py"
section["file_name"] = os.path.join(
out_dir,
section["py_name"] + ".py")

macro_list = [s for s in file_sections if s["name"] != "_main_"]

Expand Down
Loading

0 comments on commit 3d8e2d6

Please sign in to comment.