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
8 changes: 6 additions & 2 deletions flopy4/mf6/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ def _populate_remote_cache(registry, release_id: str, force: bool = False) -> No
Re-fetch even if the cache already exists. Should be True for
branch refs (mutable) and False for pinned release tags.
"""
if not force and registry.cache_path.exists() and any(registry.cache_path.iterdir()):
return
if registry.cache_path.exists() and any(registry.cache_path.iterdir()):
if not force:
return
# The registry's sync skips a non-empty cache, so clear it: otherwise
# a branch ref keeps its first fetch, and files dropped upstream stay.
shutil.rmtree(registry.cache_path)
try:
registry.sync()
except Exception:
Expand Down
22 changes: 22 additions & 0 deletions test/mf6/test_mf6_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,25 @@ def test_latest_pins_tag(dfn_path, outdir, monkeypatch, fake_install):
assert result.source == "MODFLOW-ORG/[email protected]"
assert result.version == "6.8.1"
assert fake_install[0]["version"] == "6.8.1"


class _FakeRegistry:
def __init__(self, cache_path: Path):
self.cache_path = cache_path

def sync(self):
if self.cache_path.exists() and any(self.cache_path.iterdir()):
return
self.cache_path.mkdir(parents=True, exist_ok=True)
(self.cache_path / "new.dfn").write_text("fresh")


@pytest.mark.parametrize("force", [False, True])
def test_populate_remote_cache_force_refetches(tmp_path, force):
"""A forced populate replaces a stale cache; an unforced one keeps it."""
cache = tmp_path / "develop"
cache.mkdir()
(cache / "old.dfn").write_text("stale")
_sync._populate_remote_cache(_FakeRegistry(cache), "MODFLOW-ORG/modflow6@develop", force=force)
names = sorted(p.name for p in cache.iterdir())
assert names == (["new.dfn"] if force else ["old.dfn"])
Loading