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
10 changes: 10 additions & 0 deletions autotest/test_mp7.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import shutil
from pathlib import Path
from platform import system
Expand Down Expand Up @@ -98,6 +99,15 @@ def replace_data(dpth):
with open(fpth, "w") as f:
f.writelines(content)

# MODFLOW 6.8.0 removed the IMS keywords OUTER_HCLOSE and INNER_HCLOSE,
# which the examples still use, in favor of OUTER_DVCLOSE and INNER_DVCLOSE
for fname in fpths:
if not fname.lower().endswith(".ims"):
continue
fpth = Path(dpth) / fname
text = fpth.read_text()
fpth.write_text(re.sub(r"(?i)\b(outer|inner)_hclose\b", r"\1_DVCLOSE", text))


def set_lowercase(fpth):
with open(fpth, "r") as f:
Expand Down
31 changes: 30 additions & 1 deletion pymake/pymake.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
_get_osname,
)
from .utils._usgs_src_update import _build_replace
from .utils.download import download_and_unzip, zip_all
from .utils.download import download_and_unzip, pymakeZipFile, zip_all
from .utils.usgsprograms import usgs_program_data

# targets whose distributed meson build files are removed after download, so
Expand Down Expand Up @@ -415,10 +415,39 @@ def download_url(self):
timeout=self.timeout,
verbose=self.verbose,
)
if self.download and not Path(self.download_dir).is_dir():
self._extract_nested()
if self.download and self._get_base_target() in _IGNORE_PROVIDED_MESON:
self._remove_provided_meson()
return self.download

def _extract_nested(self):
"""Extract a distribution zip nested in the downloaded archive.

Some legacy USGS downloads wrap the distribution zip, with its
documentation, in an outer zip. If the expected directory is missing
after the download, look for a zip with the directory's name among the
extracted files and extract it in its place.

Returns
-------

"""
download_path = Path(self.download_path)
name = Path(self.download_dir).name
for inner in download_path.rglob(f"{name}.zip"):
if self.verbose:
print(f"uncompressing nested...'{inner}'")
with pymakeZipFile(inner) as z:
z.extractall(download_path)
# remove what remains of the outer archive
wrapper = download_path / inner.relative_to(download_path).parts[0]
if wrapper == inner:
inner.unlink()
else:
shutil.rmtree(wrapper)
return

def _remove_provided_meson(self):
"""Remove the meson build files distributed with a downloaded target.

Expand Down
2 changes: 1 addition & 1 deletion pymake/utils/usgsprograms.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ shared_object = false
[program."swtv4"]
version = "4.00.05"
current = true
url = "https://water.usgs.gov/water-resources/software/SEAWAT/swt_v4_00_05.zip"
url = "https://water.usgs.gov/water-resources/legacy-software/SEAWAT/swt_v4_00_05.zip"
dirname = "swt_v4_00_05"
srcdir = "source"
standard_precision = false
Expand Down
Loading