MCPcopy
hub / github.com/psf/black / find_pyproject_toml

Function find_pyproject_toml

src/black/files.py:98–117  ·  view source on GitHub ↗

Find the absolute filepath to a pyproject.toml if it exists

(
    path_search_start: tuple[str, ...], stdin_filename: str | None = None
)

Source from the content-addressed store, hash-verified

96
97
98def find_pyproject_toml(
99 path_search_start: tuple[str, ...], stdin_filename: str | None = None
100) -> str | None:
101 """Find the absolute filepath to a pyproject.toml if it exists"""
102 path_project_root, _ = find_project_root(path_search_start, stdin_filename)
103 path_pyproject_toml = path_project_root / "pyproject.toml"
104 if path_pyproject_toml.is_file():
105 return str(path_pyproject_toml)
106
107 try:
108 path_user_pyproject_toml = find_user_pyproject_toml()
109 return (
110 str(path_user_pyproject_toml)
111 if path_user_pyproject_toml.is_file()
112 else None
113 )
114 except (PermissionError, RuntimeError) as e:
115 # We do not have access to the user-level config directory, so ignore it.
116 err(f"Ignoring user configuration directory due to {e!r}")
117 return None
118
119
120@mypyc_attr(patchable=True)

Callers 1

read_pyproject_tomlFunction · 0.90

Calls 3

errFunction · 0.90
find_project_rootFunction · 0.85
find_user_pyproject_tomlFunction · 0.85

Tested by

no test coverage detected