-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #550 from akaihola/black-24.2-compat
Provide compatibility with Black 24.2
- Loading branch information
Showing
9 changed files
with
59 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Helper functions for working with files and directories.""" | ||
|
||
from typing import Optional, Tuple | ||
|
||
from black import err, find_user_pyproject_toml | ||
|
||
from darkgraylib.files import find_project_root | ||
|
||
|
||
def find_pyproject_toml(path_search_start: Tuple[str, ...]) -> Optional[str]: | ||
"""Find the absolute filepath to a pyproject.toml if it exists""" | ||
path_project_root = find_project_root(path_search_start) | ||
path_pyproject_toml = path_project_root / "pyproject.toml" | ||
if path_pyproject_toml.is_file(): | ||
return str(path_pyproject_toml) | ||
|
||
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, RuntimeError) 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Test for the `darker.files` module.""" | ||
|
||
import io | ||
from contextlib import redirect_stderr | ||
from pathlib import Path | ||
from unittest.mock import MagicMock, patch | ||
|
||
from darker import files | ||
|
||
|
||
@patch("darker.files.find_user_pyproject_toml") | ||
def test_find_pyproject_toml(find_user_pyproject_toml: MagicMock) -> None: | ||
"""Test `files.find_pyproject_toml` with no user home directory.""" | ||
find_user_pyproject_toml.side_effect = RuntimeError() | ||
with redirect_stderr(io.StringIO()) as stderr: | ||
# end of test setup | ||
|
||
result = files.find_pyproject_toml(path_search_start=(str(Path.cwd().root),)) | ||
|
||
assert result is None | ||
err = stderr.getvalue() | ||
assert "Ignoring user configuration" in err |