Skip to content

Commit fe6af2f

Browse files
authored
docs(dfns): improve docs (#331)
Miscellaneous fixes and improvements to the DFNs API docs
1 parent abec244 commit fe6af2f

2 files changed

Lines changed: 52 additions & 33 deletions

File tree

docs/md/dfns.md

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
MODFLOW 6 specifies input components and their variables in configuration files with a custom format. Such files are called definition (DFN) files and conventionally have suffix `.dfn`.
44

5-
The `modflow_devtools.dfns` module provides a structured API for working with MODFLOW 6 input specifications, including typed Python objects representing each component and field type, tools for acquiring, loading and managing specification versions, and a utility to convert `.dfn` files to a revised v2 schema and standard file formats.
5+
The `modflow_devtools.dfns` module provides a structured API for working with MODFLOW 6 input specifications, including typed Python objects representing each component and field type, tools for acquiring, loading and managing specification versions, and a utility to convert `.dfn` files to a revised schema and standard file formats.
66

77
The `modflow_devtools.dfn` module provides a limited subset of the same functionality, but is now deprecated. This module will be removed with `modflow-devtools` version 2.x. The `modflow_devtools.dfns` module should in most cases be used instead, however it remains experimental and may change without notice until version 2.x.
88

@@ -21,9 +21,11 @@ pip install modflow-devtools[ecosystem]
2121

2222
The `dfn` dependency group is also sufficient, but this group is deprecated and will be removed with `modflow-devtools` version 2.x.
2323

24-
### CLI
24+
## CLI
2525

26-
A command line interface is available to manage sets of DFN files corresponding to MODLOW 6 releases.
26+
A command line interface is available to manage sets of DFN files corresponding to MODFLOW 6 releases.
27+
28+
### Cache management
2729

2830
```shell
2931
# Fetch DFNs from GitHub release assets
@@ -42,19 +44,21 @@ python -m modflow_devtools.dfns info
4244
python -m modflow_devtools.dfns clean
4345
```
4446

45-
A tool is also provided to migrate `.dfn` files to new schema versions.
47+
### Migration
48+
49+
The `migrate` subcommand converts `.dfn` files to a new schema version.
4650

4751
```shell
48-
python -m modflow_devtools.dfns.migrate -i <dfn path> -o <output path> -s <schema version> [-f <format>]
52+
python -m modflow_devtools.dfns migrate -i <dfn path> -o <output path> -s <schema version> [-f <format>]
4953
```
5054

5155
The migration tool may be used on directories or individual files.
5256

53-
Supported schema versions are currently "1.1", "1.2", and "2". Note that schema version 2 is under active development, and may change without warning. Versions 1.1 and 1.2 were early prototypes.
57+
Supported schema versions are currently `"2.0.0.dev0"`, `"2.0.0.dev1"`, and `"2.0.0.dev2"` (`CURRENT_SCHEMA_VERSION`). Note that `2.0.0.dev2` is under active development and may change without warning.
5458

5559
The default serialization format is YAML. Use `--format` / `-f` to select `yaml` (default), `toml`, or `json`.
5660

57-
#### Configuration
61+
### Configuration
5862

5963
The `modflow-devtools` package ships with a built-in configuration specifying default DFN release versions to support:
6064

@@ -74,7 +78,7 @@ You can extend or override the default registry configuration by creating an ove
7478

7579
Entries in this file are merged with (and take precedence over) the defaults. The file uses the same format as the bundled configuration file. For instance, to point to DFN releases on your own fork, substitute your GitHub username for "MODFLOW-ORG".
7680

77-
#### Caching
81+
### Cache layout
7882

7983
DFN file sets are cached under:
8084

@@ -95,29 +99,42 @@ The cache is organized by repository and release tag:
9599
└── ...
96100
```
97101

98-
### Python API
102+
## Python API
99103

100-
#### Downloading DFNs
104+
### Schema version
101105

102-
```python
103-
from modflow_devtools.dfns import fetch_dfns
106+
The current schema version is exposed as a constant:
104107

105-
fetch_dfns("MODFLOW-ORG", "modflow6", "6.6.0", "/tmp/dfns")
108+
```python
109+
from modflow_devtools.dfns import CURRENT_SCHEMA_VERSION # "2.0.0.dev2"
106110
```
107111

108-
Downloads all `.dfn` files for the specified MODFLOW 6 release into the given output directory.
112+
### Loading DFNs
109113

110-
### Inspecting DFNs
111-
112-
`Dfns` is a Pydantic model representing a set of component definitions.
114+
`Dfns` is a Pydantic model representing a set of component definitions. Load a directory of definition files with `Dfns.load()`:
113115

114116
```python
115117
from modflow_devtools.dfns import Dfns
116118

117-
# Load all component definitions from a directory
118119
spec = Dfns.load("/path/to/mf6/doc/mf6io/mf6ivar/dfn")
120+
```
121+
122+
**Note**: Calling `Dfns.load()` on a directory of `.dfn` files will convert to `CURRENT_SCHEMA_VERSION` (`"2.0.0.dev2"`) automatically.
123+
124+
For lower-level access, `fetch_dfns` downloads all `.dfn` files for a specific release to a local directory:
125+
126+
```python
127+
from modflow_devtools.dfns import fetch_dfns
128+
129+
fetch_dfns("MODFLOW-ORG", "modflow6", "6.6.0", "/tmp/dfns")
130+
```
131+
132+
In most cases, using `RemoteDfnRegistry` (see [Managing DFNs](#managing-dfns)) is preferable since it handles caching automatically.
119133

120-
spec.schema_version # e.g. "2"
134+
### Inspecting DFNs
135+
136+
```python
137+
spec.schema_version # e.g. CURRENT_SCHEMA_VERSION ("2.0.0.dev2")
121138
spec.root # the Simulation component, or None
122139
len(spec.components) # total number of components
123140

@@ -127,12 +144,10 @@ gwf_chd.name # "gwf-chd"
127144
gwf_chd.parent # "gwf-nam"
128145

129146
# Navigate the component hierarchy
130-
sim_children = spec.children_of("sim-nam") # {"gwf-nam": ..., ...}
131-
gwf_children = spec.children_of("gwf-nam") # {"gwf-chd": ..., "gwf-wel": ..., ...}
147+
sim_children = spec.children("sim-nam") # {"gwf-nam": ..., ...}
148+
gwf_children = spec.children("gwf-nam") # {"gwf-chd": ..., "gwf-wel": ..., ...}
132149
```
133150

134-
**Note**: Calling `Dfns.load()` on a directory of `.dfn` files will convert to the v2 schema automatically.
135-
136151
Each entry in `spec.components` is one of three component types, discriminated by a `type` field:
137152

138153
- `Simulation` — the root component (`sim-nam`)
@@ -185,15 +200,15 @@ See [DFN specification](dfnspec.md) for full attribute documentation.
185200

186201
### Managing DFNs
187202

188-
A registry system handles caching and accessing DFN files from MODFLOW 6 releases.
203+
A registry system handles caching and accessing DFN files from MODFLOW 6 releases. `DfnRegistry` is the abstract base class; `LocalDfnRegistry` and `RemoteDfnRegistry` are the two concrete implementations.
189204

190205
For working with DFN files on the local filesystem, there is `LocalDfnRegistry`.
191206

192207
```python
193208
from modflow_devtools.dfns import LocalDfnRegistry
194209

195210
registry = LocalDfnRegistry(path="/path/to/mf6/doc/mf6io/mf6ivar/dfn")
196-
spec = registry.spec # Dfns instance
211+
spec = registry.spec() # Dfns instance
197212
path = registry.get_path("gwf-chd") # Path to the component file
198213
```
199214

@@ -203,16 +218,16 @@ For fetching and caching DFN files from a MODFLOW 6 release, `RemoteDfnRegistry`
203218
from modflow_devtools.dfns import RemoteDfnRegistry
204219

205220
registry = RemoteDfnRegistry(release_id="MODFLOW-ORG/modflow6@6.6.0")
206-
registry.sync() # download and cache DFN files
207-
registry.sync(force=True) # force re-download
221+
registry.sync() # download and cache DFN files
222+
registry.sync(force=True) # force re-download
208223

209-
spec = registry.spec # get the specification
224+
spec = registry.spec() # get the specification
210225

211226
tag = registry.latest_tag() # resolve "latest" to actual tag
212227
tag = registry.cached_tag() # return cached tag
213228
```
214229

215-
The `release_id` takes the form `"owner/repo@tag"`, where `tag` may be a specific version or "latest".
230+
The `release_id` takes the form `"owner/repo@tag"`, where `tag` may be a specific version or `"latest"`.
216231

217232
For `@latest`, `latest_tag()` queries the GitHub API once and caches the result.
218233

@@ -237,12 +252,16 @@ To get the base cache path programmatically:
237252
RemoteDfnRegistry.base_cache_path()
238253
```
239254

240-
To check the cache contents:
255+
To check whether a release is cached:
241256

242257
```python
243258
from modflow_devtools.dfns.registry import is_cached
244259

245260
is_cached("MODFLOW-ORG/modflow6@6.6.0")
246261
```
247262

248-
When `MODFLOW_DEVTOOLS_AUTO_SYNC=1` is set, `RemoteDfnRegistry.from_ids()` will automatically call `sync()` for any release ID that has no cached files yet.
263+
### Environment variables
264+
265+
| Variable | Values | Effect |
266+
|---|---|---|
267+
| `MODFLOW_DEVTOOLS_AUTO_SYNC` | `1`, `true`, `yes` | `RemoteDfnRegistry.from_ids()` automatically calls `sync()` for any release ID with no cached files yet. |

docs/md/dfnspec.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Required. One of:
274274
- `double`
275275
- `array`
276276
- `string`
277-
- `path`
277+
- `file`
278278
- `record`
279279
- `union`
280280
- `list`
@@ -447,7 +447,7 @@ Type `union`. Sum type.
447447

448448
###### `arms`
449449

450-
`{string: Scalar | Record}`. Subfields, required.
450+
`{string: Scalar | Array | Record}`. Subfields, required.
451451

452452
#### List
453453

0 commit comments

Comments
 (0)