Skip to content

Commit 5aa9248

Browse files
authored
fix(models): auto-sync only on api commands (#277)
Similar fix was recently made in the programs API in #276
1 parent bb76dc1 commit 5aa9248

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

modflow_devtools/models/__init__.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,9 @@ def path(self) -> Path:
13001300

13011301
def _try_best_effort_sync():
13021302
"""
1303-
Attempt to sync registries on first import.
1303+
Attempt to sync registries (best-effort, fails silently).
13041304
1305-
This is a best-effort operation - if it fails (network issues,
1306-
misconfiguration, etc.), we silently continue. The user will get
1307-
a clear error message if they try to use the registry without
1308-
having synced successfully.
1305+
Called by consumer commands before accessing model registries.
13091306
"""
13101307
global _SYNC_ATTEMPTED
13111308

@@ -1323,10 +1320,6 @@ def _try_best_effort_sync():
13231320
pass
13241321

13251322

1326-
# Try to sync on first import (unless disabled)
1327-
if not os.environ.get("MODFLOW_DEVTOOLS_NO_AUTO_SYNC"):
1328-
_try_best_effort_sync()
1329-
13301323
# Lazy initialization of default registry
13311324
_default_registry_cache = None
13321325

modflow_devtools/models/__main__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
"""
99

1010
import argparse
11+
import os
1112
import sys
1213

1314
from . import (
1415
_DEFAULT_CACHE,
1516
ModelSourceConfig,
17+
_try_best_effort_sync,
1618
)
1719

1820

@@ -78,6 +80,10 @@ def cmd_sync(args):
7880

7981
def cmd_info(args):
8082
"""Info command handler."""
83+
# Attempt auto-sync before showing info (unless disabled)
84+
if not os.environ.get("MODFLOW_DEVTOOLS_NO_AUTO_SYNC"):
85+
_try_best_effort_sync()
86+
8187
config = ModelSourceConfig.load()
8288
status = config.status
8389

@@ -96,6 +102,10 @@ def cmd_info(args):
96102

97103
def cmd_list(args):
98104
"""List command handler."""
105+
# Attempt auto-sync before listing (unless disabled)
106+
if not os.environ.get("MODFLOW_DEVTOOLS_NO_AUTO_SYNC"):
107+
_try_best_effort_sync()
108+
99109
cached = _DEFAULT_CACHE.list()
100110

101111
if not cached:

0 commit comments

Comments
 (0)