diff --git a/autotest/test_mp7.py b/autotest/test_mp7.py index ae68f819..d8125605 100644 --- a/autotest/test_mp7.py +++ b/autotest/test_mp7.py @@ -1,4 +1,5 @@ import os +import re import shutil from pathlib import Path from platform import system @@ -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: diff --git a/pymake/pymake.py b/pymake/pymake.py index 9672cfab..b8b686ad 100644 --- a/pymake/pymake.py +++ b/pymake/pymake.py @@ -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 @@ -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. diff --git a/pymake/utils/usgsprograms.toml b/pymake/utils/usgsprograms.toml index 7966b7a0..346ff3ed 100644 --- a/pymake/utils/usgsprograms.toml +++ b/pymake/utils/usgsprograms.toml @@ -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