-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathcheck-python
executable file
·54 lines (42 loc) · 1.13 KB
/
check-python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#
# Runs tests and static analysis on Python files.
# Exit on first failure.
set -e
# Echo commands before executing them, by default to stderr.
set -x
# Exit on unset variable.
set -u
# Location of app source files.
SOURCE_DIR="app"
ADDITIONAL_PY_SCRIPTS=()
ADDITIONAL_PY_SCRIPTS+=("scripts/render-template")
ADDITIONAL_PY_SCRIPTS+=("scripts/update-service")
# Location of virtualenv.
VIRTUALENV_DIR=venv
./dev-scripts/check-for-init-py-files
# Delete pyc files from previous builds.
find . \
-name "*.pyc" \
-type f \
-not -path "./${VIRTUALENV_DIR}/*" \
-delete
# Run unit tests and calculate code coverage.
# Load module `app.log` to initialize our custom logger.
coverage run \
--source "$SOURCE_DIR" \
--omit "*_test.py" \
--module \
unittest discover --pattern "*_test.py" \
app.log
coverage report
# Check that source has correct formatting.
yapf --diff --recursive ./
# Run static analysis for Python bugs/cruft.
ruff check \
"${SOURCE_DIR}/" \
"${ADDITIONAL_PY_SCRIPTS[@]}"
# Check for other style violations.
PYTHONPATH="${SOURCE_DIR}" \
pylint \
"${SOURCE_DIR}" "${ADDITIONAL_PY_SCRIPTS[@]}"