Skip to content

Commit

Permalink
Add: ZIP path to global configurables paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
Labbeti committed Oct 19, 2023
1 parent ad2c124 commit 7599e11
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/aac_datasets/datasets/wavcaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from aac_datasets.datasets.base import AACDataset, DatasetCard
from aac_datasets.utils.collections import list_dict_to_dict_list
from aac_datasets.utils.download import safe_rmdir
from aac_datasets.utils.paths import _get_root
from aac_datasets.utils.paths import _get_root, _get_zip_path


pylog = logging.getLogger(__name__)
Expand Down Expand Up @@ -159,7 +159,6 @@ class WavCaps(AACDataset[WavCapsItem]):
REPO_ID: ClassVar[str] = "cvssp/WavCaps"
RESUME_DL: ClassVar[bool] = True
SIZE_CATEGORIES: Tuple[str, ...] = ("100K<n<1M",)
ZIP_PATH: ClassVar[str] = "zip"

def __init__(
self,
Expand All @@ -170,6 +169,7 @@ def __init__(
hf_cache_dir: Optional[str] = None,
revision: Optional[str] = WavCapsCard.DEFAULT_REVISION,
verbose: int = 1,
zip_path: Optional[str] = None,
) -> None:
"""
:param root: The parent of the dataset root directory.
Expand All @@ -187,6 +187,8 @@ def __init__(
defaults to :attr:`~WavCapsCard.DEFAULT_REVISION`.
:param verbose: Verbose level. Can be 0 or 1.
defaults to 0.
:param zip_path: Path to zip executable path in shell.
defaults to "zip".
"""
if subset not in WavCapsCard.SUBSETS:
raise ValueError(
Expand All @@ -205,7 +207,7 @@ def __init__(
force=WavCaps.FORCE_PREPARE_DATA,
verify_files=WavCaps.VERIFY_FILES,
clean_archives=WavCaps.CLEAN_ARCHIVES,
zip_path=WavCaps.ZIP_PATH,
zip_path=zip_path,
verbose=verbose,
)

Expand Down Expand Up @@ -515,7 +517,7 @@ def _prepare_wavcaps_dataset(
force: bool,
verify_files: bool,
clean_archives: bool,
zip_path: str,
zip_path: Optional[str],
verbose: int,
) -> None:
if subset == "as_noac":
Expand Down Expand Up @@ -545,6 +547,8 @@ def _prepare_wavcaps_dataset(
verbose,
)

zip_path = _get_zip_path(zip_path)

if subset not in WavCapsCard.SUBSETS:
raise ValueError(
f"Invalid argument subset={subset}. (expected one of {WavCapsCard.SUBSETS})"
Expand Down
32 changes: 28 additions & 4 deletions src/aac_datasets/utils/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"env": "AAC_DATASETS_FFMPEG_PATH",
"package": "ffmpeg",
},
"zip": {
"user": None,
"env": "AAC_DATASETS_ZIP_PATH",
"package": "zip",
},
}


Expand Down Expand Up @@ -61,6 +66,16 @@ def get_default_ffmpeg_path() -> str:
return __get_default_path("ffmpeg")


def get_default_zip_path() -> str:
"""Returns the default zip executable path.
If :func:`~aac_datasets.utils.path.set_default_zip_path` has been used before with a string argument, it will return the value given to this function.
Else if the environment variable AAC_DATASETS_ZIP_PATH has been set to a string, it will return its value.
Else it will be equal to "zip" by default.
"""
return __get_default_path("zip")


def set_default_root(cache_path: Optional[str]) -> None:
"""Override default root directory path."""
__set_default_path("root", cache_path)
Expand All @@ -76,19 +91,28 @@ def set_default_ffmpeg_path(tmp_path: Optional[str]) -> None:
__set_default_path("ffmpeg", tmp_path)


def set_default_zip_path(tmp_path: Optional[str]) -> None:
"""Override default zip executable path."""
__set_default_path("zip", tmp_path)


# Private functions
def _get_root(root: Union[str, None] = ...) -> str:
def _get_root(root: Union[str, None] = None) -> str:
return __get_path("root", root)


def _get_ytdl_path(ytdl_path: Union[str, None] = ...) -> str:
def _get_ytdl_path(ytdl_path: Union[str, None] = None) -> str:
return __get_path("ytdl", ytdl_path)


def _get_ffmpeg_path(ffmpeg_path: Union[str, None] = ...) -> str:
def _get_ffmpeg_path(ffmpeg_path: Union[str, None] = None) -> str:
return __get_path("ffmpeg", ffmpeg_path)


def _get_zip_path(zip_path: Union[str, None] = None) -> str:
return __get_path("zip", zip_path)


def __get_default_path(path_name: str) -> str:
paths = __DEFAULT_PATHS[path_name]

Expand Down Expand Up @@ -120,7 +144,7 @@ def __set_default_path(
__DEFAULT_PATHS[path_name]["user"] = path


def __get_path(path_name: str, path: Union[str, None] = ...) -> str:
def __get_path(path_name: str, path: Union[str, None] = None) -> str:
if path is ... or path is None:
return __get_default_path(path_name)
else:
Expand Down

0 comments on commit 7599e11

Please sign in to comment.