Skip to content

Commit

Permalink
fix(get-modflow): fix code.json handling (#1641)
Browse files Browse the repository at this point in the history
* fix(get-modflow): fix subsets

* fix(get-modflow): don't depend on modflow6 dist folder name
  • Loading branch information
wpbonelli committed Dec 8, 2022
1 parent 869787a commit 57d0862
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
10 changes: 6 additions & 4 deletions autotest/test_get_modflow.py
Expand Up @@ -33,7 +33,6 @@
"executables": [
"crt",
"gridgen",
"gsflow",
"mf2000",
"mf2005",
"mf2005dbl",
Expand Down Expand Up @@ -140,7 +139,7 @@ def test_select_bindir(bindir, tmpdir):
pytest.skip(f"{expected_path} is not writable")
selected = select_bindir(f":{bindir}")

if system() != 'Darwin':
if system() != "Darwin":
assert selected == expected_path
else:
# for some reason sys.prefix can return different python
Expand All @@ -162,6 +161,7 @@ def test_script_help():

@flaky
@requires_github
@pytest.mark.slow
def test_script_options(tmpdir, downloads_dir):
bindir = tmpdir / "bin1"
assert not bindir.exists()
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_script_options(tmpdir, downloads_dir):
pytest.skip(f"GitHub {rate_limit_msg}")
assert len(stderr) == returncode == 0
files = [item.stem for item in bindir.iterdir() if item.is_file()]
assert sorted(files) == ["mfnwt", "mfnwtdbl", "mp6"]
assert sorted(files) == ["mfnwt", "mp6"]

# similar as before, but also specify a ostag
bindir = tmpdir / "bin3"
Expand All @@ -234,11 +234,12 @@ def test_script_options(tmpdir, downloads_dir):
pytest.skip(f"GitHub {rate_limit_msg}")
assert len(stderr) == returncode == 0
files = [item.name for item in bindir.iterdir() if item.is_file()]
assert sorted(files) == ["mfnwt.exe", "mfnwtdbl.exe"]
assert sorted(files) == ["mfnwt.exe"]


@flaky
@requires_github
@pytest.mark.slow
@pytest.mark.parametrize("repo", repo_options.keys())
def test_script(tmpdir, repo, downloads_dir):
bindir = str(tmpdir)
Expand All @@ -260,6 +261,7 @@ def test_script(tmpdir, repo, downloads_dir):

@flaky
@requires_github
@pytest.mark.slow
@pytest.mark.parametrize("repo", repo_options.keys())
def test_python_api(tmpdir, repo, downloads_dir):
bindir = str(tmpdir)
Expand Down
20 changes: 15 additions & 5 deletions flopy/utils/get_modflow.py
Expand Up @@ -179,7 +179,7 @@ def get_release(repo, tag="latest", quiet=False) -> dict:
release = json.loads(result.decode())
tag_name = release["tag_name"]
if not quiet:
print(f"fetched release {tag_name!r} from {owner}/{repo}")
print(f"fetched release {tag_name!r} info from {owner}/{repo}")

return release

Expand Down Expand Up @@ -444,14 +444,24 @@ def run_main(
)
else:
if not quiet:
print(f"downloading to '{download_pth}'")
print(f"downloading '{download_url}' to '{download_pth}'")
urllib.request.urlretrieve(download_url, download_pth)

if subset:
if isinstance(subset, str):
subset = set(subset.replace(",", " ").split())
elif not isinstance(subset, set):
subset = set(subset)
subset = set(
[
(
f"{e}{lib_suffix}"
if e.startswith("lib")
else f"{e}{exe_suffix}"
)
for e in subset
]
)

# Open archive and extract files
extract = set()
Expand All @@ -475,10 +485,10 @@ def run_main(
with zipfile.ZipFile(download_pth, "r") as zipf:
if repo == "modflow6":
# modflow6 release contains the whole repo with an internal bindir
inner_bin = asset_stem + "/bin"
for pth in zipf.namelist():
if pth.startswith(inner_bin) and not pth.endswith("bin/"):
full_path[Path(pth).name] = pth
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
Expand Down

0 comments on commit 57d0862

Please sign in to comment.