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

Format code with Black #3733

Merged
merged 7 commits into from
Jun 11, 2019
Merged

Format code with Black #3733

merged 7 commits into from
Jun 11, 2019

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Mar 21, 2019

I'd like to suggest formatting the code with Black:

By using Black, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading. Formatting becomes transparent after a while and you can focus on the content instead.

https://black.readthedocs.io/en/stable/the_black_code_style.html

Black intentionally doesn't provides many options, and I've not used them here. The idea is you just run black and it takes care of everything for you.

I added #fmt:off/fmt:on to retain formatting only where the shape of a list is important, for matrices.

Only the src directory has been done here for demonstration, let me know what you think.

@jdufresne
Copy link
Contributor

I like it 👍

I've seen more and more Python projects adopt black such that it now seems very natural style to me. I think it makes the process easier for new contributors as they won't need to stress or think about the project's coding style. Instead just let the tool handle it.

As a mere infrequent outside contributor, I'm for it.

@radarhere
Copy link
Member

Provided it is just run automatically over new code, I could see this as being a time saver. On the other hand, will new contributors be confused about why their code has rearranged itself?

Note that you'd also want to add this to requirements.txt

@hugovk
Copy link
Member Author

hugovk commented Mar 26, 2019

Provided it is just run automatically over new code, I could see this as being a time saver. On the other hand, will new contributors be confused about why their code has rearranged itself?

You do need to run the command, it's not in a pre-commit hook or anything (but if they wished they could create one, or add it to their editor on save). But it's just a pip install black && black <dir>. It will fix lots of potential flake8 errors too.

On the CI, black --check --diff will show any fixes it would have made in case someone wants to make the changes manually and without the tool.

Note that you'd also want to add this to requirements.txt

Added.

@hugovk hugovk force-pushed the run-black branch 7 times, most recently from 7b0ce05 to 6c544cc Compare April 2, 2019 07:16
@hugovk

This comment has been minimized.

@radarhere

This comment has been minimized.

@hugovk

This comment has been minimized.

@hugovk
Copy link
Member Author

hugovk commented Jun 11, 2019

If no other comments, let's merge this and I'll make a new PR for the other directories.

@radarhere
Copy link
Member

Consider merging in #3898 first, before the changes from this PR make a simple revert unviable.

@hugovk
Copy link
Member Author

hugovk commented Jun 11, 2019

Yep, good idea.

@hugovk hugovk merged commit a986fed into python-pillow:master Jun 11, 2019
@hugovk hugovk deleted the run-black branch June 11, 2019 13:24
@hugovk hugovk mentioned this pull request Jun 18, 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
Development

Successfully merging this pull request may close these issues.

3 participants