Closed mole99 closed 4 months ago
I'm not very happy with "black". It seems like every single change it's making is a change to some syntax that I prefer to use for clarity. In all cases it produces output which I consider inferior and less readable. Apart from my preference for single quotes and judicious use of tabs where python allows it, it is doing obnoxious things, such as in cace_read.py
lines 26 and following, where I intentionally aligned two related lists, and "black" changed the first one to be all on one line and the second one to be one item per line, seemingly arbitrarily. In spiceunits.py
, I purposefully listed items with the same conversion factor on the same line. Again, "black" destroyed my formatting.
Is there are style option other than "black" that is better aligned with my own preferred style?
Well, the idea behind black is to cede control over formatting so you don't have to think about it and have the same formatting regardless of the project, but I can see that won't cut it ^^
Black allows for limited customization (e.g. --skip-string-normalization
to skip strings), so I'll see what we can do there. Let's talk tomorrow 👍️
I think it's more a matter of "what formatting style do I prefer?". Looking into it a bit, I think what I would like is blue
, which appears to be, more or less, "like black but preferring single quotes (plus 80-character line length)". There's also an option for adding #fmt: off ... #fmt: on
which could be applied around the couple of instances where I was specifically trying to format something in an intentional way.
This quote from the "blue" project sounds very close to my philosophy on coding:
Where the blue maintainers disagree with the stylistic (and unconfigurable) choices made by black, we monkeypatch to change these decisions to our own liking. We intend for these differences to be minimal; even in cases where we’d prefer something different, there’s a lot we can live with for the sake of consistency.
I haven't heard of blue before, but sounds like a good compromise! I'll open a PR tomorrow so we can see how it looks.
It is time.
I added black as a dependency to
requirements_dev.txt
(Python 3.8). The code can be checked usingmake lint
and formatted viamake format
.When you are ready, just merge this PR, afterwards I'll add a job to the CI to check the formatting on every push.