Implements code formatting through the use of the Python code formatter black
Motivation
Reading and working on code that uses a standard formatting is easier.
This PR should satisfy Issue #17
Implementation
Each python file was formatted using the command black -l 120 <filename> and committed
Zero logic was altered, only formatting
Why use black?
black follows a strict subset of PEP8 and it is easy to use.
What really did black do here?
The biggest changes:
Single-quotes ' become double-quotes "
Statements that could be written in less than 120 characters, which used to be multi-line, are now single line
Files that did not end in a blank line now do
Spacing was standardized
How do we use and install black?
to install:
pip install black
to use:
black -l 120 <filename>
What is -l 120?
By passing in the argument -l 120 to black we are telling it to use a 120 length line limit. The default for black is 88 characters, I have found 120 to be more readable.
Is there a way to apply black automatically before a commit?
Yes! We can use a pre-commit hook. There are many ways to set a formatter like black as part of a pre-commit hook. I did not want to include that in this PR because I felt that it was outside the scope of the PR.
I like to use pre-commit for pre-commit hooks. The instructions at their site are adequate, but I would be happy to set them up for this great project.
You could also manually create pre-commit hooks, or add black to your favorite IDE. Black integrates nicely to PyCharm, Sublime, and VSCode.
Note: I have no affiliation with black or pre-commit or anything else. Like bullet, I think they are great projects.
DCO 1.1 Signed-off-by: Andrew A Sheridan sheridan@berkeley.edu
Bullet Pull Request
Summary
Implements code formatting through the use of the Python code formatter black
Motivation
Reading and working on code that uses a standard formatting is easier.
This PR should satisfy Issue #17
Implementation
black -l 120 <filename>
and committedWhy use
black
?black
follows a strict subset of PEP8 and it is easy to use.What really did
black
do here?The biggest changes:
'
become double-quotes"
How do we use and install
black
?to install:
pip install black
to use:
black -l 120 <filename>
What is
-l 120
?By passing in the argument
-l 120
to black we are telling it to use a 120 length line limit. The default for black is 88 characters, I have found 120 to be more readable.Is there a way to apply
black
automatically before a commit?Yes! We can use a pre-commit hook. There are many ways to set a formatter like black as part of a pre-commit hook. I did not want to include that in this PR because I felt that it was outside the scope of the PR.
I like to use
pre-commit
for pre-commit hooks. The instructions at their site are adequate, but I would be happy to set them up for this great project.You could also manually create pre-commit hooks, or add black to your favorite IDE. Black integrates nicely to PyCharm, Sublime, and VSCode.
Note: I have no affiliation with
black
orpre-commit
or anything else. Likebullet
, I think they are great projects.DCO 1.1 Signed-off-by: Andrew A Sheridan sheridan@berkeley.edu