xref: /aosp_15_r20/external/bcc/scripts/py-style-check.sh (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard Worker#!/bin/bash
2*387f9dfdSAndroid Build Coastguard Worker
3*387f9dfdSAndroid Build Coastguard Workerset -euo pipefail
4*387f9dfdSAndroid Build Coastguard Worker
5*387f9dfdSAndroid Build Coastguard Worker# TODO: stop ignoring this. Maybe autopep8 existing stuff?
6*387f9dfdSAndroid Build Coastguard Workerfind tools -type f -name "*.py" | xargs pycodestyle -r --show-source --ignore=E123,E125,E126,E127,E128,E302 || \
7*387f9dfdSAndroid Build Coastguard Worker    echo "pycodestyle run failed, please fix it" >&2
8*387f9dfdSAndroid Build Coastguard Worker
9*387f9dfdSAndroid Build Coastguard WorkerNO_PROPER_SHEBANG="$(find tools examples -type f -executable -name '*.py' | xargs grep -L '#!/usr/bin/python')"
10*387f9dfdSAndroid Build Coastguard Workerif [ -n "$NO_PROPER_SHEBANG" ]; then
11*387f9dfdSAndroid Build Coastguard Worker    echo "bad shebangs found:"
12*387f9dfdSAndroid Build Coastguard Worker    echo "$NO_PROPER_SHEBANG"
13*387f9dfdSAndroid Build Coastguard Worker    echo
14*387f9dfdSAndroid Build Coastguard Worker    echo "either add proper shebang or remove executable bit" >&2
15*387f9dfdSAndroid Build Coastguard Worker
16*387f9dfdSAndroid Build Coastguard Worker    exit 1
17*387f9dfdSAndroid Build Coastguard Workerfi
18