Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions flopy4/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -115,11 +107,20 @@ def _write_contract(outdir: Path, mf6_version: str) -> None:
f'DFN_SCHEMA_VERSION = "{_DFN_SCHEMA_VERSION}"\n'
)

path = Path(release_id).expanduser()
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)
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 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}"
Expand Down Expand Up @@ -153,18 +154,16 @@ 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

exe = shutil.which("mf6") or shutil.which("mf6.exe")
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:
Expand Down
5 changes: 4 additions & 1 deletion flopy4/mf6/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ 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
if v is None:
return v
return v.rpartition("+")[0] # TODO how to handle vcs tag section?
except Exception:
return None

Expand Down
Loading