Ignore inaccessible user config (#2158)

Fixes #2157
This commit is contained in:
Jelle Zijlstra 2021-04-27 14:16:35 -07:00 committed by GitHub
parent 807a65f9d5
commit ad1696422b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -4,6 +4,8 @@
#### _Black_ #### _Black_
- Fix crash if the user configuration directory is inaccessible. (#2158)
- Clarify that _Black_ may change the AST, especially when cleaning up docstrings. - Clarify that _Black_ may change the AST, especially when cleaning up docstrings.
(#2159) (#2159)

View File

@ -311,8 +311,17 @@ def find_pyproject_toml(path_search_start: Tuple[str, ...]) -> Optional[str]:
if path_pyproject_toml.is_file(): if path_pyproject_toml.is_file():
return str(path_pyproject_toml) return str(path_pyproject_toml)
path_user_pyproject_toml = find_user_pyproject_toml() try:
return str(path_user_pyproject_toml) if path_user_pyproject_toml.is_file() else None 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]: def parse_pyproject_toml(path_config: str) -> Dict[str, Any]: