-
Notifications
You must be signed in to change notification settings - Fork 16
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
Running the black code formatter on the codebase #241
base: development
Are you sure you want to change the base?
Conversation
To add: I do want to put in some pre-push git hook to prevent the code from being de-blackified, but I've also found that it's good to do this a bit after blackifying the codebase, so as to not stir things up too much. Once (if?) we do add such a hook (for example via the pre-commit.com mechanism), there might be some files that will have gone out-of-black format, but it's no big deal to blackify them along with adding the hook. |
419d539
to
f5b8551
Compare
Makefile
Outdated
@@ -82,6 +82,11 @@ update-dependencies: | |||
@make freeze-dependencies | |||
|
|||
|
|||
.PHONY: format | |||
format: setup | |||
@. .venv/bin/activate && 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.
Decided to call the target format
, and not black
, as there might be other formatting tools we might want to add (JS/HTML/CSS..?).
@@ -62,19 +66,34 @@ def get_answer(question, proper_answers=('yes','no')): | |||
return answer | |||
|
|||
|
|||
print "*" * TERMINAL_WIDTH |
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.
I converted these python 2 style print
statements into calls to the print()
function in python 3.
line-length = 79 | ||
# NOTE: PEP8 does recommend double-quotes, but to start with we'll support | ||
# single quotes as to minimize the patch/noise produced by introducing black | ||
skip-string-normalization = true |
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.
I decided to go for 79 chars, as it's by the PEP8 standard.
Also, I figured - for now - to allow using single quote strings. We can change it later if we want to.
@@ -28,6 +28,9 @@ requests==2.22.0 | |||
signxml==2.7.2 | |||
suds-jurko==0.6 | |||
|
|||
# Development | |||
black==22.3.0 | |||
|
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.
Adding black.
cachetools==4.0.0 | ||
certifi==2019.11.28 | ||
cffi==1.13.2 | ||
chardet==3.0.4 | ||
click==8.1.3 |
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.
This, and the other dependencies below came in with the black package.
EDIT: This is really a tiny PR - should take about 5 mins to review I promise :)
Right.. This is a big one! But also, a small one.
It's big because it changes a lot of files, and it may introduce coding styles foreign to some developers.
It's small because functionally, the code is exactly the same. Black is written by one of the core contributors to python, and he did a clever thing with black: It compares the AST (abstract syntax tree) of the code before and after, and makes sure it's the same. This pretty much makes sure that the code functions the same. Hence, this patch is actually small.
**The only files that need any reviewing here are:
format
targetprint()
calls) and ran black on it, as all other.py
files.pyproject.toml
is nice. It can be used to configure other aspects of our python projects later on. Read more about it here: https://peps.python.org/pep-0621/ and here: https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/.All of the other files are
.py
files changed by black, and thus need no reviewing, unless if the reader is curious howblack
is formatting the files.