Skip to content

Commit

Permalink
Improve permission error text (#64)
Browse files Browse the repository at this point in the history
* Improve permission error text

* Update utils.py
  • Loading branch information
cthoyt authored Nov 7, 2023
1 parent eecf60f commit 47a81c3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/pystow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,20 @@ def get_base(key: str, ensure_exists: bool = True) -> Path:


def ensure_readme() -> None:
"""Ensure there's a README in the PyStow data directory."""
readme_path = get_home(ensure_exists=True).joinpath("README.md")
"""Ensure there's a README in the PyStow data directory.
:raises PermissionError: If the script calling this function does not have
adequate permissions to write a file into the PyStow home directory.
"""
try:
readme_path = get_home(ensure_exists=True).joinpath("README.md")
except PermissionError as e:
raise PermissionError(
f"PyStow was not able to create its home directory in {readme_path.parent} due to a lack of "
"permissions. This can happen, e.g., if you're working on a server where you don't have full "
"rights. See https://pystow.readthedocs.io/en/latest/installation.html#configuration for instructions "
"on choosing a different home folder location for PyStow to somewhere where you have write permissions."
) from e
if readme_path.is_file():
return
with readme_path.open("w", encoding="utf8") as file:
Expand Down

0 comments on commit 47a81c3

Please sign in to comment.