Skip to content

Commit 772a313

Browse files
authored
separate core and mf6 spec (#138)
wrap the field decorators at the top level, then wrap those for mf6. this gives us an independent layer, which right now has nothing over and above attrs/xattree, but I can imagine we might want some shared core options in the future. mf6 and other programs can layer custom decorators on top of this where needed.
1 parent db4b28c commit 772a313

File tree

2 files changed

+98
-8
lines changed

2 files changed

+98
-8
lines changed

flopy4/mf6/spec.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"""
55

66
from attrs import NOTHING, Attribute, fields_dict
7-
from xattree import array as xattree_array
8-
from xattree import coord as xattree_coord
9-
from xattree import dim as xattree_dim
10-
from xattree import field as xattree_field
7+
8+
from flopy4.spec import array as flopy_array
9+
from flopy4.spec import coord as flopy_coord
10+
from flopy4.spec import dim as flopy_dim
11+
from flopy4.spec import field as flopy_field
1112

1213

1314
def field(
@@ -24,7 +25,7 @@ def field(
2425
if block:
2526
metadata = metadata or {}
2627
metadata["block"] = block
27-
return xattree_field(
28+
return flopy_field(
2829
default=default,
2930
validator=validator,
3031
converter=converter,
@@ -49,7 +50,7 @@ def dim(
4950
if block:
5051
metadata = metadata or {}
5152
metadata["block"] = block
52-
return xattree_dim(
53+
return flopy_dim(
5354
scope=scope,
5455
coord=coord,
5556
default=default,
@@ -72,7 +73,7 @@ def coord(
7273
if block:
7374
metadata = metadata or {}
7475
metadata["block"] = block
75-
return xattree_coord(
76+
return flopy_coord(
7677
scope=scope,
7778
default=default,
7879
repr=repr,
@@ -96,7 +97,7 @@ def array(
9697
if block:
9798
metadata = metadata or {}
9899
metadata["block"] = block
99-
return xattree_array(
100+
return flopy_array(
100101
cls=cls,
101102
dims=dims,
102103
default=default,

flopy4/spec.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"""Wrap `xattree` and `attrs` specification utilities."""
2+
3+
from attrs import NOTHING
4+
from xattree import array as xattree_array
5+
from xattree import coord as xattree_coord
6+
from xattree import dim as xattree_dim
7+
from xattree import field as xattree_field
8+
9+
10+
def field(
11+
default=NOTHING,
12+
validator=None,
13+
converter=None,
14+
repr=True,
15+
eq=True,
16+
init=True,
17+
metadata=None,
18+
):
19+
"""Define a field."""
20+
return xattree_field(
21+
default=default,
22+
validator=validator,
23+
converter=converter,
24+
repr=repr,
25+
eq=eq,
26+
init=init,
27+
metadata=metadata,
28+
)
29+
30+
31+
def dim(
32+
scope=None,
33+
coord: bool | str = True,
34+
default=NOTHING,
35+
repr=True,
36+
eq=True,
37+
init=True,
38+
metadata=None,
39+
):
40+
"""Define a dimension field."""
41+
return xattree_dim(
42+
scope=scope,
43+
coord=coord,
44+
default=default,
45+
repr=repr,
46+
eq=eq,
47+
init=init,
48+
metadata=metadata,
49+
)
50+
51+
52+
def coord(
53+
scope=None,
54+
default=NOTHING,
55+
repr=True,
56+
eq=True,
57+
metadata=None,
58+
):
59+
"""Define a coordinate field."""
60+
return xattree_coord(
61+
scope=scope,
62+
default=default,
63+
repr=repr,
64+
eq=eq,
65+
metadata=metadata,
66+
)
67+
68+
69+
def array(
70+
cls=None,
71+
dims=None,
72+
default=NOTHING,
73+
validator=None,
74+
converter=None,
75+
repr=True,
76+
eq=None,
77+
metadata=None,
78+
):
79+
"""Define an array field."""
80+
return xattree_array(
81+
cls=cls,
82+
dims=dims,
83+
default=default,
84+
validator=validator,
85+
converter=converter,
86+
repr=repr,
87+
eq=eq,
88+
metadata=metadata,
89+
)

0 commit comments

Comments
 (0)