Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(download_and_unzip): return path to extract locn #96

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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