You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org

Wikimedia Cloud Services team/Python coding: Difference between revisions

From Wikitech-static
Jump to navigation Jump to search
imported>David Caro
(Update to reflect current line length settings)
imported>BryanDavis
(Undo revision 2008198 by David Caro (talk) Change lacks consensus)
 
Line 6: Line 6:
While PEP8 provides most of this, and the flake8 linter enforces it on CI, flake8 is pretty liberal, and formatting is hardly consistent.  Using the auto-formatter [https://black.readthedocs.io/en/stable/ black] provides a more narrow interpretation of PEP8, can be integrated into all of our text editors, and makes the reasoning of the code stand out over the format.  Black is configurable if we have disagreements with its defaults.
While PEP8 provides most of this, and the flake8 linter enforces it on CI, flake8 is pretty liberal, and formatting is hardly consistent.  Using the auto-formatter [https://black.readthedocs.io/en/stable/ black] provides a more narrow interpretation of PEP8, can be integrated into all of our text editors, and makes the reasoning of the code stand out over the format.  Black is configurable if we have disagreements with its defaults.


We have, as a rule, set black to a line length of 120 to comply with PEP8 and make things easier in gerrit reviews. Otherwise, we prefer black's conventions to flake8s when there is a conflict.
We have, as a rule, set black to a line length of 80 to comply with PEP8 and make things easier in gerrit reviews. Otherwise, we prefer black's conventions to flake8s when there is a conflict.


== Configuration Data ==
== Configuration Data ==
Line 13: Line 13:
<syntaxhighlight lang=ini>
<syntaxhighlight lang=ini>
[tool.black]
[tool.black]
line-length = 120
line-length = 80
</syntaxhighlight>
</syntaxhighlight>
If that repository is set to check for 79 char lines because of some old flake8 setting, like in tools-webservice, we use that for now.
If that repository is set to check for 79 char lines because of some old flake8 setting, like in tools-webservice, we use that for now.


[[Category:Cloud Services]]
[[Category:Cloud Services]]

Latest revision as of 14:56, 3 October 2022

We write a lot of python, so it seems like that would be the place to introduce some common practices for the WMCS team. In the interest of clean, readable code across the team, it is common practice by development groups to share formatting and other development practices in order to facilitate collaboration. A common example is shared linter settings, like what is used in operations/puppet for puppet-lint.

This is intended as Team Practices, not an overall standard. The movement has mw:Manual:Coding conventions/Python which provides some additional guidance.

Formatting

While PEP8 provides most of this, and the flake8 linter enforces it on CI, flake8 is pretty liberal, and formatting is hardly consistent. Using the auto-formatter black provides a more narrow interpretation of PEP8, can be integrated into all of our text editors, and makes the reasoning of the code stand out over the format. Black is configurable if we have disagreements with its defaults.

We have, as a rule, set black to a line length of 80 to comply with PEP8 and make things easier in gerrit reviews. Otherwise, we prefer black's conventions to flake8s when there is a conflict.

Configuration Data

In a repository where a pyproject.toml is appropriate or doesn't clash with other settings, we can use the settings:

[tool.black]
line-length = 80

If that repository is set to check for 79 char lines because of some old flake8 setting, like in tools-webservice, we use that for now.