From 3959f40c012cdba815a227a61e4c661f19338ba1 Mon Sep 17 00:00:00 2001 From: Kevin Albertson Date: Thu, 15 Oct 2026 16:27:15 -0400 Subject: [PATCH] test-python: fall back to uv-provisioned Python 3.11 when find_pythons finds none PYTHON-6139 (#1242) tightened _probe_pythons to require Python >= 3.11. On distros whose MongoDB toolchain tops out at 3.10 (e.g. rhel-82-arm64) find_pythons now returns nothing, so both 'test-python' and 'test-python-integ' fail at interpreter discovery ("No Python interpreter found!") before the uv fallback in integ-test.sh can run. Fall back to a uv-provisioned Python 3.11 when interpreter discovery yields nothing: in test.sh after ensure_uv, and in integ-test.sh by moving the uv provisioning ahead of the guard (also collapsing the duplicated uv blocks). Restores #1246's intent on top of #1242. --- bindings/python/.evergreen/integ-test.sh | 32 +++++++----------------- bindings/python/.evergreen/test.sh | 8 ++++-- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/bindings/python/.evergreen/integ-test.sh b/bindings/python/.evergreen/integ-test.sh index c666807be..17311e29f 100755 --- a/bindings/python/.evergreen/integ-test.sh +++ b/bindings/python/.evergreen/integ-test.sh @@ -11,19 +11,15 @@ MONGOCRYPT_DIR="$MONGOCRYPT_DIR" CRYPT_SHARED_DIR="$DRIVERS_TOOLS" MONGODB_BINARIES="$DRIVERS_TOOLS/mongodb/bin" -# Use the latest toolchain Python. +# Use the latest toolchain Python, if any qualifies. PYTHON=$(find_pythons | tail -1) -if [ -z "$PYTHON" ]; then - echo "No Python interpreter found!" - exit 1 -fi -# pymongo (unreleased master) requires Python 3.11+. Some distros (e.g. -# rhel82) only provide older interpreters, so provision one with uv. -if ! "$PYTHON" -c 'import sys; sys.exit(sys.version_info < (3, 11))'; then - if ! command -v uv >/dev/null 2>&1; then - "$PYTHON" -m pip install --user uv - fi +# pymongo (unreleased master) requires Python 3.11+ (PYTHON-6138). Some +# distros (e.g. rhel82) only provide older interpreters, or none at all +# now that find_pythons requires 3.11+, so provision one with uv. +if [ -z "$PYTHON" ] || ! "$PYTHON" -c 'import sys; sys.exit(sys.version_info < (3, 11))'; then + . "${DRIVERS_TOOLS}/.evergreen/ensure-uv.sh" + ensure_uv uv python install 3.11 PYTHON=$(uv python find 3.11) echo "Using uv-provisioned Python: $PYTHON" @@ -36,18 +32,8 @@ else fi export PYMONGOCRYPT_LIB -# PyMongo master requires Python 3.11+ (PYTHON-6138), but the newest -# interpreter on some distros is the MongoDB toolchain Python 3.10 (e.g. -# rhel-82-arm64). Provision a modern interpreter with uv in that case. -if "$PYTHON" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 11) else 1)'; then - createvirtualenv $PYTHON .venv -else - . "${DRIVERS_TOOLS}/.evergreen/ensure-uv.sh" - ensure_uv - uv python install 3.13 - uv venv --seed --python 3.13 .venv - . .venv/bin/activate -fi +# $PYTHON is guaranteed to be Python 3.11+ at this point. +createvirtualenv $PYTHON .venv pip install -e . pip install uv pushd $PYMONGO_DIR diff --git a/bindings/python/.evergreen/test.sh b/bindings/python/.evergreen/test.sh index b3953ddf5..601018f28 100755 --- a/bindings/python/.evergreen/test.sh +++ b/bindings/python/.evergreen/test.sh @@ -21,8 +21,12 @@ ensure_uv || exit 1 # Discover the toolchain pythons to test against. PYTHONS=($(find_pythons)) if [ ${#PYTHONS[@]} -eq 0 ]; then - echo "No Python interpreters found to test with!" - exit 1 + # No Python 3.11+ interpreter exists on this distro (e.g. rhel-82-arm64's + # toolchain tops out at 3.10): provision one with uv. ensure_uv has + # already run above. + uv python install 3.11 + PYTHONS=($(uv python find 3.11)) + echo "Provisioned Python 3.11 with uv: ${PYTHONS[*]}" fi echo "Testing with pythons: ${PYTHONS[*]}"