Skip to content

Commit 4c572f9

Browse files
authored
refactor(codegen): miscellaneous cleanup, amend tests (#2519)
Simplify the generate_classes.py script. Remove the backup and exclude functionality — this can be done manually if needed in the future. Improve the console output by showing lists in columns. Also, one of the old commits we tested had some funky variable definitions in gwf-evta.dfn, which I think we can safely assume are no longer part of the spec. This was breaking the codegen CI tests.
1 parent 5a746a9 commit 4c572f9

9 files changed

Lines changed: 109 additions & 204 deletions

File tree

.docs/md/generate_classes.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The `generate_classes()` function has several optional parameters.
5959
```bash
6060
$ python -m flopy.mf6.utils.generate_classes -h
6161
usage: generate_classes.py [-h] [--owner OWNER] [--repo REPO] [--ref REF]
62-
[--dfnpath DFNPATH] [--no-backup]
62+
[--dfnpath DFNPATH]
6363

6464
Generate the MODFLOW 6 flopy classes using definition files from the MODFLOW 6
6565
GitHub repository or a set of definition files in a folder provided by the
@@ -73,10 +73,6 @@ options:
7373
definition; default is 'master'.
7474
--dfnpath DFNPATH Path to a definition file folder that will be used to
7575
generate the MODFLOW 6 classes.
76-
--no-backup Set to disable backup. Default behavior is to keep a
77-
backup of the definition files in dfn_backup with a date
78-
and timestamp from when the definition files were
79-
replaced.
8076
```
8177

8278
For example, use the develop branch instead:
@@ -98,8 +94,6 @@ $ python -m flopy.mf6.utils.generate_classes --dfnpath ../your/dfn/path
9894

9995
Branch names, commit hashes, or tags may be provided to `ref`.
10096

101-
By default, a backup is made of FloPy's package classes before rewriting them. To disable backups, use `--no-backup` from command-line, or `backup=False` with the Python function.
102-
10397
## Testing class generation
10498

10599
Tests for the `generate_classes()` utility are located in `test_generate_classes.py`. The tests depend on [`virtualenv`](https://pypi.org/project/virtualenv/) and will be skipped if run in parallel without the `--dist loadfile` option for `pytest-xdist`.

.github/workflows/codegen.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
matrix:
1515
os: [ ubuntu-latest, macos-latest, windows-latest ]
1616
python-version: [ "3.10", "3.11", "3.12" ]
17-
ref: ["develop", "master", "6.4.1", "4458f9f", "4458f9f7a6244182e6acc2430a6996f9ca2df367"]
17+
ref: ["develop", "master", "6.4.1", "6.4.0"]
1818
defaults:
1919
run:
2020
shell: bash -l {0}
@@ -33,4 +33,4 @@ jobs:
3333
run: uv sync --extra test
3434

3535
- name: Generate classes
36-
run: uv run python -m flopy.mf6.utils.generate_classes --ref ${{ matrix.ref }} --no-backup
36+
run: uv run python -m flopy.mf6.utils.generate_classes --ref ${{ matrix.ref }}

.github/workflows/commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
subset: triangle
153153

154154
- name: Update package classes
155-
run: uv run python -m flopy.mf6.utils.generate_classes --ref develop --no-backup
155+
run: uv run python -m flopy.mf6.utils.generate_classes --ref develop
156156

157157
- name: Run tests
158158
working-directory: autotest

.github/workflows/examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
subset: triangle
7272

7373
- name: Update FloPy packages
74-
run: python -m flopy.mf6.utils.generate_classes --ref develop --no-backup
74+
run: python -m flopy.mf6.utils.generate_classes --ref develop
7575

7676
- name: Run example tests
7777
working-directory: autotest

.github/workflows/release.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ jobs:
3939
env:
4040
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4141

42-
- name: Sync MF6 module
43-
run: uv run python -m flopy.mf6.utils.generate_classes --no-backup --exclude chf --exclude olf --exclude swf
42+
# NOTE: assumes the MF6 module has been generated already.
43+
# we do that manually to exclude models under development.
44+
# if this becomes unnecessary, uncomment the lines below.
45+
# - name: Sync MF6 module
46+
# run: uv run python -m flopy.mf6.utils.generate_classes
4447

4548
- name: Update version numbers
4649
id: version

docs/make_release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ As described above, making a release manually involves the following steps:
9696

9797
- Run `python scripts/update_version.py -v <semver>` to update the version number stored in `version.txt` and `flopy/version.py`. For an approved release use the `--approve` flag.
9898

99-
- Update MODFLOW 6 dfn files in the repository and MODFLOW 6 package classes by running `python -m flopy.mf6.utils.generate_classes --ref master --no-backup`
99+
- Update MODFLOW 6 dfn files in the repository and MODFLOW 6 package classes by running `python -m flopy.mf6.utils.generate_classes --ref master`
100100

101101
- Run `ruff check .` and `ruff format .` from the project root.
102102

docs/mf6_dev_guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ FloPy can generate a MODFLOW 6 compatibility layer for itself, given a set of de
2727
For instance, to sync with DFNs from the MODFLOW 6 develop branch:
2828

2929
```shell
30-
python -m flopy.mf6.utils.generate_classes --ref develop --no-backup
30+
python -m flopy.mf6.utils.generate_classes --ref develop
3131
```
3232

3333
Generated files are created in `flopy/mf6/modflow/`.

flopy/mf6/utils/codegen/filters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ def _filter_metadata(metadata):
347347
meta_.append(" ".join(s))
348348
return meta_
349349

350+
# abominable. cannot be removed soon enough
350351
with open(dfn_dir / "common.dfn") as common_f, \
351352
open(dfn_dir / dfn_file_name) as f:
352353
common, _ = Dfn._load_v1_flat(common_f)

0 commit comments

Comments
 (0)