Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dev-scripts/check-all
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ set -x
set -u

./dev-scripts/check-bash
./dev-scripts/check-for-init-files
./dev-scripts/check-javascript
./dev-scripts/check-privilege-guard
./dev-scripts/check-python
Expand Down
27 changes: 0 additions & 27 deletions dev-scripts/check-for-init-py-files

This file was deleted.

54 changes: 33 additions & 21 deletions dev-scripts/check-python
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,56 @@ 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" \
-name '*.pyc' \
-type f \
-not -path "./${VIRTUALENV_DIR}/*" \
-not -path './venv/*' \
-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" \
--source app/ \
--omit '*_test.py' \
--module \
unittest discover --pattern "*_test.py" \
unittest discover --pattern '*_test.py' \
app.log
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/*' \
-exec dirname {} \; \
| sort --unique
)
"${INIT_FILES_OK}" || exit 1

# Check that source has correct formatting.
yapf --diff --recursive ./

# Gather names of all Python scripts in the scripts/ folder.
PYTHON_SCRIPTS=()
mapfile -t PYTHON_SCRIPTS < <(grep -rl '^#!.*python' scripts/)
readonly PYTHON_SCRIPTS

# Run static analysis for Python bugs/cruft.
ruff check \
"${SOURCE_DIR}/" \
"${ADDITIONAL_PY_SCRIPTS[@]}"
app/ \
"${PYTHON_SCRIPTS[@]}"

# Check for other style violations.
PYTHONPATH="${SOURCE_DIR}" \
PYTHONPATH='app/' \
pylint \
"${SOURCE_DIR}" "${ADDITIONAL_PY_SCRIPTS[@]}"
app/ \
"${PYTHON_SCRIPTS[@]}"