[Twisted-Python] Black enabled in trunk

Tom Most twm at freecog.net
Mon Sep 14 00:45:43 MDT 2020


Hi all,

Craig and I have been working to land a switch to The *Black* Coding Style <https://black.readthedocs.io/en/stable/the_black_code_style.html>. It's in! The tree has been reformatted <https://github.com/twisted/twisted/commit/bc96c774be6e307e8e3e4d39780d37b045d0973a>. Some notable changes:

* 3-2-1 blank lines are replaced by PEP 8 style 2-1-1.
* String syntax uses "double quotes".

Run this command to exclude the formatting from git blame <https://github.com/twisted/twisted/blob/trunk/.git-blame-ignore-revs>:

    git config blame.ignoreRevsFile .git-blame-ignore-revs

There are two new Tox testenvs. To check style:

    tox -e black

To adjust the formatting:

    tox -e black-reformat

The formatting is checked by a new GitHub Actions lint built.

There is some follow-up work planned:

* Many PRs have conflicts (more on this below).
* Various wiki pages need updates. I've done a few, but there are probably more.
* The coding standard should be updated <https://twistedmatrix.com/trac/ticket/9957#ticket>.
* The PR template needs an update <https://twistedmatrix.com/trac/ticket/9956#ticket>.
* A few examples need reformatting <https://tm.tl/#9952> (they weren't formatted because they fail to lint).

Inevitably, changes like this cause conflicts. For small PRs it's easiest to merge forward and then run tox -e black-reformat. For larger ones it can help to apply formatting before merge. To do this:

* Run black on the files your branch changes (be sure to use Black 20.8b1, not an older version)
* Commit the result, like `git commit -am "Fade to black"`
* Add that commit to .git-blame-ignore-revs to avoid polluting git blame.
* Merge forward. You can ignore formatting while performing the merge.
* Then run `tox -e black-reformat` to ensure you are in sync. Commit any changes it generates.

A big thanks to Hawkowl for kicking this all off and Craig for quick review turnaround. May we all be mildly displeased with the formatting, yet never have to review it again!

---Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20200913/39f550a0/attachment.htm>


More information about the Twisted-Python mailing list