From a10b6c7a8db3fb83628c2997968e4e1c67d5b8d3 Mon Sep 17 00:00:00 2001 From: Wes Bonelli Date: Sat, 5 Aug 2023 01:07:28 -0400 Subject: [PATCH] refactor(generate_classes): deprecate branch for ref, test commit hashes --- autotest/test_generate_classes.py | 24 +++++++++++++++++------- flopy/mf6/utils/generate_classes.py | 27 ++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/autotest/test_generate_classes.py b/autotest/test_generate_classes.py index e48c73eb17..06e5522552 100644 --- a/autotest/test_generate_classes.py +++ b/autotest/test_generate_classes.py @@ -17,10 +17,14 @@ def nonempty(itr: Iterable): def pytest_generate_tests(metafunc): # defaults + owner = "MODFLOW-USGS" + repo = "modflow6" ref = [ - "MODFLOW-USGS/modflow6/develop", - "MODFLOW-USGS/modflow6/master", - "MODFLOW-USGS/modflow6/6.4.1", + f"{owner}/{repo}/develop", + f"{owner}/{repo}/master", + f"{owner}/{repo}/6.4.1", + f"{owner}/{repo}/4458f9f", + f"{owner}/{repo}/4458f9f7a6244182e6acc2430a6996f9ca2df367", ] # refs provided as env vars override the defaults @@ -51,7 +55,10 @@ def pytest_generate_tests(metafunc): @pytest.mark.mf6 @pytest.mark.slow -def test_generate_classes_from_dfn(virtualenv, project_root_path, ref): +@pytest.mark.parametrize("ref_arg", ["ref", "branch"]) +def test_generate_classes_from_dfn( + virtualenv, project_root_path, ref, ref_arg +): python = virtualenv.python venv = Path(python).parent print( @@ -81,13 +88,16 @@ def test_generate_classes_from_dfn(virtualenv, project_root_path, ref): # generate classes spl = ref.split("/") owner = spl[0] - branch = spl[2] + repo = spl[1] + ref = spl[2] pprint( virtualenv.run( "python -c 'from flopy.mf6.utils import generate_classes; generate_classes(owner=\"" + owner - + '", branch="' - + branch + + '", repo="' + + repo + + f'", {ref_arg}="' + + ref + "\", backup=False)'" ) ) diff --git a/flopy/mf6/utils/generate_classes.py b/flopy/mf6/utils/generate_classes.py index ab078e33bb..2a4aabc1ac 100644 --- a/flopy/mf6/utils/generate_classes.py +++ b/flopy/mf6/utils/generate_classes.py @@ -2,6 +2,7 @@ import shutil import tempfile import time +from warnings import warn from .createpackages import create_packages @@ -104,7 +105,12 @@ def delete_mf6_classes(): def generate_classes( - owner="MODFLOW-USGS", branch="master", dfnpath=None, backup=True + owner="MODFLOW-USGS", + repo="modflow6", + branch="master", + ref=None, + dfnpath=None, + backup=True, ): """ Generate the MODFLOW 6 flopy classes using definition files from the @@ -116,9 +122,16 @@ def generate_classes( owner : str Owner of the MODFLOW 6 repository to use to update the definition files and generate the MODFLOW 6 classes. Default is MODFLOW-USGS. + repo : str + Name of the MODFLOW 6 repository to use to update the definition. branch : str Branch name of the MODFLOW 6 repository to use to update the definition files and generate the MODFLOW 6 classes. Default is master. + + .. deprecated:: 3.5.0 + Use ref instead. + ref : str + Branch name, tag, or commit hash to use to update the definition. dfnpath : str Path to a definition file folder that will be used to generate the MODFLOW 6 classes. Default is none, which means that the branch @@ -140,11 +153,19 @@ def generate_classes( # user provided dfnpath if dfnpath is None: print( - f" Updating the MODFLOW 6 classes using {owner}/modflow6/{branch}" + f" Updating the MODFLOW 6 classes using {owner}/{repo}/{branch}" ) timestr = time.strftime("%Y%m%d-%H%M%S") new_dfn_pth = os.path.join(flopypth, "mf6", "data", f"dfn_{timestr}") - download_dfn(owner, branch, new_dfn_pth) + + # branch deprecated 3.5.0 + if not ref: + if not branch: + raise ValueError("branch or ref must be provided") + warn("branch is deprecated, use ref instead") + ref = branch + + download_dfn(owner, ref, new_dfn_pth) else: print(f" Updating the MODFLOW 6 classes using {dfnpath}") assert os.path.isdir(dfnpath)