bchao1 / bullet

🚅 Interactive prompts made simple. Build a prompt like stacking blocks.
https://pypi.org/project/bullet/
MIT License
3.55k stars 113 forks source link

Applied black formatting #55

Closed andrewasheridan closed 3 years ago

andrewasheridan commented 4 years ago

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

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:

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