2022-10-27 13:15:56 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
function error_handler() {
|
|
|
|
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
|
|
|
|
exit "$2"
|
|
|
|
}
|
|
|
|
trap 'error_handler ${LINENO} $?' ERR
|
|
|
|
set -o errtrace -o errexit -o nounset -o pipefail
|
|
|
|
|
|
|
|
python_projects=(
|
|
|
|
flask-bpmn
|
|
|
|
spiffworkflow-backend
|
|
|
|
)
|
|
|
|
|
2022-11-16 16:42:56 +00:00
|
|
|
function get_python_dirs() {
|
|
|
|
(git ls-tree -r HEAD --name-only | grep -E '\.py$' | awk -F '/' '{print $1}' | sort | uniq | grep -v '\.' | grep -Ev '^(bin|migrations)$') || echo ''
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_autoflake() {
|
|
|
|
if ! command -v autoflake8 >/dev/null ; then
|
|
|
|
pip install autoflake8
|
|
|
|
asdf reshim python
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! command -v autopep8 >/dev/null ; then
|
|
|
|
pip install autopep8
|
|
|
|
asdf reshim python
|
|
|
|
fi
|
|
|
|
|
|
|
|
python_dirs=$(get_python_dirs)
|
|
|
|
python_files=$(find $python_dirs -type f -name "*.py" ! -name '.null-ls*' ! -name '_null-ls*')
|
|
|
|
|
|
|
|
autoflake8 --in-place --remove-unused-variables --remove-duplicate-keys --expand-star-imports --exit-zero-even-if-changed $python_files
|
|
|
|
autoflake --in-place --remove-all-unused-imports $python_files
|
|
|
|
autopep8 --in-place $python_files
|
2022-10-27 13:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_pre_commmit() {
|
|
|
|
poetry run pre-commit run --verbose --all-files
|
|
|
|
}
|
|
|
|
|
|
|
|
for python_project in "${python_projects[@]}" ; do
|
|
|
|
pushd "$python_project"
|
2022-11-16 16:42:56 +00:00
|
|
|
run_autoflake || run_autoflake
|
2022-10-27 13:15:56 +00:00
|
|
|
popd
|
|
|
|
done
|
|
|
|
run_pre_commmit || run_pre_commmit
|
|
|
|
|
|
|
|
for python_project in "${python_projects[@]}"; do
|
|
|
|
pushd "$python_project"
|
2022-11-16 16:42:56 +00:00
|
|
|
poetry install
|
|
|
|
poetry run mypy $(get_python_dirs)
|
|
|
|
poetry run coverage run --parallel -m pytest
|
2022-10-27 13:15:56 +00:00
|
|
|
popd
|
|
|
|
done
|