Fix Black version detection

Black made a significant change in the format of the --version output string between versions 21.10 ("black, version 21.10b0") and 21.11 ("black, 21.11b0 (compiled: no)"), which breaks the assumption in black_version() that the numeric version token will always be the last element of a .split() on the output string.

I changed the logic to instead report the first .split() component that begins with a decimal digit. This has been tested to work correctly for all black versions between 21.6b0, and I verified that all of the version strings available in pip (starting at 18.30) do indeed begin with a decimal digit. This branch started life as part of my work to get merge request !94 (closed) to pass the CI test pipeline; after I grasped the problem I decided to separate it out into a separate request as it's a simpler issue and has the potential to affect more users as they upgrade local toolchains.

Of note, the latest black release as of this writing (21.12b0) keeps the new --version format introduced by 21.11b0, so I assume it's not a one-off or regression. However, I do not recommend that diffoscope users switch to black 21.12b0 yet, as it has a different regression that wants to remove a newline from diffoscope/comparators/directory.py, which all other recent versions of black (including the one in the CI pipeline environment) want to re-insert.

Edited by Brent Spillner

Merge request reports

Loading