hack: repair unusable Python venvs instead of trusting the directory (#1316)

Guarding on `[ ! -d "$VENV_DIR" ]` treats an interrupted create (no
bin/activate) and an interpreter upgrade (dangling bin/python3) as a
good venv, so the script dies in `source venv/bin/activate` and the only
fix is knowing to delete the directory. Probe that the venv runs, and
rebuild with --clear to relink the interpreter.

Also install requirements unconditionally, which is cheap. The license
verifier skipped the install whenever the venv already existed, so it
passed without ever seeing a newly added dependency.

Fixes failure encountered by @ahmedtd. Not filing an issue because this
is pretty trivial.

AI-assisted.
This commit is contained in:
Benjamin Elder
2026-08-31 09:52:29 -07:00
committed by GitHub
parent 07485f079a
commit 8613dd9f7b
4 changed files with 75 additions and 36 deletions
+4 -13
View File
@@ -34,10 +34,9 @@ OUT_DIR="benchmarking/locust/common"
# exporters and google-cloud-storage for nothing.
CODEGEN_DIR="benchmarking/locust/codegen"
VENV_DIR="${CODEGEN_DIR}/venv"
if [ ! -d "$VENV_DIR" ]; then
echo "Creating virtual environment in $VENV_DIR..."
python3 -m venv "$VENV_DIR"
fi
source hack/util/venv.sh
ensure_venv "${VENV_DIR}"
venv_sync_requirements "${VENV_DIR}" "${CODEGEN_DIR}/requirements.txt"
# generate_proto compiles a single .proto file into ${OUT_DIR}, prepends the
# project's license header, and rewrites the generated grpc file's intra-package
@@ -81,18 +80,10 @@ generate_proto() {
}
# Run inside a subshell so `activate` doesn't leak VIRTUAL_ENV/PATH back to
# the caller; the subshell inherits errexit/nounset/pipefail. pip skips
# already-installed packages, so the install is cheap on re-runs.
# the caller; the subshell inherits errexit/nounset/pipefail.
(
echo "Activating virtual environment..."
source "$VENV_DIR/bin/activate"
echo "Installing dependencies from ${CODEGEN_DIR}/requirements.txt..."
pip install --upgrade pip
# The requirement is pinned, so an existing venv already holding that exact
# version is left alone and a venv holding any other version is corrected.
# (An unpinned requirement would instead be satisfied by whatever is already
# installed, which is how the generated files came to drift.)
pip install -r "${CODEGEN_DIR}/requirements.txt"
generate_proto "pkg/proto/ateapipb" "ateapi"
generate_proto "internal/proto/glutton" "glutton"