-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Local implementation of
find_pyproject_toml()
This ensures we use `find_project_root()` from Darkgraylib, avoiding incompatibilities with different Black versions.
- Loading branch information
Showing
2 changed files
with
28 additions
and
1 deletion.
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
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 |