From f92f3159edd2d27a592fb6e0b9940818f9561616 Mon Sep 17 00:00:00 2001 From: Hao-Wen Dong Date: Sun, 3 Jan 2021 00:17:04 -0800 Subject: [PATCH] Create root if not exists (#34) --- muspy/datasets/base.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/muspy/datasets/base.py b/muspy/datasets/base.py index 8642143e..923041ae 100644 --- a/muspy/datasets/base.py +++ b/muspy/datasets/base.py @@ -138,8 +138,7 @@ def save( raise TypeError("`kind` must be either 'json' or 'yaml'.") root = Path(root).expanduser().resolve() - if not root.exists(): - raise ValueError("`root` must be an existing path.") + root.mkdir(exist_ok=True) def _saver(idx): prefix = "0" * (n_digits - len(str(idx))) @@ -486,10 +485,7 @@ def __init__( ): super().__init__() self.root = Path(root).expanduser().resolve() - if not self.root.exists(): - raise ValueError("`root` must be an existing path.") - if not self.root.is_dir(): - raise ValueError("`root` must be a directory.") + self.root.mkdir(exist_ok=True) if download_and_extract: self.download_and_extract(cleanup) @@ -700,10 +696,7 @@ class MusicDataset(Dataset): def __init__(self, root: Union[str, Path], kind: str = "json"): self.root = Path(root).expanduser().resolve() - if not self.root.exists(): - raise ValueError("`root` must be an existing path.") - if not self.root.is_dir(): - raise ValueError("`root` must be a directory.") + self.root.mkdir(exist_ok=True) self.kind = kind self.filenames = sorted(self.root.rglob("*." + self.kind))