Skip to content

Commit

Permalink
indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Nov 29, 2024
1 parent 589da74 commit a21f19a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions flopy/mf6/utils/codegen/templates/exchange.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Modflow{{ title }}(MFPackage):

Parameters
----------
{{ macros.vars_docs(vars, indent=4) }}
{{ macros.vars_docs(vars)|indent(4, first=true) }}
"""

{% for attr in vars|attrs %}
Expand All @@ -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, skip=name|skip_init)|indent(8, first=true) }}
filename=None,
pname=None,
**kwargs,
Expand Down Expand Up @@ -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, first=true) }}
"""

super().__init__(
Expand Down
16 changes: 8 additions & 8 deletions flopy/mf6/utils/codegen/templates/macros.jinja
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{% macro init_vars(vars, alias=false, indent=0, skip=none) %}
{% macro init_vars(vars, alias=false, skip=none) %}
{% 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=true) }}{{ n }}{% if v.default is defined %}={{ v.default|value }}{% endif %},
{{ n }}{% if v.default is defined %}={{ v.default|value }}{% endif %},
{% endfor %}
{% endmacro %}

{% macro vars_docs(vars, indent=0, recurse=true) %}
{% macro vars_docs(vars, recurse=true) %}
{% for var in vars.values() recursive %}
{% set v = var|untag %}
{% set n = v.name|safe_name|escape_trailing_underscore %}
{{ ""|indent(indent, first=true) }}{% if loop.depth > 1 %}* {% endif %}{{ n }} : {{ v|type }}
{% if loop.depth > 1 %}* {% endif %}{{ n }} : {{ v|type }}
{% if v.description is defined and v.description is not none %}
{{ v.description|wordwrap|indent(indent + (loop.depth * 4), first=true) }}
{{ v.description|wordwrap|indent(loop.depth * 4, first=true) }}
{% endif %}
{% 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) }}
{% if v.type == "list" and v.children|length == 1 and (v.children.values()|first).type in ["record", "union"] %}
{{ loop((v.children.values()|first).children.values())|indent(loop.depth * 4, first=true) }}
{% else %}
{{ loop(v.children.values())|indent(indent, first=true) }}
{{ loop(v.children.values())|indent(loop.depth * 4, first=true) }}
{% endif %}
{% endif %}
{% endfor %}
Expand Down
6 changes: 3 additions & 3 deletions flopy/mf6/utils/codegen/templates/model.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Modflow{{ title }}(MFModel):

Parameters
----------
{{ macros.vars_docs(vars, indent=4) }}
{{ macros.vars_docs(vars)|indent(4, first=true) }}

Methods
-------
Expand All @@ -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, skip=name|skip_init)|indent(8, first=true) }}
**kwargs,
):
"""
Expand All @@ -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, first=true) }}
"""

super().__init__(
Expand Down
10 changes: 5 additions & 5 deletions flopy/mf6/utils/codegen/templates/package.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Modflow{{ title }}(MFPackage):

Parameters
----------
{{ macros.vars_docs(vars, indent=4) }}
{{ macros.vars_docs(vars)|indent(4, first=true) }}
"""

{% for attr in vars|attrs %}
Expand All @@ -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, skip=name|skip_init)|indent(8, first=true) }}
filename=None,
pname=None,
**kwargs,
Expand All @@ -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, first=true) }}

filename : str
File name for this package.
Expand Down Expand Up @@ -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, skip=name|skip_init)|indent(8, first=true) }}
filename=None,
pname=None,
):
Expand All @@ -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, skip=name|skip_init)|indent(8, first=true) }}
filename=None,
pname=None,
):
Expand Down
6 changes: 3 additions & 3 deletions flopy/mf6/utils/codegen/templates/simulation.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MF{{ title }}(MFSimulationBase):

Parameters
----------
{{ macros.vars_docs(vars, indent=4) }}
{{ macros.vars_docs(vars)|indent(4, first=true) }}

Methods
-------
Expand All @@ -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, skip=name|skip_init)|indent(8, first=true) }}
):
"""
{{ name|description }}
Expand Down Expand Up @@ -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, first=true) }}
"""

super().__init__(
Expand Down

0 comments on commit a21f19a

Please sign in to comment.