From 9ccf279a17ff19cc51f62c60fc88ba46e615d202 Mon Sep 17 00:00:00 2001 From: Michael Eliachevitch Date: Fri, 2 Aug 2024 18:38:07 +0200 Subject: [PATCH] Document `find_project_root` ignoring `pyproject.toml` without `[tool.black]` (#4425) Extend the docstring of black's `find_project_root` to mention that it ignores `pyproject.toml` files without a `[tool.black]` section. This is relevant because that function is also used by other python packages that use black. I found that e.g. datamodel-code-generator [1] uses that function and that there the ignoring of the pyproject.toml files lead to a degradation [2]. I think in that case it would be better to not use black's function for finding the pyproject.toml, but in any case this behavior should be documented. 1: https://github.com/koxudaxi/datamodel-code-generator 2: https://github.com/koxudaxi/datamodel-code-generator/issues/2052 Co-authored-by: Michael Eliachevitch --- src/black/files.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/black/files.py b/src/black/files.py index 3be1ed9b00f..d4c1208076b 100644 --- a/src/black/files.py +++ b/src/black/files.py @@ -59,6 +59,9 @@ def find_project_root( ) -> Tuple[Path, str]: """Return a directory containing .git, .hg, or pyproject.toml. + pyproject.toml files are only considered if they contain a [tool.black] + section and are ignored otherwise. + That directory will be a common parent of all files and directories passed in `srcs`.