aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorLuis Lozano <llozano@chromium.org>2015-12-29 17:02:12 -0800
committerchrome-bot <chrome-bot@chromium.org>2015-12-30 23:12:01 +0000
commit1bd8cd1bb4d7697ce8591c90125dab962159ec4c (patch)
treed772811dc34ffb0fd882e5a9ec0a3459578aae6f /bin
parent655dfa3bd83f6abbc7fe7cc0fa14ad38f379dcb6 (diff)
downloadtoolchain-utils-1bd8cd1bb4d7697ce8591c90125dab962159ec4c.tar.gz
Add a script to invoke pyformat.
Use this script to invoke pyformat according to our rules. BUG=None TEST=white box testing Change-Id: Ia9563a60c8d47850dc52bfed6aa6ed88e30ffa86 Reviewed-on: https://chrome-internal-review.googlesource.com/243112 Commit-Ready: Luis Lozano <llozano@chromium.org> Tested-by: Luis Lozano <llozano@chromium.org> Reviewed-by: Rahul Chaudhry <rahulchaudhry@google.com>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tc_pyformat36
1 files changed, 36 insertions, 0 deletions
diff --git a/bin/tc_pyformat b/bin/tc_pyformat
new file mode 100755
index 00000000..63a6e947
--- /dev/null
+++ b/bin/tc_pyformat
@@ -0,0 +1,36 @@
+#!/bin/bash
+# Usage: tc_pyformat <list of pyformat options> file1.py file2.py ...
+#
+# Most common option is -i, which makes formatting changes in place.
+set -u
+
+PF=pyformat
+PF_OPTIONS="--remove_trailing_comma --yapf --force_quote_type=single"
+PF_USER_OPTIONS=""
+
+if [[ -z "$(type -t ${PF})" ]]; then
+ echo "Error: ${PF} not in your path."
+ exit 1
+fi
+
+while [[ "$1" == -* ]]; do
+ PF_USER_OPTIONS+=" $1"
+ shift
+done
+
+FILES=$*
+PF_OPTIONS+=${PF_USER_OPTIONS}
+
+for f in ${FILES}; do
+ if [[ $f != *.py ]]; then
+ echo "Error: File $f is not a python file"
+ exit 2
+ elif [[ -x $f ]]; then
+ ${PF} ${PF_OPTIONS} $f
+ elif [[ -f $f ]]; then
+ ${PF} --remove_shebang ${PF_OPTIONS} $f
+ else
+ echo "Error: File $f does not exist"
+ exit 2
+ fi
+done