Repository navigation
Expand file tree
/
Copy pathcheck-python
More file actions
executable file
·72 lines (62 loc) · 1.54 KB
/
Copy pathcheck-python
File metadata and controls
executable file
·72 lines (62 loc) · 1.54 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/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
# Delete pyc files from previous builds.
find . \
-name '*.pyc' \
-type f \
-not -path './venv/*' \
-delete
# Run unit tests and calculate code coverage.
# Load module `app.log` to initialize our custom logger.
./venv/bin/coverage run \
--source app/ \
--omit '*_test.py' \
--module \
unittest discover --pattern '*_test.py' \
app.log
./venv/bin/coverage report
# Check for Python init files.
INIT_FILES_OK=true
while read -r directory; do
if [[ ! -f "${directory}/__init__.py" ]]; then
printf "Directory missing __init__.py file: %s\n" "${directory}" >&2
INIT_FILES_OK=false
fi
done < <(
find . \
-type f \
-name '*.py' \
-not -path './venv/*' \
-not -path './.git/*' \
-not -path './node_modules/*' \
-exec dirname {} \; \
| sort --unique
)
"${INIT_FILES_OK}" || exit 1
# Check that source has correct formatting.
./venv/bin/yapf \
--diff \
--recursive \
--exclude 'node_modules/*' \
./
# Run static analysis for Python bugs/cruft.
./venv/bin/ruff check \
./
# Gather names of all Python scripts in the scripts/ folder.
PYTHON_SCRIPTS=()
while read -r line; do
PYTHON_SCRIPTS+=("${line}")
done < <(grep --recursive --files-with-matches '^#!.*python' scripts/)
readonly PYTHON_SCRIPTS
# Check for other style violations.
PYTHONPATH='app/' \
./venv/bin/pylint \
app/ \
"${PYTHON_SCRIPTS[@]}"