From 4d1730896da39e6d8df802df9d3dc0c98b948ef3 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Sun, 28 Sep 2025 15:26:42 -0400 Subject: [PATCH 1/3] fix(codegen): fix recarray variable docstring rendering --- flopy/mf6/utils/codegen/filters.py | 6 +++++- flopy/mf6/utils/codegen/templates/macros.jinja | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/flopy/mf6/utils/codegen/filters.py b/flopy/mf6/utils/codegen/filters.py index a2731c30d4..efc9067af3 100644 --- a/flopy/mf6/utils/codegen/filters.py +++ b/flopy/mf6/utils/codegen/filters.py @@ -205,9 +205,13 @@ def type(var: dict) -> str: def children(var: dict) -> Optional[dict]: _type = var["type"] - items = var.get("items", None) # TODO: fix to use "item" or "items" + item = var.get("item", None) + items = var.get("items", None) fields = var.get("fields", None) choices = var.get("choices", None) + if item: + assert _type == "recarray" + return {item["name"]: item} if items: assert _type == "recarray" return items diff --git a/flopy/mf6/utils/codegen/templates/macros.jinja b/flopy/mf6/utils/codegen/templates/macros.jinja index 29c8a17248..4468761538 100644 --- a/flopy/mf6/utils/codegen/templates/macros.jinja +++ b/flopy/mf6/utils/codegen/templates/macros.jinja @@ -16,9 +16,12 @@ {{ v.description|clean|math|wordwrap|indent(loop.depth * 4, first=true) }} {% endif %} {% if recurse and children is not none %} -{% if v.type == "list" and children|length == 1 and (children.values()|first).type in ["record", "union"] %} +{% if v.type == "recarray" and children|length == 1 and (children.values()|first).name == v.name and (children.values()|first).type in ["record", "keystring"] %} +{# For recarray with single record item of same name, show the record's fields directly #} {% set grandchildren = (children.values()|first)|children %} +{% if grandchildren %} {{ loop(grandchildren.values())|indent(loop.depth * 4, first=true) }} +{% endif %} {% else %} {{ loop(children.values())|indent(loop.depth * 4, first=true) }} {% endif %} From 825b9348a92d0d76bda2246fdb8f46a2c15fdaaf Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Sun, 28 Sep 2025 17:21:49 -0400 Subject: [PATCH 2/3] remove unused code --- flopy/mf6/utils/codegen/filters.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/flopy/mf6/utils/codegen/filters.py b/flopy/mf6/utils/codegen/filters.py index efc9067af3..037a9d9f67 100644 --- a/flopy/mf6/utils/codegen/filters.py +++ b/flopy/mf6/utils/codegen/filters.py @@ -206,15 +206,11 @@ def type(var: dict) -> str: def children(var: dict) -> Optional[dict]: _type = var["type"] item = var.get("item", None) - items = var.get("items", None) fields = var.get("fields", None) choices = var.get("choices", None) if item: assert _type == "recarray" return {item["name"]: item} - if items: - assert _type == "recarray" - return items if fields: assert _type == "record" return fields From 9f1817147584061fa8c4fa26e02f30aaaaebc135 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Sun, 28 Sep 2025 19:48:47 -0400 Subject: [PATCH 3/3] avoid syrupy upgrade --- etc/environment.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/environment.yml b/etc/environment.yml index 13597bb10d..9e1fc34b8a 100644 --- a/etc/environment.yml +++ b/etc/environment.yml @@ -40,7 +40,7 @@ dependencies: - pytest-dotenv - pytest-xdist - pyzmq>=25.1.2 - - syrupy + - syrupy<5.0.0 - virtualenv # optional diff --git a/pyproject.toml b/pyproject.toml index bf6b704a0b..be5c8da9ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ test = [ "pytest-dotenv", "pytest-xdist", "pyzmq >=25.1.2", - "syrupy", + "syrupy <5.0.0", "tomli", "tomli-w", "virtualenv"