From b8dffbc6bc7bee70d18d7ec24c96e33517e4f0e8 Mon Sep 17 00:00:00 2001 From: w-bonelli Date: Thu, 29 Jun 2023 08:21:05 -0400 Subject: [PATCH] fix(get-modflow): accommodate mf6 release asset name change (#1855) * accommodate mf6 windows release asset name change * reformat jupytext scripts (broken by running black) --- .docs/Notebooks/array_output_tutorial.py | 2 +- .docs/Notebooks/plot_cross_section_example.py | 2 +- .docs/Notebooks/plot_map_view_example.py | 6 +++--- autotest/test_flopy_module.py | 3 ++- flopy/utils/get_modflow.py | 18 +++++++----------- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.docs/Notebooks/array_output_tutorial.py b/.docs/Notebooks/array_output_tutorial.py index 7e56125a2..ac790a7af 100644 --- a/.docs/Notebooks/array_output_tutorial.py +++ b/.docs/Notebooks/array_output_tutorial.py @@ -25,9 +25,9 @@ # + [markdown] pycharm={"name": "#%% md\n"} # load and run the Freyberg model -import os # + pycharm={"name": "#%%\n"} +import os import sys from tempfile import TemporaryDirectory diff --git a/.docs/Notebooks/plot_cross_section_example.py b/.docs/Notebooks/plot_cross_section_example.py index 832a8f833..a17f1b12f 100644 --- a/.docs/Notebooks/plot_cross_section_example.py +++ b/.docs/Notebooks/plot_cross_section_example.py @@ -23,9 +23,9 @@ # # ### Mapping is demonstrated for MODFLOW-2005 and MODFLOW-6 models in this notebook -import os # + pycharm={"name": "#%%\n"} +import os import sys from tempfile import TemporaryDirectory diff --git a/.docs/Notebooks/plot_map_view_example.py b/.docs/Notebooks/plot_map_view_example.py index 3a489d182..d24854c7a 100644 --- a/.docs/Notebooks/plot_map_view_example.py +++ b/.docs/Notebooks/plot_map_view_example.py @@ -24,9 +24,9 @@ # ### Mapping is demonstrated for MODFLOW-2005, MODFLOW-USG, and MODFLOW-6 models in this notebook # -import os # + +import os import sys from tempfile import TemporaryDirectory @@ -315,8 +315,6 @@ # + [markdown] pycharm={"name": "#%% md\n"} # Array contours can be exported directly to a shapefile. -from shapefile import Reader - # + pycharm={"name": "#%%\n"} from flopy.export.utils import ( # use export_contourf for filled contours export_contours, @@ -325,6 +323,8 @@ shp_path = os.path.join(modelpth, "contours.shp") export_contours(shp_path, contour_set) +from shapefile import Reader + with Reader(shp_path) as r: nshapes = len(r.shapes()) print("Contours:", nshapes) diff --git a/autotest/test_flopy_module.py b/autotest/test_flopy_module.py index bc93fb997..1a4bd40ea 100644 --- a/autotest/test_flopy_module.py +++ b/autotest/test_flopy_module.py @@ -1,15 +1,16 @@ import os import re -from packaging.version import Version from pathlib import Path import numpy as np +from packaging.version import Version import flopy def test_import_and_version_string(): import flopy + # an error is raised if the version string can't be parsed Version(flopy.__version__) diff --git a/flopy/utils/get_modflow.py b/flopy/utils/get_modflow.py index 60442e350..2c979e163 100755 --- a/flopy/utils/get_modflow.py +++ b/flopy/utils/get_modflow.py @@ -396,18 +396,14 @@ def run_main( release = get_release(repo, release_id, quiet) assets = release.get("assets", []) - # Windows 64-bit asset in modflow6 repo release has no OS tag - if repo == "modflow6" and ostag == "win64": - asset = list(sorted(assets, key=lambda a: len(a["name"])))[0] + for asset in assets: + if ostag in asset["name"]: + break else: - for asset in assets: - if ostag in asset["name"]: - break - else: - raise ValueError( - f"could not find ostag {ostag!r} from release {release['tag_name']!r}; " - f"see available assets here:\n{release['html_url']}" - ) + raise ValueError( + f"could not find ostag {ostag!r} from release {release['tag_name']!r}; " + f"see available assets here:\n{release['html_url']}" + ) asset_name = asset["name"] download_url = asset["browser_download_url"] if repo == "modflow6":