Skip to content

Commit

Permalink
refactor(download_and_unzip): return path to extract locn
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Aug 4, 2023
1 parent 9e7eaa7 commit 4a1fafb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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 4a1fafb

Please sign in to comment.