pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.91k stars 382 forks source link

black + isort #754

Closed Fizzadar closed 2 years ago

Fizzadar commented 2 years ago

Black recently graduated out of beta and is rapidly become the standard code formatter for Python. Although I personally prefer single quotes, standardization is more important and removes any question over code style/format. Therefore I am proposing to blacken the pyinfra codebase.

Would also like to use isort and ssort.

gchazot commented 2 years ago

Just had a look at ssort and I think it's going the opposite direction of making code more readable / easy to understand.

One should be able to read a code file top-down, going from the most high-level structure and concepts, to the most specific implementation details. Python language allows that to a very wide extent for free.

I guess that's what they refer to when saying it sorts it an "old-fashionned" way, i.e. in reference to Fortran, C or similarly parsed languages, where code is validated depth-first rather than Python's breadth-first (-ish) approach.

ssort (I guess as a brainchild of black) is boldly "opinionated". It's sad that they picked the solution that just makes it easier to be strongly opinionated: I think sorting code top-down automatically is a lot more complicated than the other way around because the programmer needs to think about the order in which they want to present the structure/concepts. But those decisions are at best based on the logical relations between concepts, and often very subjective.

Let's remember that code is for humans to read and that some aspects of it can't be translated in strict formatting rules.

gchazot commented 2 years ago

black :+1: isort :+1:

Fizzadar commented 2 years ago

👍 agreed, too strict vs. human readability, keeping this to just isort/black!