Skip to content

Commit 91ce990

Browse files
committed
autosync fix
1 parent 151f261 commit 91ce990

9 files changed

Lines changed: 36 additions & 29 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
working-directory: modflow-devtools/autotest
125125
env:
126126
REPOS_PATH: ${{ github.workspace }}
127-
MODFLOW_DEVTOOLS_NO_AUTO_SYNC: 1
127+
MODFLOW_DEVTOOLS_AUTO_SYNC: 0
128128
TEST_DFN_PATH: ${{ github.workspace }}/modflow6/doc/mf6io/mf6ivar/dfn
129129
# use --dist loadfile to so tests requiring pytest-virtualenv run on the same worker
130130
run: uv run pytest -v -n auto --dist loadfile --durations 0 --ignore test_download.py --ignore test_models.py --ignore test_dfns_registry.py

docs/md/dev/dfns.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ status = get_sync_status()
476476
- **At install time**: Best-effort sync to default refs during package installation (fail silently on network errors)
477477
- **On first use**: If registry cache is empty for requested ref, attempt to sync before raising errors
478478
- **Lazy loading**: Don't sync until DFN access is actually requested
479-
- **Configurable**: Users can disable auto-sync via environment variable: `MODFLOW_DEVTOOLS_NO_AUTO_SYNC=1`
479+
- **Configurable (Experimental)**: Auto-sync is opt-in via environment variable: `MODFLOW_DEVTOOLS_AUTO_SYNC=1` (set to "1", "true", or "yes")
480480

481481
### Source repository integration
482482

@@ -1295,7 +1295,7 @@ dfn.name # attribute access
12951295
5. Implement `sync_dfns()` function
12961296
6. Add registry metadata caching with hash verification
12971297
7. Implement version-controlled registry discovery
1298-
8. Add auto-sync on first use (with opt-out via `MODFLOW_DEVTOOLS_NO_AUTO_SYNC`)
1298+
8. Add auto-sync on first use (opt-in via `MODFLOW_DEVTOOLS_AUTO_SYNC` while experimental)
12991299
9. **Implement `DfnSpec` dataclass** with `Mapping` protocol for single canonical hierarchical representation with flat dict access
13001300

13011301
**CLI and module API** (depends on Registry infrastructure):

docs/md/dev/programs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ status = get_sync_status()
509509

510510
- **At install time**: Best-effort sync during package installation (fail silently on network errors)
511511
- **On first use**: If registry cache is empty, attempt to sync before raising errors
512-
- **Configurable**: Users can disable auto-sync via environment variable: `MODFLOW_DEVTOOLS_NO_AUTO_SYNC=1`
512+
- **Configurable (Experimental)**: Auto-sync is opt-in via environment variable: `MODFLOW_DEVTOOLS_AUTO_SYNC=1` (set to "1", "true", or "yes")
513513

514514
#### Force semantics
515515

docs/md/models.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ python -m modflow_devtools.models cp mf6/example/ex-gwf-twri01 /path/to/workspac
156156
```
157157

158158
The copy command:
159-
- Automatically attempts to sync registries before copying (unless `MODFLOW_DEVTOOLS_NO_AUTO_SYNC=1`)
159+
- Automatically attempts to sync registries before copying (if `MODFLOW_DEVTOOLS_AUTO_SYNC=1`)
160160
- Creates the workspace directory if it doesn't exist
161161
- Copies all input files for the specified model
162162
- Preserves subdirectory structure within the workspace
@@ -316,16 +316,16 @@ mf models clear --force
316316

317317
## Automatic Synchronization
318318

319-
By default, `modflow-devtools` attempts to sync registries:
320-
- On first import (best-effort, fails silently on network errors)
321-
- When accessing models (unless `MODFLOW_DEVTOOLS_NO_AUTO_SYNC=1`)
322-
323-
To disable auto-sync:
319+
Auto-sync is **opt-in** (experimental). To enable:
324320

325321
```bash
326-
export MODFLOW_DEVTOOLS_NO_AUTO_SYNC=1
322+
export MODFLOW_DEVTOOLS_AUTO_SYNC=1 # or "true" or "yes"
327323
```
328324

325+
When enabled, `modflow-devtools` attempts to sync registries:
326+
- On first access (best-effort, fails silently on network errors)
327+
- When accessing models via the API or CLI
328+
329329
Then manually sync when needed:
330330

331331
```bash

docs/md/programs.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,17 @@ mf programs install mf6 --force
347347
348348
## Automatic Synchronization
349349
350-
By default, `modflow-devtools` attempts to sync registries:
351-
- On first import (best-effort, fails silently on network errors)
352-
- Before installation (unless `MODFLOW_DEVTOOLS_NO_AUTO_SYNC=1`)
353-
- Before listing available programs
354-
355-
To disable auto-sync:
350+
Auto-sync is **opt-in** (experimental). To enable:
356351
357352
```bash
358-
export MODFLOW_DEVTOOLS_NO_AUTO_SYNC=1
353+
export MODFLOW_DEVTOOLS_AUTO_SYNC=1 # or "true" or "yes"
359354
```
360355
356+
When enabled, `modflow-devtools` attempts to sync registries:
357+
- On first access (best-effort, fails silently on network errors)
358+
- Before installation
359+
- Before listing available programs
360+
361361
Then manually sync when needed:
362362
363363
```bash

modflow_devtools/dfns/registry.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ def get_sync_status(source: str = "modflow6") -> dict[str, bool]:
734734
def get_registry(
735735
source: str = "modflow6",
736736
ref: str = "develop",
737-
auto_sync: bool = True,
737+
auto_sync: bool = False,
738738
path: str | PathLike | None = None,
739739
) -> DfnRegistry:
740740
"""
@@ -747,8 +747,9 @@ def get_registry(
747747
ref : str, optional
748748
Git ref (branch, tag, or commit hash). Default is "develop".
749749
auto_sync : bool, optional
750-
If True and registry is not cached, automatically sync. Default is True.
751-
Can be disabled via MODFLOW_DEVTOOLS_NO_AUTO_SYNC environment variable.
750+
If True and registry is not cached, automatically sync. Default is False
751+
(opt-in while experimental). Can be enabled via MODFLOW_DEVTOOLS_AUTO_SYNC
752+
environment variable (set to "1", "true", or "yes").
752753
Ignored when path is provided.
753754
path : str or PathLike, optional
754755
Path to a local directory containing DFN files. If provided, returns
@@ -775,9 +776,9 @@ def get_registry(
775776
if path is not None:
776777
return LocalDfnRegistry(path=Path(path), source=source, ref=ref)
777778

778-
# Check for auto-sync opt-out
779-
if os.environ.get("MODFLOW_DEVTOOLS_NO_AUTO_SYNC", "").lower() in ("1", "true", "yes"):
780-
auto_sync = False
779+
# Check for auto-sync opt-in (experimental - off by default)
780+
if os.environ.get("MODFLOW_DEVTOOLS_AUTO_SYNC", "").lower() in ("1", "true", "yes"):
781+
auto_sync = True
781782

782783
registry = RemoteDfnRegistry(source=source, ref=ref)
783784

modflow_devtools/models/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,13 +1322,19 @@ def get_default_registry():
13221322
This allows the module to import successfully even if the cache
13231323
is empty, with a clear error message on first use.
13241324
1325+
Auto-sync can be enabled via MODFLOW_DEVTOOLS_AUTO_SYNC environment variable
1326+
(currently opt-in while experimental). Set to "1", "true", or "yes" to enable.
1327+
13251328
Returns
13261329
-------
13271330
PoochRegistry
13281331
The default model registry
13291332
"""
13301333
global _default_registry_cache
13311334
if _default_registry_cache is None:
1335+
# Opt-in auto-sync (experimental - off by default)
1336+
if os.environ.get("MODFLOW_DEVTOOLS_AUTO_SYNC", "").lower() in ("1", "true", "yes"):
1337+
_try_best_effort_sync()
13321338
_default_registry_cache = PoochRegistry(base_url=_DEFAULT_BASE_URL, env=_DEFAULT_ENV)
13331339
return _default_registry_cache
13341340

modflow_devtools/models/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def cmd_sync(args):
108108
def cmd_info(args):
109109
"""Info command handler."""
110110
# Attempt auto-sync before showing info (unless disabled)
111-
if not os.environ.get("MODFLOW_DEVTOOLS_NO_AUTO_SYNC"):
111+
if os.environ.get("MODFLOW_DEVTOOLS_AUTO_SYNC", "").lower() in ("1", "true", "yes"):
112112
_try_best_effort_sync()
113113

114114
config = ModelSourceConfig.load()
@@ -176,7 +176,7 @@ def cmd_info(args):
176176
def cmd_list(args):
177177
"""List command handler."""
178178
# Attempt auto-sync before listing (unless disabled)
179-
if not os.environ.get("MODFLOW_DEVTOOLS_NO_AUTO_SYNC"):
179+
if os.environ.get("MODFLOW_DEVTOOLS_AUTO_SYNC", "").lower() in ("1", "true", "yes"):
180180
_try_best_effort_sync()
181181

182182
cached = _DEFAULT_CACHE.list()
@@ -285,7 +285,7 @@ def cmd_clear(args):
285285
def cmd_copy(args):
286286
"""Copy command handler."""
287287
# Attempt auto-sync before copying (unless disabled)
288-
if not os.environ.get("MODFLOW_DEVTOOLS_NO_AUTO_SYNC"):
288+
if os.environ.get("MODFLOW_DEVTOOLS_AUTO_SYNC", "").lower() in ("1", "true", "yes"):
289289
_try_best_effort_sync()
290290

291291
from . import copy_to

modflow_devtools/programs/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def cmd_info(args):
139139
def cmd_list(args):
140140
"""List command handler."""
141141
# Attempt auto-sync before listing (unless disabled)
142-
if not os.environ.get("MODFLOW_DEVTOOLS_NO_AUTO_SYNC"):
142+
if os.environ.get("MODFLOW_DEVTOOLS_AUTO_SYNC", "").lower() in ("1", "true", "yes"):
143143
_try_best_effort_sync()
144144

145145
cached = _DEFAULT_CACHE.list()
@@ -193,7 +193,7 @@ def cmd_list(args):
193193
def cmd_install(args):
194194
"""Install command handler."""
195195
# Attempt auto-sync before installation (unless disabled)
196-
if not os.environ.get("MODFLOW_DEVTOOLS_NO_AUTO_SYNC"):
196+
if os.environ.get("MODFLOW_DEVTOOLS_AUTO_SYNC", "").lower() in ("1", "true", "yes"):
197197
_try_best_effort_sync()
198198

199199
# Parse program@version syntax if provided

0 commit comments

Comments
 (0)