Closed gforcada closed 1 year ago
Well, my favourite tool for this is https://github.com/google/yapf, which is much more configurable and IMHO produces better code. Anyway if we decide to go for black I am all in because I am 100% sure that adopting it will be a big benefit.
I second using black.
@ale-rt if yapf is your choice just configure it in a way its doing the same as black.
But my experience with yapf is its much more difficult to use and, most important, it allows too many options leading to discussions which this PLIP intention is to avoid.
If we decide to go black I will switch to black with no problem! My personal evaluation lead to YAPF exactly because it is more configurable, but if the majority picks another tool I will switch to it without any problem. I see much more an advantage to have this PLIP approved with black than having nothing like the current status is. So if everybody loves black, let's go black :)
+1 for black. The lack of configurability (and thus lack of bike-shed-ability) is a feature.
+1 for black. Though, we might want to wait with that until we get rid of Python 2. Since black does not run on Python 2 we always risk that people who work with Python 2 are not able to run the formatter.
@gforcada the @plone/framework-team approved your PLIP in its meeting today. Please go ahead with the implementation.
+1 for black. Though, we might want to wait with that until we get rid of Python 2. Since black does not run on Python 2 we always risk that people who work with Python 2 are not able to run the formatter.
Black itself uses python3, but it will format both 2 and 3.
In the issue linked by Jens just above, he says we can use black --check .
That could replace most of flake8
. Not all of it: there are some plone/zope-specific flake8 plugins that we use.
Yup, there are plenty of things that black does not check(i.e. a bare except:
clause for example) that still needs flake8.
But there are quite a few flake8 plugins that can be disabled completely.
Sure, it does not check all. Btw., now the PLIP is approved, what is next?
Me finding some time to work on the deliverables? :sweat_smile:
But, please, pretty please, forget about this PLIP for now, we have pretty much more specific and urgent topics to work on (i.e. get 5.2 out :wink: )
This will have implications with bobtemplates.plone, used to create packages in the Plone world. Should we try to enforce black there as well? For the sake of an example, if I run black
in a newly created package from bobtemplates.plone, without --skip-string-normalization, it would create a big diff:
@MrTango FYI
This has been applied since the plone/meta
project being put in motion this year 2023 🎉
PLIP (Plone Improvement Proposal)
Responsible Persons
Proposer: Gil Forcada Codinachs (gforcada)
Seconder: up for grabbing
Abstract
Motivation
tl;dr; efficiency, i.e. once and for all, end up all the formatting discussions and make contributing to Plone even easier.
Plone is transitioning into Python 3 and has decades of history on its shoulders. Linters and styleguides have helped keep some code consistency, but just like tendencies, they keep changing over time, and most of the times are left half implemented.
As everything, it starts small and gets more and more complex over time:
Autoformatters are already mature enough to deal with large code bases. This means, that for the first time ever, we are in a position where we can finally have a single source of truth on how to format our code base.
As usual though, that gets us only up to a certain degree, no functions, methods, classes etc. will get renamed.
Black is a python code autoformatter that has to main promises:
Notice that having the code formatted automatically (by black or whichever other tool) does not necessarily mean that we do not need any code analysis tool anymore. A bare exception handling is a really bad thing that one should never do, code analysis tools will warn about it, auto formatters will never.
Fortunately for us, it is not too much effort to make them cooperate with each other :+1:
Assumptions
Proposal & Implementation
Deliverables
Risks
We keep the current half mess of styleguides and formattings, as well as linting hints on and off here and there.
We hinder contributions from newcomers by making them uneasy on how they are expected to format their contribution.
Participants