[GRASS-dev] black: Python code formatter (eg PEP8)

Vaclav Petras wenzeslaus at gmail.com
Tue May 21 17:13:23 PDT 2019


On Mon, May 20, 2019 at 8:31 AM Markus Neteler <neteler at osgeo.org> wrote:
>
> Back - Python code formatter (eg. PEP8)
> https://github.com/python/black

I like that, although I don't understand why they didn't decide for 4
spaces for first indent level and 1 tab for the second one ;-) But on a
serious note:

> Would that be useful for us?

Yes, I think we should adopt it. The philosophy of no settings is great. I
write with PEP8 (pycodestyle/pep8), but there is still too many options.
>From the tools Black, YAPF, pep8ify, and autopep8, Black seems the best in
several ways (strict style, close to core Python devs, more predicable and
consistent, better style) as long as one accepts the style without
questions (as if it would be part of the language).

It is worth noting that it will likely introduce many changes into our
code. Some of Black's practices are different from what we are using (e.g.
"single quotes for data, double quotes for text"). Additionally, if I
remember correctly, after we applied autopep8 to wxGUI, several places were
broken, although we were working on PEP8 compliance long time before that.
It should be significantly better this time especially because the main
problem were mixed tabs and spaces in that case. However with `--check
--skip-string-normalization --line-length` and couple of `# fmt: on/off`,
we can use it right away for checks.

We already have settings for pycodestyle/pep8 and Pylint in tools
directory. The reason I have never added that to makefiles was that I
didn't want to introduce it as a dependency. Perhaps there is a way in
makefiles to make it optional. Same goes for Black too. Of course the check
could be only in CI, but for that we really need to apply the style fully
first.

The problem with applying it fully is that it is in beta and they warn that
the style may change (to different subset of PEP8). I think we should test
it first anyway.

I encourage everybody to use it locally for checks of old files and apply
it to new ones. After some time, we can apply it fully.

Best,
Vaclav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20190521/ba362878/attachment.html>


More information about the grass-dev mailing list