Skip to content

Commit

Permalink
fix(get-modflow): manage internal "bin" dir structures (#1837)
Browse files Browse the repository at this point in the history
* fix(get-modflow): manage internal "bin" dir structures

* less brittle tests

* test for consistent ostags in releases from all 3 repos

---------

Co-authored-by: w-bonelli <wbonelli@uga.edu>
  • Loading branch information
mwtoews and wpbonelli committed Jun 23, 2023
1 parent 43a39c2 commit a72a8c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
10 changes: 5 additions & 5 deletions autotest/test_get_modflow.py
Expand Up @@ -105,10 +105,6 @@ def test_get_releases(repo):
releases = get_releases(repo)
assert "latest" in releases

# test page size option
if repo == "modflow6-nightly-build":
assert len(releases) == 31 # last 30 releases +1 for "latest"


@flaky
@requires_github
Expand All @@ -119,6 +115,7 @@ def test_get_release(repo):
assets = release["assets"]

expected_assets = ["linux.zip", "mac.zip", "win64.zip"]
expected_ostags = [a.replace(".zip", "") for a in expected_assets]
actual_assets = [asset["name"] for asset in assets]

if repo == "modflow6":
Expand All @@ -127,7 +124,10 @@ def test_get_release(repo):
a for a in expected_assets if not a.startswith("win")
}
else:
assert set(actual_assets) >= set(expected_assets)
for ostag in expected_ostags:
assert any(
ostag in a for a in actual_assets
), f"dist not found for {ostag}"


@pytest.mark.parametrize("bindir", bindir_options.keys())
Expand Down
31 changes: 17 additions & 14 deletions flopy/utils/get_modflow.py
Expand Up @@ -9,6 +9,7 @@
"""
import json
import os
import shutil
import sys
import tempfile
import urllib
Expand Down Expand Up @@ -252,7 +253,7 @@ def select_bindir(bindir, previous=None, quiet=False, is_cli=False) -> Path:
f"invalid option '{bindir}', choose from: {opt_avail}"
)
if not quiet:
print(f"auto-selecting option {sel[0]!r} for '{bindir}'")
print(f"auto-selecting option {sel[0]!r} for 'bindir'")
return Path(options[sel[0]][0]).resolve()
else:
if not is_cli:
Expand Down Expand Up @@ -370,7 +371,7 @@ def run_main(
bindir, previous=prev_bindir, quiet=quiet, is_cli=_is_cli
)
elif not isinstance(bindir, (str, Path)):
raise ValueError(f"Invalid bindir option (expected string or Path)")
raise ValueError("Invalid bindir option (expected string or Path)")
bindir = Path(bindir).resolve()

# make sure bindir exists
Expand Down Expand Up @@ -473,21 +474,19 @@ def run_main(
if subset:
meta["subset"] = sorted(subset)
with zipfile.ZipFile(download_pth, "r") as zipf:
if repo == "modflow6":
# modflow6 release contains the whole repo with an internal bindir
for pth in zipf.namelist():
p = Path(pth)
if p.parent.name == "bin":
full_path[p.name] = pth
files = set(full_path.keys())
else:
# assume all files to be extracted
# First gather files within internal directories named "bin"
for pth in zipf.namelist():
p = Path(pth)
if p.parent.name == "bin":
full_path[p.name] = pth
files = set(full_path.keys())

if not files:
# there was no internal "bin", so assume all files to be extracted
files = set(zipf.namelist())

code = False
if "code.json" in files and repo == "executables":
# don't extract this file
files.remove("code.json")
code_bytes = zipf.read("code.json")
code = json.loads(code_bytes.decode())
if meta_path:
Expand All @@ -496,6 +495,10 @@ def run_main(
code_md5 = hashlib.md5(code_bytes).hexdigest()
meta["code_json_md5"] = code_md5

if "code.json" in files:
# don't extract this file
files.remove("code.json")

if subset:
nosub = False
subset_keys = files
Expand Down Expand Up @@ -587,7 +590,7 @@ def add_item(key, fname, do_chmod):
bindir_path = bindir / subdir
if bindir_path == bindir:
break
bindir_path.rmdir()
shutil.rmtree(str(bindir_path))

if ostag in ["linux", "mac"]:
# similar to "chmod +x fname" for each executable
Expand Down

0 comments on commit a72a8c9

Please sign in to comment.