Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force a specific version of black in format checking #2839

Closed
ashleysommer opened this issue Jul 24, 2024 · 5 comments
Closed

Force a specific version of black in format checking #2839

ashleysommer opened this issue Jul 24, 2024 · 5 comments

Comments

@ashleysommer
Copy link
Contributor

Black is a tool for ensuring consistent python formatting from all contributors across the whole codebase.
Black was in beta for a long time, but in Jan 2023 it released its first "stable" version, where the code formatting generated by Black is considered "stable" and not subject to change.
However it is observed that people using different versions of "black" will produce different code than others, and if the CI tool is using a different version than a contributor is using, it can emit formatting errors and block the PR merge.

It is for this reason that black introduced the "required-version" config option. This way you can enforce only a specific version of black to be used, the tool will throw an error if a different version is being used.

This reflects the "lets pick one version of Black to use, and stick with it, and tell everyone to use that one" decision the RDFLib maintainers made back in April 2020.

The introduction of dependabot has bumped the version of "black" once or twice a month for the last two years. Black is the most commonly updated dependabot package, but there is no point updating it (outside of security fixes) and it makes it difficult for users to know which is the correct version to use.

I propose to merge just the latest version of "black" (v24.4.2), add "black" to the dependabot ignore list, and add the "required-version=24.4.2" to black config so we always use that version.

@ashleysommer
Copy link
Contributor Author

@nicholascar @edmondchuc
Does that sound like a good plan?

@edmondchuc
Copy link
Contributor

Sounds fine to me.

I'm also curious whether black is still needed since we are also using ruff for linting, because ruff also includes a more performant drop-in replacement formatter for black.

I haven't had the need for black for a while now as I just rely on linting, import sorting as well as formatting all on ruff.

@ashleysommer
Copy link
Contributor Author

Yeah, I had the same thought. The formatting provided by ruff and black are definitely different, but I don't know if one is better than the other. Ruff is a great all-in-one tool.
In the PySHACL codebase I've switched to Ruff for linting and import sorting, replacing flake8 and isort. But I've disabled Ruff's formatter, relying on Black for formatting, simply because I don't want to yet-again reformat every file in the codebase.

@edmondchuc
Copy link
Contributor

Ok cool, let's go with your plan and we can always revisit in the future whether we should drop black in favour of ruff format when we have time to investigate.

@ashleysommer
Copy link
Contributor Author

Fixed by #2843

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants