Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use black to format python sources #528

Merged
merged 4 commits into from
Jan 30, 2024

Conversation

tmadlener
Copy link
Collaborator

@tmadlener tmadlener commented Dec 7, 2023

BEGINRELEASENOTES

  • Use black to format all python source files
  • Add a pre-commit hook for running black in CI

ENDRELEASENOTES

IMPORTANT: Do not squash-merge this because then we cannot add the format only commit to .git-ignore-blame-refs

@tmadlener
Copy link
Collaborator Author

Keep this open until #516 is merged to not have to many conflicts between the two.

@tmadlener tmadlener changed the title [WIP] Use black to format python sources Use black to format python sources Jan 23, 2024
@jmcarcell
Copy link
Member

Sorry for the late comment but now that we are getting at this there is a similar tool called ruff: https://github.com/astral-sh/ruff
ruff was initially a linter but after some time is also a formatter with support for black and others: https://astral.sh/blog/the-ruff-formatter. One of the reasons to use it would be the speed although we don't have repos large enough to benefit from that a lot, probably. Another reason is the fact that it is a tool that can do several things. This is what I use as linter in my editor and tells me issues without having to run other things and can also format, in this case being fast and reacting to changes quickly is important. I added it to the key4hep stack not too long ago with the intention to use it in key4hep one day...

Maybe I'm biased but I hear people using ruff a lot. For comparison, ruff is 1.5 years old and has 22k stars on github, black is almost 6 years old and has 36k (and part of the PSF) so it's a quite popular tool.

@tmadlener
Copy link
Collaborator Author

If we can make ruff format to the same as black in this configuration, we can always switch the linters later, because that would presumably also replace pylint and flake8, IIUC.

@tmadlener
Copy link
Collaborator Author

Merging this now. From a quick test it looks like ruff can be made to reproduce this formatting with black.

@tmadlener
Copy link
Collaborator Author

Failing CI, due to #545

@tmadlener tmadlener merged commit 518dae4 into AIDASoft:master Jan 30, 2024
16 of 18 checks passed
@tmadlener tmadlener deleted the py-format-black branch January 30, 2024 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants