Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore inaccessible user config #2158

Merged
merged 5 commits into from Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add some logging (atleast @ debug level) so we at least tell the user why their config is not being picked up.

  • Could save hours of debugging for someone one day
  • Silent swallowing at debug level is evil

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I made it just unconditionally print for now. Maybe we'd want to do it only if -v is passed, but that's hard because this code gets executed during argument parsing.

err(f"Ignoring user configuration directory due to {e!r}")
return None


def parse_pyproject_toml(path_config: str) -> Dict[str, Any]:
Expand Down