|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -ROOT="$(cd "$(dirname "$0")"/.. && pwd)" |
| 3 | +SCRIPT_DIR="$( cd -- "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| 4 | +ROOT="$( "$SCRIPT_DIR"/get-root.sh )" |
4 | 5 | PREFIX="${ROOT}"/prefix
|
5 | 6 | MIN_CODE_QUALITY=8.0
|
6 | 7 |
|
7 | 8 | get_code_score() {
|
8 |
| - if [ -n "$1" ]; then |
9 |
| - # set minimum quality to user input (int/float) if provided and (5.0 <= input <= 10.0) |
10 |
| - if [[ $1 =~ ^([0-9]+)*([\.][0-9])?$ ]]; then |
11 |
| - if (( $(echo "$1 >= 5.0" | bc -l) )) && (( $(echo "$1 <= 10.0" | bc -l) )); then |
12 |
| - MIN_CODE_QUALITY=$1 |
13 |
| - else |
14 |
| - # In the future, we want code quality to be at minimum 8.0/10.0 |
15 |
| - echo "Code quality score must be between 5.0 and 10.0, inclusive." |
16 |
| - echo "Recommended code quality score is >= 8.0." |
17 |
| - exit 1 |
18 |
| - fi |
19 |
| - else |
20 |
| - echo "Code quality score must be an integer or floating point number." |
21 |
| - exit 1 |
| 9 | + if [ -n "$1" ]; then |
| 10 | + # set minimum quality to user input (int/float) if provided and (5.0 <= input <= 10.0) |
| 11 | + if [[ $1 =~ ^([0-9]+)*([\.][0-9])?$ ]]; then |
| 12 | + if (( $(echo "$1 >= 5.0" | bc -l) )) && (( $(echo "$1 <= 10.0" | bc -l) )); then |
| 13 | + MIN_CODE_QUALITY=$1 |
| 14 | + else |
| 15 | + # In the future, we want code quality to be at minimum 8.0/10.0 |
| 16 | + echo "Code quality score must be between 5.0 and 10.0, inclusive." |
| 17 | + echo "Recommended code quality score is >= 8.0." |
| 18 | + exit 1 |
| 19 | + fi |
| 20 | + else |
| 21 | + echo "Code quality score must be an integer or floating point number." |
| 22 | + exit 1 |
| 23 | + fi |
22 | 24 | fi
|
23 |
| - fi |
24 |
| - echo "Linting Python code with minimum quality of $MIN_CODE_QUALITY/10.0..." |
| 25 | + echo "Linting Python code with minimum quality of $MIN_CODE_QUALITY/10.0..." |
25 | 26 | }
|
26 | 27 |
|
27 | 28 | check_pylint() {
|
28 |
| - if ! command -v pylint &>/dev/null; then |
29 |
| - echo "pylint is not installed." |
30 |
| - echo "Run 'sudo ./scripts/install-build-tools.sh' to install pylint." |
31 |
| - exit 1 |
32 |
| - fi |
| 29 | + if ! command -v pylint &>/dev/null; then |
| 30 | + echo "pylint is not installed." |
| 31 | + echo "Run 'sudo ./scripts/install-build-tools.sh' to install pylint." |
| 32 | + exit 1 |
| 33 | + fi |
33 | 34 | }
|
34 | 35 |
|
35 | 36 | get_code_score $1
|
36 | 37 | if source "${ROOT}/scripts/activate-venv.sh"; then
|
37 |
| - echo "Virtual environment activated." |
| 38 | + echo "Virtual environment activated." |
38 | 39 | else
|
39 |
| - echo "Failed to activate virtual environment." |
40 |
| - exit 1 |
| 40 | + echo "Failed to activate virtual environment." |
| 41 | + exit 1 |
41 | 42 | fi
|
42 | 43 |
|
43 | 44 | check_pylint
|
44 | 45 | if ! pylint scripts src tests tools --rcfile=.pylintrc \
|
45 |
| - --fail-under=$MIN_CODE_QUALITY $(git ls-files '*.py'); then |
| 46 | + --fail-under=$MIN_CODE_QUALITY $(git ls-files '*.py'); then |
46 | 47 | echo "Linting failed, please fix the issues and rerun."
|
47 |
| - exit 1 |
| 48 | + exit 1 |
48 | 49 | else
|
49 |
| - echo "Linting passed." |
| 50 | + echo "Linting passed." |
50 | 51 | fi
|
0 commit comments