RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.15k stars 555 forks source link

Force a specific version of `black` in format checking #2839

Closed ashleysommer closed 2 months ago

ashleysommer commented 2 months ago

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 commented 2 months ago

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

edmondchuc commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

Fixed by #2843