Pants: Add Black support to pants and dogfood it

Created on 25 Sep 2019  路  4Comments  路  Source: pantsbuild/pants

https://github.com/psf/black

Black is an opinionated python formatter.

See reasoning for preferring Black over alternatives in the project's slack channel: https://pantsbuild.slack.com/archives/C046T6T9U/p1569413859055800

To sum things up, I would like to

  • add a rule to pants so it can format python code with Black
  • format all our python code with Black
  • add Black formatting as a necessary step in our pre_commit hook to avoid regressions

This would solve a workflow pain issue with manually formatting python code.
It would also help us have a wildly more consistent formatting style in the python code, which should help with onboarding new programmers and reduce friction during code review.

Black allows freedom on the maximum line length. If no-one strongly opposes it, I would pick 100 as it's a nice round number and it seems to be consistent with our previous de-facto standard.

Most helpful comment

If we do that (I am all for it...)
We should also leverage this git feature so that the git history doesn鈥檛 get messed up.

I heard of it via Twitter: https://twitter.com/llanga/status/1163767833706323970?s=21

All 4 comments

If we do that (I am all for it...)
We should also leverage this git feature so that the git history doesn鈥檛 get messed up.

I heard of it via Twitter: https://twitter.com/llanga/status/1163767833706323970?s=21

If we do that (I am all for it...)
We should also leverage this git feature so that the git history doesn鈥檛 get messed up.

I heard of it via Twitter: https://twitter.com/llanga/status/1163767833706323970?s=21

Thank you! Thank you! Thank you! Thank you! 馃槃 馃殌 馃帀

Outstanding tasks needed here:

  • Get the pre_commit hook merged (https://github.com/pantsbuild/pants/pull/8403)
  • Get the git blame fix (https://github.com/pantsbuild/pants/pull/8404) merged (see https://github.com/pantsbuild/pants/issues/8334#issuecomment-535242467)
  • Raise PR for reformatting the doc-comments, as discussed here: https://github.com/pantsbuild/pants/pull/8391#issuecomment-538416738

Pants has been using Black since February 馃帀

Was this page helpful?
0 / 5 - 0 ratings