Skip to content

Commit

Permalink
Added funtionality to remove top-level directory to downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
josephine-funken committed Sep 27, 2023
1 parent 4f4ab5d commit 22bf1f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/pymovements/utils/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def download_and_extract_archive(
md5: str | None = None,
recursive: bool = True,
remove_finished: bool = False,
remove_top_level: bool = True,
verbose: int = 1,
) -> None:
"""Download and extract archive file.
Expand All @@ -60,6 +61,8 @@ def download_and_extract_archive(
Recursively extract archives which are included in extracted archive.
remove_finished : bool
Remove downloaded file after successful extraction or decompression, default: False.
remove_top_level: bool
If ``True``, remove the top-level directory if it has only one child, default:True.
verbose : int
Verbosity levels: (1) Show download progress bar and print info messages on downloading
and extracting archive files without printing messages for recursive archive extraction.
Expand Down Expand Up @@ -87,6 +90,7 @@ def download_and_extract_archive(
destination_path=extract_dirpath,
recursive=recursive,
remove_finished=remove_finished,
remove_top_level=remove_top_level,
verbose=verbose,
)

Expand Down
9 changes: 8 additions & 1 deletion tests/utils/downloads_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,14 @@ def test_download_and_extract_archive(tmp_path):
md5 = '52bbf03a7c50ee7152ccb9d357c2bb30'
extract_dirpath = tmp_path / 'extracted'

download_and_extract_archive(url, tmp_path, download_filename, extract_dirpath, md5)
download_and_extract_archive(
url,
tmp_path,
download_filename,
extract_dirpath,
md5,
remove_top_level=False,
)

assert extract_dirpath.exists()
assert (extract_dirpath / 'pymovements-0.4.0').exists()
Expand Down

0 comments on commit 22bf1f8

Please sign in to comment.