Skip to content

Commit

Permalink
Ignore inaccessible user config (#2158)
Browse files Browse the repository at this point in the history
Fixes #2157
  • Loading branch information
JelleZijlstra committed Apr 27, 2021
1 parent 807a65f commit ad16964
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -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)

Expand Down
13 changes: 11 additions & 2 deletions src/black/__init__.py
Expand Up @@ -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]:
Expand Down

0 comments on commit ad16964

Please sign in to comment.