1#!/bin/bash 2# Usage: tc_pyformat <list of pyformat options> file1.py file2.py ... 3# 4# Most common option is -i, which makes formatting changes in place. 5set -u 6 7PF=pyformat 8PF_OPTIONS="--yapf --force_quote_type=single" 9PF_USER_OPTIONS="" 10 11if [[ -z "$(type -t ${PF})" ]]; then 12 echo "Error: ${PF} not in your path." 13 exit 1 14fi 15 16while [[ "$1" == -* ]]; do 17 PF_USER_OPTIONS+=" $1" 18 shift 19done 20 21FILES=$* 22PF_OPTIONS+=${PF_USER_OPTIONS} 23 24for f in ${FILES}; do 25 if [[ $f != *.py ]]; then 26 echo "Error: File $f is not a python file" 27 exit 2 28 elif [[ -x $f ]]; then 29 ${PF} ${PF_OPTIONS} $f 30 elif [[ -f $f ]]; then 31 ${PF} --remove_shebang ${PF_OPTIONS} $f 32 else 33 echo "Error: File $f does not exist" 34 exit 2 35 fi 36done 37