Skip to content

Commit 51ef955

Browse files
committed
top-level mf sync command
1 parent 91ce990 commit 51ef955

4 files changed

Lines changed: 80 additions & 10 deletions

File tree

modflow_devtools/cli.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Root CLI for modflow-devtools.
33
44
Usage:
5+
mf sync
6+
mf dfns sync
7+
mf dfns info
8+
mf dfns list
9+
mf dfns clean
510
mf models sync
611
mf models info
712
mf models list
@@ -17,6 +22,56 @@
1722

1823
import argparse
1924
import sys
25+
import warnings
26+
27+
28+
def _sync_all():
29+
"""Sync all registries (dfns, models, programs)."""
30+
print("Syncing all registries...")
31+
print()
32+
33+
# Sync DFNs
34+
print("=== DFNs ===")
35+
try:
36+
from modflow_devtools.dfns.registry import sync_dfns
37+
38+
registries = sync_dfns()
39+
for registry in registries:
40+
meta = registry.registry_meta
41+
print(f" {registry.ref}: {len(meta.files)} files")
42+
print(f"Synced {len(registries)} DFN registry(ies)")
43+
except Exception as e:
44+
print(f"Error syncing DFNs: {e}")
45+
print()
46+
47+
# Sync Models
48+
print("=== Models ===")
49+
try:
50+
from modflow_devtools.models import ModelSourceConfig
51+
52+
config = ModelSourceConfig.load()
53+
config.sync()
54+
print("Models synced successfully")
55+
except Exception as e:
56+
print(f"Error syncing models: {e}")
57+
print()
58+
59+
# Sync Programs
60+
print("=== Programs ===")
61+
try:
62+
# Suppress experimental warning
63+
with warnings.catch_warnings():
64+
warnings.filterwarnings("ignore", message=".*modflow_devtools.programs.*experimental.*")
65+
from modflow_devtools.programs import ProgramSourceConfig
66+
67+
config = ProgramSourceConfig.load()
68+
config.sync()
69+
print("Programs synced successfully")
70+
except Exception as e:
71+
print(f"Error syncing programs: {e}")
72+
print()
73+
74+
print("All registries synced!")
2075

2176

2277
def main():
@@ -27,6 +82,12 @@ def main():
2782
)
2883
subparsers = parser.add_subparsers(dest="subcommand", help="Available commands")
2984

85+
# Sync subcommand (syncs all APIs)
86+
subparsers.add_parser("sync", help="Sync all registries (dfns, models, programs)")
87+
88+
# DFNs subcommand
89+
subparsers.add_parser("dfns", help="Manage MODFLOW 6 definition files")
90+
3091
# Models subcommand
3192
subparsers.add_parser("models", help="Manage MODFLOW model registries")
3293

@@ -41,7 +102,14 @@ def main():
41102
sys.exit(1)
42103

43104
# Dispatch to the appropriate module CLI with remaining args
44-
if args.subcommand == "models":
105+
if args.subcommand == "sync":
106+
_sync_all()
107+
elif args.subcommand == "dfns":
108+
from modflow_devtools.dfns.__main__ import main as dfns_main
109+
110+
sys.argv = ["mf dfns", *remaining]
111+
sys.exit(dfns_main())
112+
elif args.subcommand == "models":
45113
from modflow_devtools.models.__main__ import main as models_main
46114

47115
# Replace sys.argv to make it look like we called the submodule directly

modflow_devtools/dfns/__main__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
Command-line interface for the DFNs API.
33
44
Usage:
5-
python -m modflow_devtools.dfns sync [--ref REF] [--force]
6-
python -m modflow_devtools.dfns info
7-
python -m modflow_devtools.dfns list [--ref REF]
8-
python -m modflow_devtools.dfns clean [--all]
5+
mf dfns sync [--ref REF] [--force]
6+
mf dfns info
7+
mf dfns list [--ref REF]
8+
mf dfns clean [--all]
99
"""
1010

1111
from __future__ import annotations
@@ -138,7 +138,7 @@ def cmd_list(args: argparse.Namespace) -> int:
138138

139139
except DfnRegistryNotFoundError as e:
140140
print(f"Error: {e}", file=sys.stderr)
141-
print("Try running 'python -m modflow_devtools.dfn sync' first.", file=sys.stderr)
141+
print("Try running 'mf dfns sync' first.", file=sys.stderr)
142142
return 1
143143
except Exception as e:
144144
print(f"Error: {e}", file=sys.stderr)
@@ -198,7 +198,7 @@ def _format_size(size_bytes: int) -> str:
198198
def main(argv: list[str] | None = None) -> int:
199199
"""Main entry point for the CLI."""
200200
parser = argparse.ArgumentParser(
201-
prog="python -m modflow_devtools.dfn",
201+
prog="mf dfns",
202202
description="MODFLOW 6 definition file tools",
203203
)
204204
parser.add_argument(

modflow_devtools/models/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,15 +1062,15 @@ def _load(self):
10621062
Load registry data from cache.
10631063
10641064
Raises an error if no cached registries are found.
1065-
Run 'python -m modflow_devtools.models sync' to populate the cache.
1065+
Run 'mf models sync' to populate the cache.
10661066
"""
10671067
# Try to load from cache
10681068
loaded_from_cache = self._try_load_from_cache()
10691069

10701070
if not loaded_from_cache:
10711071
raise RuntimeError(
10721072
"No model registries found in cache. "
1073-
"Run 'python -m modflow_devtools.models sync' to download registries, "
1073+
"Run 'mf models sync' to download registries, "
10741074
"or use ModelSourceConfig.load().sync() programmatically."
10751075
)
10761076

modflow_devtools/programs/__main__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ def cmd_list(args):
145145
cached = _DEFAULT_CACHE.list()
146146

147147
if not cached:
148-
print("No cached program registries. Run 'sync' first.")
148+
print(
149+
"No program registries found in cache. Run 'mf programs sync' to download registries."
150+
)
149151
return
150152

151153
# Apply filters

0 commit comments

Comments
 (0)