Skip to content

Commit 4d68575

Browse files
committed
cleanup
1 parent b4d20a5 commit 4d68575

File tree

149 files changed

+1175
-1059
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+1175
-1059
lines changed

flopy4/mf6/codec/reader/dfn2lark.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def generate(dfndir: PathLike, outdir: PathLike):
1919
outdir.mkdir(exist_ok=True, parents=True)
2020
dfns_v1 = load_flat(dfndir)
2121
dfns_v2 = {name: map(dfn, schema_version=2) for name, dfn in dfns_v1.items()}
22-
# TODO fix devtools v1 -> v2 map, it's not converting the field type
2322
make_all_grammars(dfns_v2, outdir)
2423

2524

flopy4/mf6/codec/reader/grammar/__init__.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,14 @@ def _get_template_env():
2020
return env
2121

2222

23-
def _compute_block_metadata(blocks):
24-
"""Pre-compute block metadata for template rendering."""
25-
blocks_list = []
26-
all_fields = {} # Collect all unique fields
23+
def _get_template_data(blocks) -> tuple[list[dict], dict[str, object]]:
24+
all_blocks = []
25+
all_fields = {}
2726

2827
for block_name, block_fields in blocks.items():
2928
period_groups = filters.group_period_fields(block_fields)
3029
has_index = block_name == "period"
3130

32-
# Build recarrays list
3331
recarrays = []
3432
grouped_field_names = set()
3533
if period_groups:
@@ -38,14 +36,11 @@ def _compute_block_metadata(blocks):
3836
recarrays.append({"name": recarray_name, "fields": field_names})
3937
grouped_field_names.update(field_names)
4038

41-
# Get standalone fields (not in any recarray)
4239
all_field_names = list(block_fields.keys())
4340
standalone_fields = [f for f in all_field_names if f not in grouped_field_names]
4441

45-
# Collect field objects
4642
all_fields.update(block_fields)
47-
48-
blocks_list.append(
43+
all_blocks.append(
4944
{
5045
"name": block_name,
5146
"has_index": has_index,
@@ -54,7 +49,7 @@ def _compute_block_metadata(blocks):
5449
}
5550
)
5651

57-
return blocks_list, all_fields
52+
return all_blocks, all_fields
5853

5954

6055
def make_grammar(dfn: Dfn, outdir: PathLike):
@@ -63,13 +58,10 @@ def make_grammar(dfn: Dfn, outdir: PathLike):
6358
env = _get_template_env()
6459
template = env.get_template("component.lark.jinja")
6560
target_path = outdir / f"{dfn.name}.lark"
66-
67-
# Pre-compute block metadata and collect all fields
68-
blocks_list, fields = _compute_block_metadata(dfn.blocks)
69-
61+
blocks, fields = _get_template_data(dfn.blocks)
7062
with open(target_path, "w") as f:
7163
name = dfn.name
72-
f.write(template.render(name=name, blocks=blocks_list, fields=fields))
64+
f.write(template.render(name=name, blocks=blocks, fields=fields))
7365

7466

7567
def make_all_grammars(dfns: dict[str, Dfn], outdir: PathLike):

flopy4/mf6/codec/reader/grammar/filters.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ def record_child_type(field: FieldV2) -> str:
3030
return field.type
3131

3232

33-
def keystring_children(field: FieldV2) -> dict:
34-
"""Get the children of a keystring field for union generation."""
35-
return {} if field.type != "union" else field.children
36-
37-
3833
def is_period_list_field(field: FieldV2) -> bool:
3934
"""Check if a field is part of a period block list/recarray."""
4035
if not field.shape or not field.block:
@@ -75,17 +70,3 @@ def get_recarray_name(block_name: str) -> str:
7570
if block_name == "period":
7671
return "stress_period_data"
7772
return f"{block_name}data"
78-
79-
80-
def get_all_grouped_field_names(blocks: Mapping[str, Mapping[str, FieldV2]]) -> set[str]:
81-
"""
82-
Get all field names that are grouped into recarrays across all blocks.
83-
84-
Returns a set of field names that should not have individual rules generated.
85-
"""
86-
grouped = set()
87-
for block_fields in blocks.values():
88-
period_groups = group_period_fields(block_fields)
89-
for field_list in period_groups.values():
90-
grouped.update(field_list)
91-
return grouped

flopy4/mf6/codec/reader/grammar/generated/chf-cdb.lark

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// Auto-generated grammar for MF6 CHF-CDB
2+
3+
%import typed.integer -> integer
4+
%import typed.double -> double
5+
%import typed.number -> number
6+
%import typed.string -> string
7+
%import typed.array -> array
8+
%import typed.record -> record
9+
%import typed.NEWLINE -> NEWLINE
210
%import common.WS
311
%import common.SH_COMMENT
412

@@ -22,10 +30,3 @@ save_flows: "save_flows"i
2230
obs_filerecord: "filein"i "obs6"i string
2331
maxbound: "maxbound"i integer
2432
stress_period_data: record+
25-
%import typed.integer -> integer
26-
%import typed.double -> double
27-
%import typed.number -> number
28-
%import typed.string -> string
29-
%import typed.array -> array
30-
%import typed.record -> record
31-
%import typed.NEWLINE -> NEWLINE

flopy4/mf6/codec/reader/grammar/generated/chf-chd.lark

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// Auto-generated grammar for MF6 CHF-CHD
2+
3+
%import typed.integer -> integer
4+
%import typed.double -> double
5+
%import typed.number -> number
6+
%import typed.string -> string
7+
%import typed.array -> array
8+
%import typed.record -> record
9+
%import typed.NEWLINE -> NEWLINE
210
%import common.WS
311
%import common.SH_COMMENT
412

@@ -24,10 +32,3 @@ ts_filerecord: "ts6"i "filein"i string
2432
obs_filerecord: "filein"i "obs6"i string
2533
maxbound: "maxbound"i integer
2634
stress_period_data: record+
27-
%import typed.integer -> integer
28-
%import typed.double -> double
29-
%import typed.number -> number
30-
%import typed.string -> string
31-
%import typed.array -> array
32-
%import typed.record -> record
33-
%import typed.NEWLINE -> NEWLINE

flopy4/mf6/codec/reader/grammar/generated/chf-cxs.lark

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// Auto-generated grammar for MF6 CHF-CXS
2+
3+
%import typed.integer -> integer
4+
%import typed.double -> double
5+
%import typed.number -> number
6+
%import typed.string -> string
7+
%import typed.array -> array
8+
%import typed.record -> record
9+
%import typed.NEWLINE -> NEWLINE
210
%import common.WS
311
%import common.SH_COMMENT
412

@@ -20,10 +28,3 @@ nsections: "nsections"i integer
2028
npoints: "npoints"i integer
2129
packagedata: "packagedata"i recarray
2230
crosssectiondata: "crosssectiondata"i recarray
23-
%import typed.integer -> integer
24-
%import typed.double -> double
25-
%import typed.number -> number
26-
%import typed.string -> string
27-
%import typed.array -> array
28-
%import typed.record -> record
29-
%import typed.NEWLINE -> NEWLINE

flopy4/mf6/codec/reader/grammar/generated/chf-dfw.lark

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// Auto-generated grammar for MF6 CHF-DFW
2+
3+
%import typed.integer -> integer
4+
%import typed.double -> double
5+
%import typed.number -> number
6+
%import typed.string -> string
7+
%import typed.array -> array
8+
%import typed.record -> record
9+
%import typed.NEWLINE -> NEWLINE
210
%import common.WS
311
%import common.SH_COMMENT
412

@@ -22,10 +30,3 @@ export_array_ascii: "export_array_ascii"i
2230
dev_swr_conductance: "dev_swr_conductance"i
2331
manningsn: "manningsn"i array
2432
idcxs: "idcxs"i array
25-
%import typed.integer -> integer
26-
%import typed.double -> double
27-
%import typed.number -> number
28-
%import typed.string -> string
29-
%import typed.array -> array
30-
%import typed.record -> record
31-
%import typed.NEWLINE -> NEWLINE

flopy4/mf6/codec/reader/grammar/generated/chf-disv1d.lark

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// Auto-generated grammar for MF6 CHF-DISV1D
2+
3+
%import typed.integer -> integer
4+
%import typed.double -> double
5+
%import typed.number -> number
6+
%import typed.string -> string
7+
%import typed.array -> array
8+
%import typed.record -> record
9+
%import typed.NEWLINE -> NEWLINE
210
%import common.WS
311
%import common.SH_COMMENT
412

@@ -32,10 +40,3 @@ bottom: "bottom"i array
3240
idomain: "idomain"i array
3341
vertices: "vertices"i recarray
3442
cell1d: "cell1d"i recarray
35-
%import typed.integer -> integer
36-
%import typed.double -> double
37-
%import typed.number -> number
38-
%import typed.string -> string
39-
%import typed.array -> array
40-
%import typed.record -> record
41-
%import typed.NEWLINE -> NEWLINE

flopy4/mf6/codec/reader/grammar/generated/chf-evp.lark

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// Auto-generated grammar for MF6 CHF-EVP
2+
3+
%import typed.integer -> integer
4+
%import typed.double -> double
5+
%import typed.number -> number
6+
%import typed.string -> string
7+
%import typed.array -> array
8+
%import typed.record -> record
9+
%import typed.NEWLINE -> NEWLINE
210
%import common.WS
311
%import common.SH_COMMENT
412

@@ -24,10 +32,3 @@ ts_filerecord: "ts6"i "filein"i string
2432
obs_filerecord: "filein"i "obs6"i string
2533
maxbound: "maxbound"i integer
2634
stress_period_data: record+
27-
%import typed.integer -> integer
28-
%import typed.double -> double
29-
%import typed.number -> number
30-
%import typed.string -> string
31-
%import typed.array -> array
32-
%import typed.record -> record
33-
%import typed.NEWLINE -> NEWLINE

flopy4/mf6/codec/reader/grammar/generated/chf-flw.lark

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// Auto-generated grammar for MF6 CHF-FLW
2+
3+
%import typed.integer -> integer
4+
%import typed.double -> double
5+
%import typed.number -> number
6+
%import typed.string -> string
7+
%import typed.array -> array
8+
%import typed.record -> record
9+
%import typed.NEWLINE -> NEWLINE
210
%import common.WS
311
%import common.SH_COMMENT
412

@@ -24,10 +32,3 @@ ts_filerecord: "ts6"i "filein"i string
2432
obs_filerecord: "filein"i "obs6"i string
2533
maxbound: "maxbound"i integer
2634
stress_period_data: record+
27-
%import typed.integer -> integer
28-
%import typed.double -> double
29-
%import typed.number -> number
30-
%import typed.string -> string
31-
%import typed.array -> array
32-
%import typed.record -> record
33-
%import typed.NEWLINE -> NEWLINE

0 commit comments

Comments
 (0)