Skip to content

Commit

Permalink
Merge pull request #5 from gruntwork-io/yori-flake8
Browse files Browse the repository at this point in the history
Add yapf
  • Loading branch information
yorinasub17 committed Jan 23, 2019
2 parents 3684eb6 + 3557e5b commit e6091ad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@
language: script
files: \.go$
exclude: vendor\/.*$

- id: yapf
name: yapf
description: yapf (Yet Another Python Formatter) is a python formatter from Google.
entry: hooks/yapf.sh
language: script
files: \.py$
exclude: __pycache__\/.*$
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ supported hooks are:
* **shellcheck**: Run [`shellcheck`](https://www.shellcheck.net/) to lint files that contain a bash [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix))
* **gofmt**: Automatically run `gofmt` on all Golang code (`*.go` files).
* **golint**: Automatically run `golint` on all Golang code (`*.go` files)
* **yapf**: Automatically run [`yapf`](https://github.com/google/yapf) on all python code (`*.py` files).



Expand Down
16 changes: 16 additions & 0 deletions hooks/yapf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions,
# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
export PATH=$PATH:/usr/local/bin

readonly STYLE="{BASED_ON_STYLE: google, ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT: true, COLUMN_LIMIT: 120, BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF: true, COALESCE_BRACKETS: false, DEDENT_CLOSING_BRACKETS: true, SPLIT_BEFORE_DOT: true, SPLIT_COMPLEX_COMPREHENSION: true}"

for file in "$@"; do
if [[ "$file" =~ \.py$ ]]; then
yapf -ri --style="$STYLE" "$(dirname "$file")"
fi
done

0 comments on commit e6091ad

Please sign in to comment.