Skip to content

Commit

Permalink
fix(generate_classes): use branch arg if provided (#1938)
Browse files Browse the repository at this point in the history
* previously branch was ignored even if provided
* add repo param to download_dfn() function
* fix logging output
* fix test
  • Loading branch information
wpbonelli authored Aug 31, 2023
1 parent 5d57fb7 commit 4f6cd47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 4 additions & 2 deletions autotest/test_generate_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,17 @@ def test_generate_classes_from_github_refs(
mod_file_times = [Path(mod_file).stat().st_mtime for mod_file in mod_files]
pprint(mod_files)

# generate classes
# split ref into owner, repo, ref name
spl = ref.split("/")
owner = spl[0]
repo = spl[1]
ref = spl[2]

# generate classes
pprint(
virtualenv.run(
"python -m flopy.mf6.utils.generate_classes "
f"--owner {owner} --repo {repo} ref {ref} --no-backup"
f"--owner {owner} --repo {repo} --ref {ref} --no-backup"
)
)

Expand Down
18 changes: 8 additions & 10 deletions flopy/mf6/utils/generate_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def list_files(pth, exts=["py"]):
print(f" {idx:5d} - {fn}")


def download_dfn(owner, branch, new_dfn_pth):
def download_dfn(owner, repo, ref, new_dfn_pth):
try:
from modflow_devtools.download import download_and_unzip
except ImportError:
Expand All @@ -61,8 +61,7 @@ def download_dfn(owner, branch, new_dfn_pth):
" pip install modflow-devtools"
)

mf6url = "https://github.com/{}/modflow6/archive/{}.zip"
mf6url = mf6url.format(owner, branch)
mf6url = f"https://github.com/{owner}/{repo}/archive/{ref}.zip"
print(f" Downloading MODFLOW 6 repository from {mf6url}")
with tempfile.TemporaryDirectory() as tmpdirname:
dl_path = download_and_unzip(mf6url, tmpdirname, verbose=True)
Expand Down Expand Up @@ -159,20 +158,19 @@ def generate_classes(
# download the dfn files and put them in flopy.mf6.data or update using
# user provided dfnpath
if dfnpath is None:
print(
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}")

# branch deprecated 3.5.0
if not ref:
if not branch:
raise ValueError("branch or ref must be provided")
if not ref and not branch:
raise ValueError("branch or ref must be provided")
if branch:
warn("branch is deprecated, use ref instead", DeprecationWarning)
ref = branch

download_dfn(owner, ref, new_dfn_pth)
print(f" Updating the MODFLOW 6 classes using {owner}/{repo}/{ref}")

download_dfn(owner, repo, ref, new_dfn_pth)
else:
print(f" Updating the MODFLOW 6 classes using {dfnpath}")
assert os.path.isdir(dfnpath)
Expand Down

0 comments on commit 4f6cd47

Please sign in to comment.