Page MenuHomeElementl

style: adopt pre-commit for Python black formatting
Needs RevisionPublic

Authored by rexledesma on Jul 2 2021, 7:38 PM.
Referenced Files
Unknown Object (File)
Tue, May 30, 9:55 AM
Unknown Object (File)
Tue, May 30, 9:00 AM
Unknown Object (File)
Thu, May 18, 12:13 PM
Unknown Object (File)
Thu, May 11, 4:33 PM
Unknown Object (File)
Tue, May 9, 3:34 AM
Unknown Object (File)
Mon, May 8, 9:58 PM
Unknown Object (File)
Mon, May 8, 3:32 PM
Unknown Object (File)
Sun, May 7, 3:06 PM



A contributor recommended that we adopt (pre-commit) for the formatting
steps that we usually test for in buildkite. We'll be migrating to Github
soon anyways, so adopting this toolchain will be great to replace what
arclint usually did for us.

Overall, pretty nice experience. pip install pre-commit and you're off to the

I decided to format all python files rather than whatever we configured in the Makefile
before. Docs are formatted with line-length=78 for ease of reading.

Since this tool installs the hooks on its own, we remove dependencies of black from setup.

We'll use this tool to adopt the other linters we have as well.

Test Plan

buildkite, pre-commit run black --all-files

Diff Detail

R1 dagster
Lint Skipped
No Test Coverage

Event Timeline

Harbormaster returned this revision to the author for changes because remote builds failed.Jul 2 2021, 8:30 PM
Harbormaster failed remote builds in B33112: Diff 40813!

remove black step from grpc compile

use pre-commit in grpc compile step

Harbormaster returned this revision to the author for changes because remote builds failed.Jul 6 2021, 4:45 PM
Harbormaster failed remote builds in B33235: Diff 40971!

I don't personally love git-hooks and find them to often be more of a hinderance than a help:

But if we do want to go in this direction, I think we should continue to make our use of black explicit in our (or at least in our make dev_install) so that developers can continue to run it ad hoc or automatically in their editors.


If black isn't installed, will editor linters/fixers generally work? I'm not sure how the common VSCode ones generally work, but I use ALE and it conditionally runs black based on whether or not it's installed. I rely on pyenv local so it'll automatically activate the appropriate virtualenv when I enter a directory - that way I don't automatically run black when working on projects that don't use black.

Take it with a grain of salt, but it looks like we backed away from pre-commit hooks once before as well:

And later removed them entirely:

Although I suspect the issue that caused us to remove them is no longer a problem.

I faintly remember some weird shit around statefulness of how pre-commit worked when we had it set up but im struggling to remember the details

make black has reference in contributing.mdx that'll need update

Overall, pretty nice experience. pip install pre-commit and you're off to the races.

you need to run pre-commit install too to get the hooks in to git installed

Should maybe post in #core-team or something to solicit feedback from others who may care or have past experience with pre-commit




does pre-commit run black --all-files return a failing exit code if it generates changes? if not may need to go with [1]


when exactly does this fire? on amends too?

I don't personally love pre-commit hooks but if we do this we should think about also adding mypy, isort

Well given that installing the pre-commit hooks is a choice, I think its safe to add the config file that meets our projects standards to ease that process for those that want it.

To make this change more agreeable & incremental - lets add the config file, but preserve the existing source of truth, CI, and dev setup portions. We can change the CI source of truth in the future if momentum for pre-commit is strong.

I don't have strong feelings about the files currently missed getting formatted, your discretion on how to handle those.

This revision now requires changes to proceed.Jul 23 2021, 3:25 PM