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

RFC: Use black for code formatting #1104

Closed
sloria opened this issue Jan 15, 2019 · 5 comments · Fixed by #1250
Closed

RFC: Use black for code formatting #1104

sloria opened this issue Jan 15, 2019 · 5 comments · Fixed by #1250
Milestone

Comments

@sloria
Copy link
Member

sloria commented Jan 15, 2019

Let's spend less time formatting code and let the computer do it.

I've been using black in other projects and it's worked nicely. Integrates with pre-commit, has plugins for all the popular editors.

I've held off on black to avoid creating conflicts for existing PRs. But we have a relatively low number of PRs right now, so maybe now's a good time?

@lafrech @deckar01

@deckar01
Copy link
Member

We started using it at work on a large legacy code base a few months ago. The only gotcha we ran into is that we had to pin the black version in our dev requirements, because the output can differ between minor versions while it is in beta. Fixing merge conflicts was pretty straight forward. Rebase, keep my changes, run black, continue rebase.

A quick check indicates that the changes will be about half quotes and half line wrapping.

@sloria
Copy link
Member Author

sloria commented Jan 15, 2019

I've been using pre-commit to run black, which requires you to pin the version anyway. Example: https://github.com/marshmallow-code/webargs/blob/1c2f034f03baca3ab582ec881d572bb8290a61f6/.pre-commit-config.yaml#L2-L6 . I don't add black to dev requirements.

@lafrech
Copy link
Member

lafrech commented Jan 15, 2019

No objection to this kind of things.

The only issue have is that I use Debian Stretch at work and at home (I might go for testing at home before it gets stable), and therefore I work on Python 3.5. Because I never needed to use a more recent Python and because I deploy on 3.5.

This might prevent me to run pre-commit (marshmallow-code/webargs#244) unless I use 3.6 to develop using pyenv, which I'd rather avoid.

No big deal. I can fix my mess after CI fails on my PRs.

@sloria
Copy link
Member Author

sloria commented Jan 16, 2019

@lafrech You could run pre-commit in Docker. Here's an image for running it on Python 3.6.

docker pull sloria/pre-commit:py36
# In a repo with a .pre-commit-config.yaml
docker run --rm -v $(pwd):/root sloria/pre-commit:py36

EDIT: Use python 3.6
EDIT 2: Fix link

sloria added a commit that referenced this issue Jan 20, 2019
* Add pyupgrade, black, and blacken-docs pre-commit hooks
* Use black's recommended flake8 config: https://github.com/ambv/black/blob/master/.flake8
* Fix a number of issues found by blacken-docs

close #1104
@madsmtm
Copy link

madsmtm commented Jan 20, 2019

@deckar01, this will (hopefully) change soon, when a full release is made, see psf/black#517

sloria added a commit that referenced this issue Jan 31, 2019
* Add pyupgrade, black, and blacken-docs pre-commit hooks
* Use black's recommended flake8 config: https://github.com/ambv/black/blob/master/.flake8
* Fix a number of issues found by blacken-docs

close #1104
@sloria sloria added this to the 3.0 milestone Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants