Skip to content

Commit

Permalink
Local implementation of find_pyproject_toml()
Browse files Browse the repository at this point in the history
This ensures we use `find_project_root()` from Darkgraylib, avoiding
incompatibilities with different Black versions.
  • Loading branch information
akaihola committed Mar 8, 2024
1 parent 8059d1d commit 5181d04
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/darker/black_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from black import FileMode as Mode
from black import (
TargetVersion,
find_pyproject_toml,
format_str,
parse_pyproject_toml,
re_compile_maybe_verbose,
Expand All @@ -53,6 +52,7 @@
from black.files import gen_python_files
from black.report import Report

from darker.files import find_pyproject_toml
from darkgraylib.config import ConfigurationError
from darkgraylib.utils import TextDocument

Expand Down
27 changes: 27 additions & 0 deletions src/darker/files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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, ...], stdin_filename: Optional[str] = None
) -> Optional[str]:
"""Find the absolute filepath to a pyproject.toml if it exists"""
path_project_root, _ = find_project_root(path_search_start, stdin_filename)
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

0 comments on commit 5181d04

Please sign in to comment.