From 47a81c3f5ee4ff61f839425eab11edfc26d2ab84 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Tue, 7 Nov 2023 08:51:00 +0100 Subject: [PATCH] Improve permission error text (#64) * Improve permission error text * Update utils.py --- src/pystow/utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pystow/utils.py b/src/pystow/utils.py index d7a24dc..5b724ef 100644 --- a/src/pystow/utils.py +++ b/src/pystow/utils.py @@ -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: