Skip to content

Commit

Permalink
Create root if not exists (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
salu133445 committed Jan 3, 2021
1 parent 3310035 commit f92f315
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions muspy/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit f92f315

Please sign in to comment.