Skip to content

Commit

Permalink
add params macro
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Oct 31, 2024
1 parent 13e7d5f commit 44f5db4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
5 changes: 2 additions & 3 deletions flopy/mf6/utils/codegen/templates/exchange.py.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% import 'macros.jinja' as macros %}
# autogenerated file, do not modify

from os import PathLike, curdir
from typing import Union
Expand Down Expand Up @@ -26,9 +27,7 @@ class Modflow{{ name.title.title() }}(MFPackage):
exgtype="{{ name.r[:3].upper() }}6-{{ name.r[3:].upper() }}6",
exgmnamea=None,
exgmnameb=None,
{%- for n, var in vars.items() if n not in init_skip %}
{{ var.name }}{%- if var.default is defined %}={{ var.default }}{%- endif -%},
{%- endfor %}
{{ macros.vars_params(vars, init_skip, start_indent=8) }}
filename=None,
pname=None,
**kwargs,
Expand Down
6 changes: 6 additions & 0 deletions flopy/mf6/utils/codegen/templates/macros.jinja
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{% macro vars_params(vars, init_skip=none, start_indent=0) %}
{%- for n, var in vars.items() if n not in init_skip %}
{{ ""|indent(start_indent, first=true) }}{{ var.name }}{%- if var.default is defined %}={{ var.default }}{% endif -%},
{%- endfor %}
{% endmacro %}

{% macro vars_docs(vars, start_indent=0) %}
{%- for v in vars.values() recursive %}
{{ ""|indent(start_indent, first=true) }}{% if loop.depth > 1 %}* {% endif %}{% if v.name|last == "_" %}{{ v.name.replace("_", "\\\_") }}{% else %}{{ v.name }}{% endif %}{% if v.meta is defined and v.meta.type is defined %} : {{ v.meta.type }}{% endif %}
Expand Down
5 changes: 2 additions & 3 deletions flopy/mf6/utils/codegen/templates/model.py.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% import 'macros.jinja' as macros %}
# autogenerated file, do not modify

from os import PathLike, curdir
from typing import Union
Expand Down Expand Up @@ -33,9 +34,7 @@ class Modflow{{ name.title.title() }}(MFModel):
version="mf6",
exe_name="mf6",
model_rel_path=".",
{%- for n, var in vars.items() if n not in init_skip %}
{{ var.name }}{%- if var.default is defined %}={{ var.default }}{%- endif -%},
{%- endfor %}
{{ macros.vars_params(vars, init_skip, start_indent=8) }}
**kwargs,
):
"""
Expand Down
21 changes: 6 additions & 15 deletions flopy/mf6/utils/codegen/templates/package.py.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% import 'macros.jinja' as macros %}
# autogenerated file, do not modify

from os import PathLike, curdir
from typing import Union
Expand All @@ -24,9 +25,7 @@ class Modflow{{ name.title.title() }}(MFPackage):
self,
{{ parent }},
loading_package=False,
{%- for n, var in vars.items() if n not in init_skip %}
{{ var.name }}{%- if var.default is defined %}={{ var.default }}{%- endif -%},
{%- endfor %}
{{ macros.vars_params(vars, init_skip, start_indent=8) }}
filename=None,
pname=None,
**kwargs,
Expand Down Expand Up @@ -95,17 +94,13 @@ class {{ name.title.title() }}Packages(MFChildPackages):

def initialize(
self,
{%- for n, var in vars.items() if n not in init_skip %}
{{ n }}{%- if var.default is defined %}={{ var.default }}{% endif -%},
{%- endfor %}
{{ macros.vars_params(vars, init_skip, start_indent=8) }}
filename=None,
pname=None,
):
new_package = Modflow{{ name.title.title() }}(
self._cpparent,
{%- for n, var in vars.items() if n not in init_skip %}
{{ n }}={{ n }},
{%- endfor %}
{{ macros.vars_params(vars, init_skip, start_indent=12) }}
filename=filename,
pname=pname,
child_builder_call=True,
Expand All @@ -115,17 +110,13 @@ class {{ name.title.title() }}Packages(MFChildPackages):
{% if name.r != "obs" %}
def append_package(
self,
{%- for n, var in vars.items() if n not in init_skip %}
{{ n }}{%- if var.default is defined %}={{ var.default }}{% endif -%},
{%- endfor %}
{{ macros.vars_params(vars, init_skip, start_indent=8) }}
filename=None,
pname=None,
):
new_package = Modflow{{ name.title.title() }}(
self._cpparent,
{%- for n, var in vars.items() if n not in init_skip %}
{{ n }}={{ n }},
{%- endfor %}
{{ macros.vars_params(vars, init_skip, start_indent=12) }}
filename=filename,
pname=pname,
child_builder_call=True,
Expand Down
5 changes: 2 additions & 3 deletions flopy/mf6/utils/codegen/templates/simulation.py.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% import 'macros.jinja' as macros %}
# autogenerated file, do not modify

from os import PathLike, curdir
from typing import Union
Expand Down Expand Up @@ -34,9 +35,7 @@ class MF{{ name.title.title() }}(MFSimulationBase):
write_headers: bool = True,
use_pandas: bool = True,
lazy_io: bool = False,
{%- for n, var in vars.items() if n not in init_skip %}
{{ var.name }}{%- if var.default is defined %}={{ var.default }}{%- endif -%},
{%- endfor %}
{{ macros.vars_params(vars, init_skip, start_indent=8) }}
):
"""
{{ name.description }}
Expand Down

0 comments on commit 44f5db4

Please sign in to comment.