Skip to content

Commit

Permalink
refactor(download_and_unzip): return path to extract locn (#96)
Browse files Browse the repository at this point in the history
* docs: fix README typo
  • Loading branch information
wpbonelli authored Aug 4, 2023
1 parent 72e29e1 commit c1bdb3c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Python development tools for MODFLOW 6.

This is a small toolkit for developing MODFLOW 6, FloPy, and related projects. It includes standalone utilities and optional [Pytest](https://github.com/pytest-dev/pytest) extensions.

Standalone utilities include a very minimal GitHub API client, mainly for retrieving release information and downloading asset, and a `ZipFile` subclass that [preserves file permissions](https://stackoverflow.com/questions/39296101/python-zipfile-removes-execute-permissions-from-binaries) (workaround for [Python #15795](https://bugs.python.org/issue15795))
Standalone utilities include a very minimal GitHub API client, mainly for retrieving release information and downloading assets, and a `ZipFile` subclass that [preserves file permissions](https://stackoverflow.com/questions/39296101/python-zipfile-removes-execute-permissions-from-binaries) (workaround for [Python #15795](https://bugs.python.org/issue15795))

Pytest features include:

Expand Down
2 changes: 2 additions & 0 deletions docs/md/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ from modflow_devtools.download import download_and_unzip
url = f"https://github.com/MODFLOW-USGS/modflow6/releases/download/6.4.1/mf6.4.1_linux.zip"
download_and_unzip(url, "~/Downloads", delete_zip=True, verbose=True)
```

The function's return value is the `Path` the archive was extracted to.
9 changes: 8 additions & 1 deletion modflow_devtools/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def download_and_unzip(
delete_zip=True,
retries=3,
verbose=False,
):
) -> Path:
"""
Download and unzip a zip file from a URL.
The filename must be the last element in the URL.
Expand All @@ -455,6 +455,11 @@ def download_and_unzip(
The maximum number of retries for each request
verbose : bool
Whether to show verbose output
Returns
-------
Path
The path to the directory where the zip file was unzipped
"""

path = Path(path if path else os.getcwd())
Expand Down Expand Up @@ -544,3 +549,5 @@ def download_and_unzip(

if verbose:
print(f"Done downloading and extracting {file_path.name} to {path}")

return path

0 comments on commit c1bdb3c

Please sign in to comment.