From d70efc3bd1db5a831f02f9c01673e81a51ded561 Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Fri, 5 Jun 2026 07:42:14 -0700 Subject: [PATCH 1/2] look for version.txt if syncing with local dfn path --- flopy4/cli.py | 23 ++++++++++------------- flopy4/mf6/_compat.py | 4 +++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/flopy4/cli.py b/flopy4/cli.py index bff02023..c6e5260e 100644 --- a/flopy4/cli.py +++ b/flopy4/cli.py @@ -48,11 +48,6 @@ def _cmd_sync(args: argparse.Namespace) -> None: from flopy4.mf6.utils.codegen.dfn2py import make - release_id = _resolve_release_id(args.release_id, verbose=args.verbose) - - # For remote release IDs, install the matching binary unless --no-install. - from pathlib import Path - # is_local = Path(release_id).expanduser().is_dir() # if not is_local and not args.no_install: # _, tag = release_id.split("@", 1) @@ -76,9 +71,6 @@ def _cmd_sync(args: argparse.Namespace) -> None: # print(f"Warning: binary installation failed: {exc}", file=sys.stderr) # print("Continuing with class generation only.", file=sys.stderr) - if args.verbose: - print(f"Generating flopy4.mf6 from {release_id} ...") - def _populate_remote_cache( registry: RemoteDfnRegistry, release_id: str, force: bool = False ) -> None: @@ -115,11 +107,18 @@ def _write_contract(outdir: Path, mf6_version: str) -> None: f'DFN_SCHEMA_VERSION = "{_DFN_SCHEMA_VERSION}"\n' ) - path = Path(release_id).expanduser() + if args.verbose: + print(f"Generating flopy4.mf6 from {release_id} ...") + + path = Path(args.release_id).expanduser() if path.exists() and path.is_dir(): registry = LocalDfnRegistry(path=path) - effective_version = "unknown" + if "modflow6" in path.parts: + effective_version = (path.parents[3] / "version.txt").read_text() + else: + effective_version = "unknown" else: + release_id = _resolve_release_id(args.release_id, verbose=args.verbose) if "@" not in release_id or "/" not in release_id.split("@")[0]: raise ValueError( f"release_id must be 'owner/repo@tag' or a local path; got: {release_id!r}" @@ -153,10 +152,9 @@ def _write_contract(outdir: Path, mf6_version: str) -> None: def _cmd_status(args: argparse.Namespace) -> None: try: - from flopy4.mf6._contract import DFN_SCHEMA_VERSION, MF6_VERSION + from flopy4.mf6._contract import MF6_VERSION except ImportError: MF6_VERSION = "unknown" - DFN_SCHEMA_VERSION = "unknown" from flopy4.mf6._compat import _query_mf6_version @@ -164,7 +162,6 @@ def _cmd_status(args: argparse.Namespace) -> None: binary_version = _query_mf6_version(exe) if exe else None print(f"flopy4.mf6 synced to : {MF6_VERSION}") - print(f"DFN schema version : {DFN_SCHEMA_VERSION}") if not exe: print("Discovered binary : (not found on PATH)") elif binary_version is None: diff --git a/flopy4/mf6/_compat.py b/flopy4/mf6/_compat.py index 574c5c9c..a0c48f9a 100644 --- a/flopy4/mf6/_compat.py +++ b/flopy4/mf6/_compat.py @@ -10,7 +10,9 @@ def _query_mf6_version(exe: str) -> str | None: try: out = subprocess.check_output([exe, "-v"], text=True, stderr=subprocess.STDOUT) m = _VERSION_RE.search(out) - return m.group(1) if m else None + v = m.group(1) if m else None + v = v.rpartition("+")[0] # TODO how to handle vcs tag section? + return v except Exception: return None From 91d6429bd6944c5ad27cc15756eafee32908621c Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Fri, 5 Jun 2026 08:00:39 -0700 Subject: [PATCH 2/2] appease mypy --- flopy4/cli.py | 8 +++++--- flopy4/mf6/_compat.py | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/flopy4/cli.py b/flopy4/cli.py index c6e5260e..ededeb9c 100644 --- a/flopy4/cli.py +++ b/flopy4/cli.py @@ -107,11 +107,11 @@ def _write_contract(outdir: Path, mf6_version: str) -> None: f'DFN_SCHEMA_VERSION = "{_DFN_SCHEMA_VERSION}"\n' ) - if args.verbose: - print(f"Generating flopy4.mf6 from {release_id} ...") - path = Path(args.release_id).expanduser() if path.exists() and path.is_dir(): + if args.verbose: + print(f"Generating flopy4.mf6 from local DFNs: {path}") + registry = LocalDfnRegistry(path=path) if "modflow6" in path.parts: effective_version = (path.parents[3] / "version.txt").read_text() @@ -119,6 +119,8 @@ def _write_contract(outdir: Path, mf6_version: str) -> None: effective_version = "unknown" else: release_id = _resolve_release_id(args.release_id, verbose=args.verbose) + if args.verbose: + print(f"Generating flopy4.mf6 from remote release: {release_id}") if "@" not in release_id or "/" not in release_id.split("@")[0]: raise ValueError( f"release_id must be 'owner/repo@tag' or a local path; got: {release_id!r}" diff --git a/flopy4/mf6/_compat.py b/flopy4/mf6/_compat.py index a0c48f9a..e1e031c4 100644 --- a/flopy4/mf6/_compat.py +++ b/flopy4/mf6/_compat.py @@ -11,8 +11,9 @@ def _query_mf6_version(exe: str) -> str | None: out = subprocess.check_output([exe, "-v"], text=True, stderr=subprocess.STDOUT) m = _VERSION_RE.search(out) v = m.group(1) if m else None - v = v.rpartition("+")[0] # TODO how to handle vcs tag section? - return v + if v is None: + return v + return v.rpartition("+")[0] # TODO how to handle vcs tag section? except Exception: return None