GEMDAT icon indicating copy to clipboard operation
GEMDAT copied to clipboard

Consider dropping yapf for ruff formatter

Open stefsmeets opened this issue 2 years ago • 5 comments
trafficstars

Formatting is now built into ruff (https://astral.sh/blog/the-ruff-formatter) as part of 0.1.2.

It's about 100x faster than yapf. Although it is in preview, it's considered production ready.

stefsmeets avatar Oct 25 '23 09:10 stefsmeets

Its very nice for new projects, not so much for existing ones: https://github.com/duqtools/duqtools/issues/669

The diff would be: 31 files changed, 555 insertions(+), 732 deletions(-)

v1kko avatar Nov 14 '23 11:11 v1kko

I still want this 😅

Now that it is has come along a bit more, and I have used it in other repos, I also want to update GEMDAT to use ruff for formatting. I prefer the formatting style of ruff and it now has some configuration options if necessary (most importantly a toggle for single quotes)

It can replace yapf and nbqa (for linting notebooks) in the pre-commit config.

Any thoughts on this @SCiarella ?

stefsmeets avatar May 21 '24 14:05 stefsmeets

I don't have a strong opinion on yapf vs ruff, so I totally trust you on this! Go with the one you like the most!

SCiarella avatar May 21 '24 15:05 SCiarella

I don't like that it would rewrite most of the history. I hoped that at some point there would be feature parity between the two formatters, so no changes to the source code (except changing the formatter) would be necessary

v1kko avatar May 21 '24 15:05 v1kko

I don't think it's so bad. There will not be feature parity between the two. The python community has largely adopted black as the goto formatting style and ruff mimicks that. Yapf is fairly dated at this point and not very actively developed anymore.

It hurts once, but in the long run it will pay off by maintaining history better. One of the issues with yapf is how it formats functions and dicts.

def optimal_n_paths(F_graph: nx.Graph,
                    *,
                    start: Collection,
                    stop: Collection,
                    method: _PATHFINDING_METHODS = 'dijkstra',
                    n_paths: int = 3,
                    min_diff: float = 0.15) -> list[Pathway]:

vs ruff/black:

def optimal_n_paths(
    F_graph: nx.Graph,
    *,
    start: Collection,
    stop: Collection,
    method: _PATHFINDING_METHODS = 'dijkstra',
    n_paths: int = 3,
    min_diff: float = 0.15,
) -> list[Pathway]:

This is means that with yapf, changing the function name could incur 10 lines changed. Imo the 2nd is way nicer in the sense that ruff/black would give cleaner diffs. Most of the changes are of this kind.

stefsmeets avatar May 21 '24 15:05 stefsmeets

Do it then :rocket: :face_with_peeking_eye:

v1kko avatar May 27 '24 09:05 v1kko

#yolo

stefsmeets avatar May 27 '24 10:05 stefsmeets