Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle error with cachedir creation gracefully #1287

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lhotse/tools/env.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import logging
import os
import sys
from pathlib import Path


def default_tools_cachedir() -> Path:
def default_tools_cachedir(force_mkdir: bool = False) -> Path:
d = Path.home() / ".lhotse/tools"
d.mkdir(exist_ok=True, parents=True)
try:
d.mkdir(exist_ok=True, parents=True)
except OSError:
if force_mkdir:
raise

Check warning on line 13 in lhotse/tools/env.py

View check run for this annotation

Codecov / codecov/patch

lhotse/tools/env.py#L11-L13

Added lines #L11 - L13 were not covered by tests
else:
logging.warning(

Check warning on line 15 in lhotse/tools/env.py

View check run for this annotation

Codecov / codecov/patch

lhotse/tools/env.py#L15

Added line #L15 was not covered by tests
f"We couldn't create lhotse utilities directory: {d} (not enough space/no permissions?)"
)
return d


Expand Down
5 changes: 4 additions & 1 deletion lhotse/tools/sph2pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import tarfile
from pathlib import Path
from typing import Optional

from lhotse.tools.env import default_tools_cachedir
from lhotse.utils import Pathlike, resumable_download, safe_extract
Expand All @@ -10,7 +11,7 @@


def install_sph2pipe(
where: Pathlike = default_tools_cachedir(),
where: Optional[Pathlike] = None,
download_from: str = SPH2PIPE_URL,
force: bool = False,
) -> None:
Expand All @@ -20,6 +21,8 @@

It downloads an archive and then decompresses and compiles the contents.
"""
if where is None:
where = default_tools_cachedir(force_mkdir=True)

Check warning on line 25 in lhotse/tools/sph2pipe.py

View check run for this annotation

Codecov / codecov/patch

lhotse/tools/sph2pipe.py#L24-L25

Added lines #L24 - L25 were not covered by tests
where = Path(where)
# Download
download_and_untar_sph2pipe(where, url=download_from, force_download=force)
Expand Down
Loading