Feature Request - add required black version in pyproject.toml #1246
Labels
C: configuration
CLI and configuration
S: accepted
The changes in this design / enhancement issue have been accepted and can be implemented
T: enhancement
New feature or request
Many projects that I contribute to have adopted black. (Congrats and Thank You!)
An issue which has come up in multiple projects is automatic tests failing because of differences in the installed
black
versions between environments.For example: a project may indicate a particular version of black in a pre-commit configuration in
.pre-commit-config.yaml
(https://black.readthedocs.io/en/stable/version_control_integration.html) which will re-format the code to that version... but that will not-necessarily be the same version which is invoked by the local developer or the build/deploy service - as black will consult thepyproject.toml
file instead (https://black.readthedocs.io/en/stable/pyproject_toml.html).This can create issues on automated tests, because the server environment may be configured to install
19.3b0
while the hook or developer's environment is formatting to19.10b0
. This can suggest a developer didn't runblack
or made an error, when the build/deploy system is what requires adjustment.A potential solution is to extend the
pyproject.toml
configuration to have an argument which states the required version:If specified, black would then raise a fatal exception if invoked with a version that does not match. Perhaps a commandline flag is needed to avoid this for certain causes. Some projects specify a specific version of black for a particular test environment in
tox.ini
, but nothing is global.An alternative might also include migrating the version declaration from the
.pre-commit-config.yaml
into thepyproject.toml
file, where it seems to be more applicable. However, I assume the revision was declared in this file for important reasons I do not understand yet.To summarize:
having a centralized version pin, instead of requiring a version pin for each context, would eliminate many problems.
Thank you.
see also: #420
The text was updated successfully, but these errors were encountered: