diff --git a/src/pymovements/utils/downloads.py b/src/pymovements/utils/downloads.py index fc053fd0c..3a245496d 100644 --- a/src/pymovements/utils/downloads.py +++ b/src/pymovements/utils/downloads.py @@ -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. @@ -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. @@ -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, ) diff --git a/tests/utils/downloads_test.py b/tests/utils/downloads_test.py index ae6ff3bc1..6d2b3a82c 100644 --- a/tests/utils/downloads_test.py +++ b/tests/utils/downloads_test.py @@ -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()