From: Jelle Zijlstra Date: Tue, 27 Apr 2021 21:16:35 +0000 (-0700) Subject: Ignore inaccessible user config (#2158) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/ad1696422b7343a0cfea3c4b304e6acfa15d3cff Ignore inaccessible user config (#2158) Fixes #2157 --- diff --git a/CHANGES.md b/CHANGES.md index a30668d..cae61f2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ #### _Black_ +- Fix crash if the user configuration directory is inaccessible. (#2158) + - Clarify that _Black_ may change the AST, especially when cleaning up docstrings. (#2159) diff --git a/src/black/__init__.py b/src/black/__init__.py index 015ca41..1c69cc4 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -311,8 +311,17 @@ def find_pyproject_toml(path_search_start: Tuple[str, ...]) -> Optional[str]: if path_pyproject_toml.is_file(): return str(path_pyproject_toml) - path_user_pyproject_toml = find_user_pyproject_toml() - return str(path_user_pyproject_toml) if path_user_pyproject_toml.is_file() else None + try: + path_user_pyproject_toml = find_user_pyproject_toml() + return ( + str(path_user_pyproject_toml) + if path_user_pyproject_toml.is_file() + else None + ) + except PermissionError as e: + # We do not have access to the user-level config directory, so ignore it. + err(f"Ignoring user configuration directory due to {e!r}") + return None def parse_pyproject_toml(path_config: str) -> Dict[str, Any]: