diff --git a/pysd/py_backend/builder.py b/pysd/py_backend/builder.py index eb1fbf64..89ce584e 100644 --- a/pysd/py_backend/builder.py +++ b/pysd/py_backend/builder.py @@ -296,13 +296,12 @@ 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", submodules=[])) + exec(load_modules("modules_%(outfile)s", _modules, _root, [])) """ % { "outfile": os.path.basename(file_name).split(".")[0], }) + print(text) text += funcs text = black.format_file_contents(text, fast=True, mode=black.FileMode()) diff --git a/pysd/py_backend/utils.py b/pysd/py_backend/utils.py index 12fc8b46..5947bf15 100644 --- a/pysd/py_backend/utils.py +++ b/pysd/py_backend/utils.py @@ -889,21 +889,18 @@ def open_module(root_dir, model_name, module, submodule=None): os.path.join(root_dir, "modules_" + model_name, rel_file_path)).read() -def load_modules(module_name, module_content, root_dir, model_name, - work_dir=None, submodules=[]): +def load_modules(module_name, module_content, work_dir, submodules): # TODO: document - if not work_dir: - work_dir = os.path.join(root_dir, "modules_" + model_name) if isinstance(module_content, list): 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(): load_modules( - submod_name, submod_content, root_dir, model_name, - work_dir=work_dir, submodules=submodules) + submod_name, submod_content, + os.path.join(work_dir, module_name), + submodules) return "\n\n".join(submodules)