-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feat/black formatter: add black to pre-commit config and github workflow #30
Conversation
A lot of files were changed due to adding black I hope it’s not too unreadable |
Just to understand correctly, if you have black non-conforming code and commit, black automatically formats your files and commits the formatted code instead of your original one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice tho, thank you!
.github/workflows/tests.yml
Outdated
@@ -20,5 +20,9 @@ jobs: | |||
run: | | |||
pip install poetry | |||
poetry install | |||
- name: Format with Black | |||
run: | | |||
pip install black |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also install black using poetry and just run poetry run black
then we dont need the pip install
(same for pytest and pylint when/if we implement them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes great catch! lemme check and add it
Yes @kbiniek it will format the code each time before commiting. One might get an error when commiting when the code is not formated properly — you might need to commit again (see attached screenshots on VSCode). You pretty much never have to run black yourself, it’s all done with the pre-commit config automatically (after runnig ![]() ![]() ![]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice, thank you!! I only have one comment but thats personal taste i think so ignore and merge away if you disagree :)
@@ -20,5 +20,9 @@ jobs: | |||
run: | | |||
pip install poetry | |||
poetry install | |||
- name: Format with Black | |||
run: | | |||
poetry add black |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
poetry install
installs everything we have in the pyproject.toml
right? Do we want to maybe include black in the pyproject.toml
directly then? Then we dont have to add it every time and can also run it inbetween commits just to format the code from time to time manually which i like to do but maybe thats just me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that sounds good as well! From the experiences I’ve heard from: When developing a package, its dependencies should only be packages required for the src code to work, black would be an example for a “development” pckg. Butin this case it honestly shouldn’t matter; so we can add it and leave the poetry add black as a “general test workflow”, does that sound good?
Or other thing to consider form my side, which is why i would perhaps consider keeping it that way: black is “enforced” any time we commit anyways, meaning that the code that is commited already has to be black-format conform. Would it therefore be ok for you to leave it like this, and have the code be formatted each time when running git commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then also the line length 79. is already custom and doens’t need to be specified when running the cmd black
Description:
This PR introduces the Black code formatter into our development process. Black is a highly opinionated, deterministic formatter that allows us to focus more on writing code rather than formatting it.
Changes include:
Added Black to our pre-commit hooks in .pre-commit-config.yaml. This will ensure that code is automatically formatted when committing changes.
Updated our GitHub workflow in .github/workflows/tests.yml to include a step for checking code formatting with Black. This will help us maintain a consistent code style across all contributions.
By integrating Black into our development process, we can ensure a consistent, PEP 8 compliant code style across the project, and allow contributors to focus more on the logic of their code rather than its formatting. Kindly lmk what you think