Describe the bug
Since black release v24.2 black ignores pyproject.toml
files without a [tool.black]
section. The bug arises because datamodel-codegen uses black's black.find_project_root
here, but that now that ignores pyproject.toml files without a [tool.black]
section, even if there is a [tool.datamodel-codegen]
section, as defined here:
for directory in (common_base, *common_base.parents):
if (directory / ".git").exists():
return directory, ".git directory"
if (directory / ".hg").is_dir():
return directory, ".hg directory"
if (directory / "pyproject.toml").is_file():
pyproject_toml = _load_toml(directory / "pyproject.toml")
if "black" in pyproject_toml.get("tool", {}):
return directory, "pyproject.toml"
At my job I'm working in a monorepo where the python package and the pyproject.toml
are in a subdirectory, i.e. with the structure <git root>/<python root>/pyproject.toml>
. We use ruff
to reformat all generated files, so we didn't have a black config in the pyproject.toml. I noticed that datamodel-codegen could not fild our pyproject.toml. It assumed the project root is the git root, since the pyproject.toml was ignored (see code snippet above).
To Reproduce
Expected behavior
Recognize pyproject.toml
if it's in subdirectory and has no [tool.black]
section, as long as it has [tool.datamodel-codegen]
section.
Version:
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too