diff --git a/flopy/mf6/utils/codegen/filters.py b/flopy/mf6/utils/codegen/filters.py index 201db7395..9d19f18d6 100644 --- a/flopy/mf6/utils/codegen/filters.py +++ b/flopy/mf6/utils/codegen/filters.py @@ -153,9 +153,10 @@ def type(var: dict) -> str: children = var.get("children", None) if children: if _type == "list": - import pdb; pdb.set_trace() - if len(children) == 1 and (first := list(children.values())[0])["type"] == "record": - return f"{Filters.Var.type(first)}" + if len(children) == 1: + first = list(children.values())[0] + if first["type"] in ["record", "union"]: + return f"[{Filters.Var.type(first)}]" children = ", ".join( [v["name"] for v in children.values()] ) diff --git a/flopy/mf6/utils/codegen/templates/exchange.py.jinja b/flopy/mf6/utils/codegen/templates/exchange.py.jinja index d95a831c5..998728680 100644 --- a/flopy/mf6/utils/codegen/templates/exchange.py.jinja +++ b/flopy/mf6/utils/codegen/templates/exchange.py.jinja @@ -13,7 +13,7 @@ class Modflow{{ title }}(MFPackage): Parameters ---------- - {{ macros.vars_docs(vars, indent=4) }} +{{ macros.vars_docs(vars, indent=4) }} """ {% for attr in vars|attrs %} @@ -27,7 +27,7 @@ class Modflow{{ title }}(MFPackage): exgtype="{{ name.r[:3].upper() }}6-{{ name.r[3:].upper() }}6", exgmnamea=None, exgmnameb=None, - {{ macros.init_vars(vars, indent=8, skip=name|skip_init) }} +{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }} filename=None, pname=None, **kwargs, @@ -64,7 +64,7 @@ class Modflow{{ title }}(MFPackage): GWE Model with the name exgmnameb must correspond to the GWF Model with the name gwfmodelname2. - {{ macros.vars_docs(vars, indent=8) }} +{{ macros.vars_docs(vars, indent=8) }} """ super().__init__( diff --git a/flopy/mf6/utils/codegen/templates/macros.jinja b/flopy/mf6/utils/codegen/templates/macros.jinja index 5dd6ea7a2..6e567fc39 100644 --- a/flopy/mf6/utils/codegen/templates/macros.jinja +++ b/flopy/mf6/utils/codegen/templates/macros.jinja @@ -2,11 +2,11 @@ {% for name, var in vars.items() if name not in skip %} {% set v = var|untag %} {% set n = (name if alias else v.name)|safe_name %} -{{ ""|indent(indent, first=false) }}{{ n }}{% if v.default is defined %}={{ v.default|value }}{% endif %}, +{{ ""|indent(indent, first=true) }}{{ n }}{% if v.default is defined %}={{ v.default|value }}{% endif %}, {% endfor %} {% endmacro %} -{% macro vars_docs(vars, indent=0) %} +{% macro vars_docs(vars, indent=0, recurse=true) %} {% for var in vars.values() recursive %} {% set v = var|untag %} {% set n = v.name|safe_name|escape_trailing_underscore %} @@ -14,12 +14,12 @@ {% if v.description is defined and v.description is not none %} {{ v.description|wordwrap|indent(indent + (loop.depth * 4), first=true) }} {% endif %} -{% if v.children is defined and v.children is not none %} -{% if v.type == "list" and v.childen|length == 1 and (v.children.values()|first).type == "record" %} +{% if recurse and v.children is defined and v.children is not none %} +{% if v.type == "list" and v.children|length == 1 and (v.children.values()|first).type == "record" %} {{ loop((v.children.values()|first).children.values())|indent(indent, first=true) }} {% else %} {{ loop(v.children.values())|indent(indent, first=true) }} {% endif %} {% endif %} {% endfor %} -{% endmacro %} \ No newline at end of file +{% endmacro %} diff --git a/flopy/mf6/utils/codegen/templates/model.py.jinja b/flopy/mf6/utils/codegen/templates/model.py.jinja index b9d1bfa48..89e072ce5 100644 --- a/flopy/mf6/utils/codegen/templates/model.py.jinja +++ b/flopy/mf6/utils/codegen/templates/model.py.jinja @@ -14,7 +14,7 @@ class Modflow{{ title }}(MFModel): Parameters ---------- - {{ macros.vars_docs(vars, indent=4) }} +{{ macros.vars_docs(vars, indent=4) }} Methods ------- @@ -34,7 +34,7 @@ class Modflow{{ title }}(MFModel): version="mf6", exe_name="mf6", model_rel_path=".", - {{ macros.init_vars(vars, indent=8, skip=name|skip_init) }} +{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }} **kwargs, ): """ @@ -61,7 +61,7 @@ class Modflow{{ title }}(MFModel): Simulation that this model is a part of. Model is automatically added to simulation when it is initialized. - {{ macros.vars_docs(vars, indent=8) }} +{{ macros.vars_docs(vars, indent=8) }} """ super().__init__( diff --git a/flopy/mf6/utils/codegen/templates/package.py.jinja b/flopy/mf6/utils/codegen/templates/package.py.jinja index b0ce7c603..fc2bf0ebe 100644 --- a/flopy/mf6/utils/codegen/templates/package.py.jinja +++ b/flopy/mf6/utils/codegen/templates/package.py.jinja @@ -25,7 +25,7 @@ class Modflow{{ title }}(MFPackage): self, {{ name|parent }}, loading_package=False, - {{ macros.init_vars(vars, indent=8, skip=name|skip_init) }} +{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }} filename=None, pname=None, **kwargs, @@ -43,7 +43,7 @@ class Modflow{{ title }}(MFPackage): Do not set this parameter. It is intended for debugging and internal processing purposes only. - {{ macros.vars_docs(vars, indent=8) }} +{{ macros.vars_docs(vars, indent=8) }} filename : str File name for this package. @@ -94,7 +94,7 @@ class {{ title }}Packages(MFChildPackages): def initialize( self, - {{ macros.init_vars(vars, alias=true, indent=8, skip=name|skip_init) }} +{{ macros.init_vars(vars, alias=true, indent=8, skip=name|skip_init) }} filename=None, pname=None, ): @@ -112,7 +112,7 @@ class {{ title }}Packages(MFChildPackages): {% if name.r != "obs" %} def append_package( self, - {{ macros.init_vars(vars, alias=true, indent=8, skip=name|skip_init) }} +{{ macros.init_vars(vars, alias=true, indent=8, skip=name|skip_init) }} filename=None, pname=None, ): diff --git a/flopy/mf6/utils/codegen/templates/simulation.py.jinja b/flopy/mf6/utils/codegen/templates/simulation.py.jinja index 446c1bc8b..d50df39aa 100644 --- a/flopy/mf6/utils/codegen/templates/simulation.py.jinja +++ b/flopy/mf6/utils/codegen/templates/simulation.py.jinja @@ -13,7 +13,7 @@ class MF{{ title }}(MFSimulationBase): Parameters ---------- - {{ macros.vars_docs(vars, indent=4) }} +{{ macros.vars_docs(vars, indent=4) }} Methods ------- @@ -35,7 +35,7 @@ class MF{{ title }}(MFSimulationBase): write_headers: bool = True, use_pandas: bool = True, lazy_io: bool = False, - {{ macros.init_vars(vars, indent=8, skip=name|skip_init) }} +{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }} ): """ {{ name|description }} @@ -66,7 +66,7 @@ class MF{{ title }}(MFSimulationBase): lazy_io Whether to use lazy IO - {{ macros.vars_docs(vars, indent=8) }} +{{ macros.vars_docs(vars, indent=8) }} """ super().__init__(