Add nocleanup special arg

This commit is contained in:
crasm 2023-12-21 04:55:28 -05:00
parent e86b8cd93a
commit bdfe4ba85c
2 changed files with 22 additions and 5 deletions

View file

@ -24,4 +24,4 @@ jobs:
with: with:
python-version: "3.11" python-version: "3.11"
- name: Run check-requirements.sh script - name: Run check-requirements.sh script
run: bash check-requirements.sh run: bash check-requirements.sh nocleanup

View file

@ -6,9 +6,18 @@
# WARNING: This is quite IO intensive, because a fresh venv is set up for every # WARNING: This is quite IO intensive, because a fresh venv is set up for every
# python script. # python script.
# #
# usage: ./check-requirements.sh [<working_dir>]
# ./check-requirements.sh 'nocleanup' [<working_dir>]
#
# where:
# - <working_dir> is a directory that can be used as the base for
# setting up the venvs. Defaults to `/tmp`.
# - 'nocleanup' as the first argument will disable automatic cleanup
# of the files created by this script.
#
# requires: # requires:
# * bash >= 3.2.57 # - bash >= 3.2.57
# * shellcheck # - shellcheck
# #
# For each script, it creates a fresh venv, `pip install -r` the # For each script, it creates a fresh venv, `pip install -r` the
# requirements, and finally executes the python script with no arguments to # requirements, and finally executes the python script with no arguments to
@ -54,8 +63,12 @@ abort() {
exit 1 exit 1
} }
trap abort SIGINT SIGTERM SIGQUIT SIGABRT if [[ $1 == nocleanup ]]; then
trap cleanup EXIT shift # discard nocleanup arg
else
trap abort SIGINT SIGTERM SIGQUIT SIGABRT
trap cleanup EXIT
fi
set -eu -o pipefail set -eu -o pipefail
this="$(realpath "$0")" this="$(realpath "$0")"
@ -107,6 +120,10 @@ check_convert_script() {
info "$py: beginning check" info "$py: beginning check"
local reqs="requirements-$pyname.txt" local reqs="requirements-$pyname.txt"
if [[ ! -r "$reqs" ]]; then
fatal "$py missing requirements. Expected: $reqs"
fi
local venv="$workdir/$pyname-venv" local venv="$workdir/$pyname-venv"
python3 -m venv "$venv" python3 -m venv "$venv"