Skip to content

Commit 3979c4b

Browse files
committed
better composite variable docstring format
1 parent 71feaa6 commit 3979c4b

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

flopy/mf6/utils/codegen/filters.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ def type(var: dict) -> str:
153153
children = var.get("children", None)
154154
if children:
155155
if _type == "list":
156-
import pdb; pdb.set_trace()
157-
if len(children) == 1 and (first := list(children.values())[0])["type"] == "record":
158-
return f"{Filters.Var.type(first)}"
156+
if len(children) == 1:
157+
first = list(children.values())[0]
158+
if first["type"] in ["record", "union"]:
159+
return f"[{Filters.Var.type(first)}]"
159160
children = ", ".join(
160161
[v["name"] for v in children.values()]
161162
)

flopy/mf6/utils/codegen/templates/exchange.py.jinja

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Modflow{{ title }}(MFPackage):
1313

1414
Parameters
1515
----------
16-
{{ macros.vars_docs(vars, indent=4) }}
16+
{{ macros.vars_docs(vars, indent=4) }}
1717
"""
1818

1919
{% for attr in vars|attrs %}
@@ -27,7 +27,7 @@ class Modflow{{ title }}(MFPackage):
2727
exgtype="{{ name.r[:3].upper() }}6-{{ name.r[3:].upper() }}6",
2828
exgmnamea=None,
2929
exgmnameb=None,
30-
{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }}
30+
{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }}
3131
filename=None,
3232
pname=None,
3333
**kwargs,
@@ -64,7 +64,7 @@ class Modflow{{ title }}(MFPackage):
6464
GWE Model with the name exgmnameb must correspond to the GWF Model
6565
with the name gwfmodelname2.
6666

67-
{{ macros.vars_docs(vars, indent=8) }}
67+
{{ macros.vars_docs(vars, indent=8) }}
6868
"""
6969

7070
super().__init__(

flopy/mf6/utils/codegen/templates/macros.jinja

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
{% for name, var in vars.items() if name not in skip %}
33
{% set v = var|untag %}
44
{% set n = (name if alias else v.name)|safe_name %}
5-
{{ ""|indent(indent, first=false) }}{{ n }}{% if v.default is defined %}={{ v.default|value }}{% endif %},
5+
{{ ""|indent(indent, first=true) }}{{ n }}{% if v.default is defined %}={{ v.default|value }}{% endif %},
66
{% endfor %}
77
{% endmacro %}
88

9-
{% macro vars_docs(vars, indent=0) %}
9+
{% macro vars_docs(vars, indent=0, recurse=true) %}
1010
{% for var in vars.values() recursive %}
1111
{% set v = var|untag %}
1212
{% set n = v.name|safe_name|escape_trailing_underscore %}
1313
{{ ""|indent(indent, first=true) }}{% if loop.depth > 1 %}* {% endif %}{{ n }} : {{ v|type }}
1414
{% if v.description is defined and v.description is not none %}
1515
{{ v.description|wordwrap|indent(indent + (loop.depth * 4), first=true) }}
1616
{% endif %}
17-
{% if v.children is defined and v.children is not none %}
18-
{% if v.type == "list" and v.childen|length == 1 and (v.children.values()|first).type == "record" %}
17+
{% if recurse and v.children is defined and v.children is not none %}
18+
{% if v.type == "list" and v.children|length == 1 and (v.children.values()|first).type == "record" %}
1919
{{ loop((v.children.values()|first).children.values())|indent(indent, first=true) }}
2020
{% else %}
2121
{{ loop(v.children.values())|indent(indent, first=true) }}
2222
{% endif %}
2323
{% endif %}
2424
{% endfor %}
25-
{% endmacro %}
25+
{% endmacro %}

flopy/mf6/utils/codegen/templates/model.py.jinja

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Modflow{{ title }}(MFModel):
1414

1515
Parameters
1616
----------
17-
{{ macros.vars_docs(vars, indent=4) }}
17+
{{ macros.vars_docs(vars, indent=4) }}
1818

1919
Methods
2020
-------
@@ -34,7 +34,7 @@ class Modflow{{ title }}(MFModel):
3434
version="mf6",
3535
exe_name="mf6",
3636
model_rel_path=".",
37-
{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }}
37+
{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }}
3838
**kwargs,
3939
):
4040
"""
@@ -61,7 +61,7 @@ class Modflow{{ title }}(MFModel):
6161
Simulation that this model is a part of. Model is automatically
6262
added to simulation when it is initialized.
6363

64-
{{ macros.vars_docs(vars, indent=8) }}
64+
{{ macros.vars_docs(vars, indent=8) }}
6565
"""
6666

6767
super().__init__(

flopy/mf6/utils/codegen/templates/package.py.jinja

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Modflow{{ title }}(MFPackage):
2525
self,
2626
{{ name|parent }},
2727
loading_package=False,
28-
{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }}
28+
{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }}
2929
filename=None,
3030
pname=None,
3131
**kwargs,
@@ -43,7 +43,7 @@ class Modflow{{ title }}(MFPackage):
4343
Do not set this parameter. It is intended for debugging and internal
4444
processing purposes only.
4545

46-
{{ macros.vars_docs(vars, indent=8) }}
46+
{{ macros.vars_docs(vars, indent=8) }}
4747

4848
filename : str
4949
File name for this package.
@@ -94,7 +94,7 @@ class {{ title }}Packages(MFChildPackages):
9494

9595
def initialize(
9696
self,
97-
{{ macros.init_vars(vars, alias=true, indent=8, skip=name|skip_init) }}
97+
{{ macros.init_vars(vars, alias=true, indent=8, skip=name|skip_init) }}
9898
filename=None,
9999
pname=None,
100100
):
@@ -112,7 +112,7 @@ class {{ title }}Packages(MFChildPackages):
112112
{% if name.r != "obs" %}
113113
def append_package(
114114
self,
115-
{{ macros.init_vars(vars, alias=true, indent=8, skip=name|skip_init) }}
115+
{{ macros.init_vars(vars, alias=true, indent=8, skip=name|skip_init) }}
116116
filename=None,
117117
pname=None,
118118
):

flopy/mf6/utils/codegen/templates/simulation.py.jinja

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class MF{{ title }}(MFSimulationBase):
1313

1414
Parameters
1515
----------
16-
{{ macros.vars_docs(vars, indent=4) }}
16+
{{ macros.vars_docs(vars, indent=4) }}
1717

1818
Methods
1919
-------
@@ -35,7 +35,7 @@ class MF{{ title }}(MFSimulationBase):
3535
write_headers: bool = True,
3636
use_pandas: bool = True,
3737
lazy_io: bool = False,
38-
{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }}
38+
{{ macros.init_vars(vars, indent=8, skip=name|skip_init) }}
3939
):
4040
"""
4141
{{ name|description }}
@@ -66,7 +66,7 @@ class MF{{ title }}(MFSimulationBase):
6666
lazy_io
6767
Whether to use lazy IO
6868

69-
{{ macros.vars_docs(vars, indent=8) }}
69+
{{ macros.vars_docs(vars, indent=8) }}
7070
"""
7171

7272
super().__init__(

0 commit comments

Comments
 (0)