Created by: QiJune
1 use yapf( https://github.com/google/yapf)tool to format python code, and add .style.yapf config file #254 (closed) 2 contributors can add a git hooks to auto-format changed python code just like this
cat .git/hooks/pre-commit
#!/bin/bash
function python_style_check() {
#check python code in a git repo
root=`git rev-parse --show-toplevel`
exit=0
for file in `git diff --staged --name-only|grep '\.py$'`; do
yapf -i --style=$root/.style.yapf $root/$file
if [ $? -ne 0 ]; then
let exit=1
fi
git add $root/$file
done
exit $exit
}
python_style_check