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

Informative error message when directory is not writeable #752

Closed
wants to merge 3 commits into from
Closed
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
19 changes: 17 additions & 2 deletions src/inspect_ai/_util/appdirs.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import textwrap
from pathlib import Path

from platformdirs import user_cache_path, user_runtime_path

from inspect_ai._util.constants import PKG_NAME


def _xdg_error(dir_type: str, dir: Path) -> str:
return textwrap.dedent(f"""{dir_type} directory {dir} is not writeable.
This may be because you are running Inspect without a normal login session.
On Linux, try setting XDG_RUNTIME_DIR to somewhere writeable.
See also https://github.com/UKGovernmentBEIS/inspect_ai/issues/51.""")


def inspect_runtime_dir(subdir: str | None) -> Path:
runtime_dir = user_runtime_path(PKG_NAME)
if subdir:
runtime_dir = runtime_dir / subdir
runtime_dir.mkdir(parents=True, exist_ok=True)
try:
runtime_dir.mkdir(parents=True, exist_ok=True)
except PermissionError as e:
raise Exception(_xdg_error("Runtime", runtime_dir)) from e
return runtime_dir


def inspect_cache_dir(subdir: str | None) -> Path:
cache_dir = user_cache_path(PKG_NAME)
if subdir:
cache_dir = cache_dir / subdir
cache_dir.mkdir(parents=True, exist_ok=True)
# catch this failure, suggest setting XDG_CACHE_HOME
try:
cache_dir.mkdir(parents=True, exist_ok=True)
except PermissionError as e:
raise Exception(_xdg_error("Cache", cache_dir)) from e
return cache_dir
Loading