Integration as a http://pre-commit.com/ hook
See original GitHub issueThis isn’t really such a bug report as more of an inquisition about how to approach this.
As requested here: https://github.com/pre-commit/pre-commit-hooks/issues/50 we’ve had some interest in integrating yapf with our pre-commit framework.
There’s two basic approaches to doing this so I’d like to get your opinions on this (I’d like to contribute to making either of them happen):
- Provide the proper metadata in google/yapf for running hooks (basically involves checking in a file similar to this: https://github.com/pre-commit/pre-commit-hooks/blob/master/hooks.yaml (except of course it’d just list yapf)).
- Provide library mechanisms to fix files and we’d write a wrapper around yapf in one of our repositories.
Option 1 is ideal for us as we don’t have to deal with dependencies, breaking apis, etc. especially when the project is in an early stage and potentially volatile (and I don’t think yapf is on pypi yet?)
Either way, the general interface for a pre-commit hook to work with our framework is as follows:
- Installable in an isolated environment
- Exposes an executable which:
- Takes a list of filenames to check / fix (in the case of yapf, either)
- Returns 0 when everything is A-OK or no changes are made, and nonzero otherwise
I’m not sure how much of that already happens but I’d be willing to pitch in to make it work (and test it to prevent regressions, etc.).
Given those assumptions it’d be as simple as checking in a file named hooks.yaml
which has contents probably similar to this:
- id: yapf
name: yapf
description: "Runs yapf 'Yet Another Python Formatter' over python source"
entry: yapf
language: python
files: \.py$
args: [-i]
Thanks in advance,
Anthony
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (9 by maintainers)
My thought is that like most linters you would return 0 when the code is good and nonzero when the code is wrong (needs reformatting, etc.). Which would mean when running with
--diff
and there’s any diff you’d return nonzero. When running with--in-place
it would return nonzero when a change is made.Does this sound reasonable?
On Wed, Apr 1, 2015 at 11:17 AM jab notifications@github.com wrote:
Adding new files to the yapf repository for this purpose is not going to be