OpenOversight icon indicating copy to clipboard operation
OpenOversight copied to clipboard

Using python auto-formatter

Open abandoned-prototype opened this issue 4 years ago • 2 comments

We currently enforce the code style in our code-base using flake8. One downside of that tool is that flake8 points out issues, but doesn't really help you to solve it. I found this particularly annoying with errors like continuation line under-indented for visual indent after breaking up a function call that is too long into multiple lines.

That is why I propose that we select an auto-formatter that we can use from now on. I found this blog post that compares a few: https://www.kevinpeters.net/auto-formatters-for-python. Generally it seems to me that at the current time an auto-formatter called black is most widely used: https://black.readthedocs.io/en/latest/index.html. The strengths of it are that it comes with pretty good default configurations and basically makes code-styling decisions for us, ideally leading to a consistent style throughout the code base. Another advantage of black is that it uses the existing .flake8 file, so any file formatted with black should automatically be passing flake8.

Hoping to get some feedback from people that have experience with either black or any other auto-formatter. I definitely think adding an auto-formatter is valuable to our project, but I am not insisting on a particular one.

abandoned-prototype avatar Jun 28 '20 05:06 abandoned-prototype

yeah I much prefer the autoformatting tools like Golang and Rust have. I use black in most of my other Python projects, I like it a lot, so :+1: from me to adding it to the linters (might be a good time to add a make lint target for devs) and running black --check in CI (exits 1 if files will be reformatted)

redshiftzero avatar Aug 07 '20 20:08 redshiftzero

I personally feel like black is too intense about some things, but consistency is always good and the python community seems to throw a lot of weight behind black. I use pycharm and know there's both black (and flake8) autoformatting options so :+1: from me

fritzdavenport avatar Aug 09 '20 02:08 fritzdavenport

Has been added via https://github.com/lucyparsons/OpenOversight/commit/7bd564b4641408cc7e96ed26cb6315c230e9e7eb

abandoned-prototype avatar Apr 11 '23 04:04 abandoned-prototype