From 0e9782088efd88c488ca876cd09832eaf3b9a8a0 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Fri, 5 Jun 2026 05:53:59 -0700 Subject: [PATCH 1/3] tweak compat check --- flopy4/mf6/_compat.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/flopy4/mf6/_compat.py b/flopy4/mf6/_compat.py index f4d77959..814edfa6 100644 --- a/flopy4/mf6/_compat.py +++ b/flopy4/mf6/_compat.py @@ -27,13 +27,16 @@ def check_mf6_compatibility(exe: str | None = None) -> None: Path to an MF6 executable. If None, searches PATH for ``mf6`` or ``mf6.exe``. Does nothing if no binary is found. """ - try: - from flopy4.mf6._contract import MF6_VERSION - except ImportError: - return + from flopy4.mf6._contract import MF6_VERSION # Skip if version is unknown or a branch name rather than a semver tag. - if not MF6_VERSION or not MF6_VERSION[0].isdigit(): + if not MF6_VERSION or MF6_VERSION == "unknown": + warnings.warn( + f"flopy4.mf6 is synced to an unknown MF6 version. " + "Run `flopy4 mf6 sync` to re-sync.", + UserWarning, + stacklevel=3, + ) return if exe is None: From ab1047b0067265aad3033d4f432156f7b327e1d5 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Fri, 5 Jun 2026 06:05:37 -0700 Subject: [PATCH 2/3] more tweaks, no ruff in codegen --- flopy4/cli.py | 8 ++--- flopy4/mf6/_compat.py | 3 +- flopy4/mf6/_contract.py | 2 +- flopy4/mf6/utils/codegen/dfn2py.py | 8 ----- flopy4/mf6/utils/codegen/make.py | 51 ++++++------------------------ 5 files changed, 13 insertions(+), 59 deletions(-) diff --git a/flopy4/cli.py b/flopy4/cli.py index 1231740c..bff02023 100644 --- a/flopy4/cli.py +++ b/flopy4/cli.py @@ -17,6 +17,8 @@ def _resolve_release_id(release_id: str | None, verbose: bool = False) -> str: or the latest release if no release_id is given. """ if release_id is not None: + if "@" not in release_id: + return f"MODFLOW-ORG/modflow6@{release_id}" return release_id # Try to read the version from a binary on PATH. @@ -142,7 +144,6 @@ def _write_contract(outdir: Path, mf6_version: str) -> None: outdir=_MF6_ROOT, existing_only=not args.all_packages, makedirs=args.all_packages, - fmt=not args.no_format, ) _write_contract(_MF6_ROOT, effective_version) @@ -211,11 +212,6 @@ def main() -> None: help="Generate all packages, including ones not yet on disk. " "By default sync only updates already-generated files.", ) - sync_p.add_argument( - "--no-format", - action="store_true", - help="Skip ruff formatting of generated files.", - ) sync_p.add_argument("--force", action="store_true", help="Force binary reinstallation.") sync_p.add_argument("--verbose", action="store_true") sync_p.set_defaults(func=_cmd_sync) diff --git a/flopy4/mf6/_compat.py b/flopy4/mf6/_compat.py index 814edfa6..574c5c9c 100644 --- a/flopy4/mf6/_compat.py +++ b/flopy4/mf6/_compat.py @@ -32,8 +32,7 @@ def check_mf6_compatibility(exe: str | None = None) -> None: # Skip if version is unknown or a branch name rather than a semver tag. if not MF6_VERSION or MF6_VERSION == "unknown": warnings.warn( - f"flopy4.mf6 is synced to an unknown MF6 version. " - "Run `flopy4 mf6 sync` to re-sync.", + "flopy4.mf6 is synced to an unknown MF6 version. Run `flopy4 mf6 sync` to re-sync.", UserWarning, stacklevel=3, ) diff --git a/flopy4/mf6/_contract.py b/flopy4/mf6/_contract.py index 520d9a71..e285309e 100644 --- a/flopy4/mf6/_contract.py +++ b/flopy4/mf6/_contract.py @@ -1,3 +1,3 @@ # autogenerated file, do not modify -MF6_VERSION = "unknown" +MF6_VERSION = "develop" DFN_SCHEMA_VERSION = "2.0.0.dev1" diff --git a/flopy4/mf6/utils/codegen/dfn2py.py b/flopy4/mf6/utils/codegen/dfn2py.py index 125b360f..8e1b0333 100644 --- a/flopy4/mf6/utils/codegen/dfn2py.py +++ b/flopy4/mf6/utils/codegen/dfn2py.py @@ -44,7 +44,6 @@ def make( dfndir: str | PathLike, outdir: str | PathLike = _MF6_ROOT, developmode: bool = False, - fmt: bool = True, makedirs: bool = False, existing_only: bool = False, ): @@ -57,7 +56,6 @@ def make( dfns=dfns, outdir=outdir, developmode=developmode, - fmt=fmt, skip=_SKIP, makedirs=makedirs, existing_only=existing_only, @@ -93,11 +91,6 @@ def cli_main() -> None: action="store_true", help="Include developmode fields.", ) - parser.add_argument( - "--no-format", - action="store_true", - help="Skip ruff formatting.", - ) parser.add_argument( "--makedirs", action="store_true", @@ -116,7 +109,6 @@ def cli_main() -> None: dfndir=args.dfndir, outdir=args.outdir, developmode=args.developmode, - fmt=not args.no_format, makedirs=args.makedirs, existing_only=args.existing_only, ) diff --git a/flopy4/mf6/utils/codegen/make.py b/flopy4/mf6/utils/codegen/make.py index 52670903..8057f7ec 100644 --- a/flopy4/mf6/utils/codegen/make.py +++ b/flopy4/mf6/utils/codegen/make.py @@ -5,9 +5,6 @@ Jinja templates stay thin and logic is easy to test and debug. """ -import logging -import subprocess -import sys from dataclasses import dataclass from dataclasses import field as dc_field from os import PathLike @@ -28,11 +25,6 @@ replace_list_fields, ) -logger = logging.getLogger(__name__) - -_RUFF_CONFIG = Path(__file__).parents[4] / "pyproject.toml" - - # Pre-computed context dataclasses @@ -912,39 +904,13 @@ def _get_env() -> jinja2.Environment: ) -# File generation - - -def _format(path: Path) -> None: - config = ["--config", str(_RUFF_CONFIG)] if _RUFF_CONFIG.exists() else [] - subprocess.run( - [sys.executable, "-m", "ruff", "format", *config, str(path)], - check=True, - capture_output=True, - ) - subprocess.run( - [sys.executable, "-m", "ruff", "check", "--fix", *config, str(path)], - check=True, - capture_output=True, - ) - - -def make_module( - spec: ComponentSpec, - env: jinja2.Environment, - *, - fmt: bool = True, -) -> None: +def make_module(spec: ComponentSpec, env: jinja2.Environment, verbose: bool = False) -> None: """Generate a single component module.""" template = env.get_template(spec.template) rendered = template.render(spec=spec) spec.outpath.write_text(rendered, newline="\n") - logger.info(f"Wrote {spec.outpath}") - if fmt: - try: - _format(spec.outpath) - except subprocess.CalledProcessError as e: - logger.warning(f"Failed to format {spec.outpath}: {e.stderr.decode().strip()}") + if verbose: + print(f"Wrote {spec.outpath}") def make_modules( @@ -953,10 +919,10 @@ def make_modules( dfndir: PathLike | None = None, outdir: PathLike, developmode: bool = False, - fmt: bool = True, skip: set[str] | None = None, makedirs: bool = False, existing_only: bool = False, + verbose: bool = False, ) -> list[ComponentSpec]: """Generate Python modules for all components. @@ -971,14 +937,14 @@ def make_modules( Root output directory for generated Python files. developmode : If True, include developmode fields. - fmt : - If True, run ruff format/check on generated files. skip : Set of DFN names to skip. makedirs : If True, create output subdirectories as needed. existing_only : If True, only (re)generate files that already exist on disk. + verbose : + Whether to show verbose output Returns ------- @@ -998,10 +964,11 @@ def make_modules( continue spec = build_component_spec(dfn, root=outdir, developmode=developmode, v1_dfn=dfn) if existing_only and not spec.outpath.exists(): - logger.info(f"{spec.outpath} does not exist — skipping {name} (existing_only)") + if verbose: + print(f"{spec.outpath} does not exist — skipping {name} (existing_only)") continue if makedirs: spec.outpath.parent.mkdir(parents=True, exist_ok=True) - make_module(spec, env, fmt=fmt) + make_module(spec, env) specs.append(spec) return specs From 4948decce16ec4cb80db5b1f134d529f3091b9dc Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Fri, 5 Jun 2026 06:15:04 -0700 Subject: [PATCH 3/3] no fmt --- test/test_mf6_codegen.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_mf6_codegen.py b/test/test_mf6_codegen.py index 83382a4d..b2a7e186 100644 --- a/test/test_mf6_codegen.py +++ b/test/test_mf6_codegen.py @@ -600,7 +600,7 @@ def test_simple_tier_generates_importable_files(dfn_path, tmp_path, all_dfns): (tmp_path / "gwf").mkdir() skip = {n for n in all_dfns if n not in SIMPLE_TIER} - specs = make_modules(dfndir=dfn_path, outdir=tmp_path, fmt=False, skip=skip) + specs = make_modules(dfndir=dfn_path, outdir=tmp_path, skip=skip) generated = {s.dfn_name: s for s in specs} @@ -638,7 +638,7 @@ def test_solution_tier_generates_importable_files(dfn_path, tmp_path, all_dfns): from flopy4.mf6.solution import Solution skip = {n for n in all_dfns if n not in SOLUTION_TIER} - specs = make_modules(dfndir=dfn_path, outdir=tmp_path, fmt=False, skip=skip) + specs = make_modules(dfndir=dfn_path, outdir=tmp_path, skip=skip) generated = {s.dfn_name: s for s in specs} @@ -697,7 +697,7 @@ def test_transport_tier_generates_importable_files(dfn_path, tmp_path, all_dfns) target = {n for n in TRANSPORT_TIER if n in all_dfns} skip = {n for n in all_dfns if n not in target} - specs = make_modules(dfndir=dfn_path, outdir=tmp_path, fmt=False, skip=skip) + specs = make_modules(dfndir=dfn_path, outdir=tmp_path, skip=skip) generated = {s.dfn_name: s for s in specs} from flopy4.mf6.package import Package @@ -719,7 +719,7 @@ def test_oc_tier_generates_importable_files(dfn_path, tmp_path, all_dfns): target = {n for n in OC_TIER if n in all_dfns} skip = {n for n in all_dfns if n not in target} - specs = make_modules(dfndir=dfn_path, outdir=tmp_path, fmt=False, skip=skip) + specs = make_modules(dfndir=dfn_path, outdir=tmp_path, skip=skip) generated = {s.dfn_name: s for s in specs} from flopy4.mf6.package import Package @@ -743,7 +743,7 @@ def test_utl_tier_generates_importable_files(dfn_path, tmp_path, all_dfns): target = {n for n in UTL_TIER if n in all_dfns} skip = {n for n in all_dfns if n not in target} - specs = make_modules(dfndir=dfn_path, outdir=tmp_path, fmt=False, makedirs=True, skip=skip) + specs = make_modules(dfndir=dfn_path, outdir=tmp_path, makedirs=True, skip=skip) generated = {s.dfn_name: s for s in specs} from flopy4.mf6.package import Package @@ -764,7 +764,7 @@ def test_exg_tier_generates_importable_files(dfn_path, tmp_path, all_dfns): target = {n for n in EXG_TIER if n in all_dfns} skip = {n for n in all_dfns if n not in target} - specs = make_modules(dfndir=dfn_path, outdir=tmp_path, fmt=False, makedirs=True, skip=skip) + specs = make_modules(dfndir=dfn_path, outdir=tmp_path, makedirs=True, skip=skip) generated = {s.dfn_name: s for s in specs} from flopy4.mf6.package import Package