run_style_checks.sh 1.35 KB
Newer Older
1
2
#!/usr/bin/env bash

moto's avatar
moto committed
3
set -eux
4

moto's avatar
moto committed
5
6
7
root_dir="$(git rev-parse --show-toplevel)"
conda_dir="${root_dir}/conda"
env_dir="${root_dir}/env"
moto's avatar
moto committed
8
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
9

moto's avatar
moto committed
10
11
12
13
14
eval "$("${conda_dir}/bin/conda" shell.bash hook)"
conda activate "${env_dir}"

# 1. Install tools
conda install flake8
moto's avatar
moto committed
15
16
17
printf "Installed flake8: "
flake8 --version

moto's avatar
moto committed
18
19
20
clangformat_path="${root_dir}/clang-format"
curl https://oss-clang-format.s3.us-east-2.amazonaws.com/linux64/clang-format-linux64 -o "${clangformat_path}"
chmod +x "${clangformat_path}"
moto's avatar
moto committed
21
22
printf "Installed clang-fortmat"
"${clangformat_path}" --version
moto's avatar
moto committed
23
24

# 2. Run style checks
25
26
# We want to run all the style checks even if one of them fail.

moto's avatar
moto committed
27
28
set +e

29
30
exit_status=0

moto's avatar
moto committed
31
printf "\x1b[34mRunning flake8:\x1b[0m\n"
32
33
34
35
36
37
38
flake8 torchaudio test build_tools/setup_helpers
status=$?
exit_status="$((exit_status+status))"
if [ "${status}" -ne 0 ]; then
    printf "\x1b[31mflake8 failed. Check the format of Python files.\x1b[0m\n"
fi

moto's avatar
moto committed
39
40
41
42
43
printf "\x1b[34mRunning clang-format:\x1b[0m\n"
"${this_dir}"/run-clang-format.py \
  -r torchaudio/csrc \
  --clang-format-executable "${clangformat_path}" \
    && git diff --exit-code
44
45
46
status=$?
exit_status="$((exit_status+status))"
if [ "${status}" -ne 0 ]; then
moto's avatar
moto committed
47
    printf "\x1b[31mC++ files are not formatted. Please use clang-format to format CPP files.\x1b[0m\n"
48
49
fi
exit $exit_status