Skip to content

Commit

Permalink
Merge branch 'dev' into improve_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrakenhoff authored Jun 27, 2024
2 parents 2f24ed8 + f70f100 commit 3870331
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,4 @@ notoriously hard to install on certain platforms. Please see the

## Getting started

If you are using `nlmod` for the first time you need to download the MODFLOW
executables. You can easily download these executables by running this Python code:

import nlmod
nlmod.download_mfbinaries()

After you've downloaded the executables you can run the Jupyter Notebooks in the
examples folder. These notebooks illustrate how to use the `nlmod` package.
Start with the Jupyter Notebooks in the examples folder. These notebooks illustrate how to use the `nlmod` package.
19 changes: 0 additions & 19 deletions docs/examples/00_model_from_scratch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,6 @@
"nlmod.util.get_color_logger(\"INFO\");"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Download MODFLOW-binaries\n",
"To run MODFLOW, we need to download the MODFLOW-excecutables. We do this with the following code:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if not nlmod.util.check_presence_mfbinaries():\n",
" nlmod.download_mfbinaries()"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down
6 changes: 2 additions & 4 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ MODFLOW 6 model given a model dataset::

# ... add some boundary condition packages (GHB, RIV, DRN, ...)

Running the model requires the modflow binaries provided by the USGS. Those can
be downloaded with::

nlmod.download_mfbinaries()
The MODFLOW 6 executable is automatically downloaded and installed to your system
when building the first model.

Writing and running the model can then be done using::

Expand Down
33 changes: 30 additions & 3 deletions nlmod/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def get_bin_directory(
Parameters
----------
exe_name : str, optional
The name of the executable, by default None.
The name of the executable, by default mf6.
bindir : Path, optional
The directory where the executables are stored, by default "mf6".
download_if_not_found : bool, optional
Expand Down Expand Up @@ -232,7 +232,7 @@ def get_bin_directory(
if sys.platform.startswith("win") and not exe_name.endswith(".exe"):
exe_name += ".exe"

enable_version_check = version_tag is not None and repo is not None
enable_version_check = version_tag is not None

# If exe_name is a full path
if Path(exe_name).exists():
Expand Down Expand Up @@ -285,7 +285,11 @@ def get_bin_directory(

# Else download the executables
if download_if_not_found:
download_mfbinaries(bindir=bindir, version_tag=version_tag, repo=repo)
download_mfbinaries(
bindir=bindir,
version_tag=version_tag if version_tag is not None else "latest",
repo=repo
)

# Rerun this function
return get_bin_directory(
Expand Down Expand Up @@ -408,6 +412,29 @@ def download_mfbinaries(bindir=None, version_tag="latest", repo="executables"):

get_modflow(bindir=str(bindir), release_id=version_tag, repo=repo)

# Ensure metadata is saved.
# https://github.com/modflowpy/flopy/blob/
# 0748dcb9e4641b5ad9616af115dd3be906f98f50/flopy/utils/get_modflow.py#L623
flopy_metadata_fp = flopy_appdata_path / "get_modflow.json"

if not flopy_metadata_fp.exists():
if "pytest" not in str(bindir) and "pytest" not in sys.modules:
logger.warning(
f"flopy metadata file not found at {flopy_metadata_fp}. "
"After downloading and installing the executables. "
"Creating a new metadata file."
)

release_metadata = get_release(tag=version_tag, repo=repo, quiet=True)
install_metadata = {
"release_id": release_metadata["tag_name"],
"repo": repo,
"bindir": str(bindir),
}

with open(flopy_metadata_fp, "w", encoding="UTF-8") as f:
json.dump([install_metadata], f, indent=4)

# download the provisional version of modpath from Github
download_modpath_provisional_exe(bindir=bindir, timeout=120)

Expand Down

0 comments on commit 3870331

Please sign in to comment.