diff --git a/.evergreen/scripts/setup-uv-python.sh b/.evergreen/scripts/setup-uv-python.sh index 09397803f5..2d91cc6dc6 100755 --- a/.evergreen/scripts/setup-uv-python.sh +++ b/.evergreen/scripts/setup-uv-python.sh @@ -14,17 +14,33 @@ # 3.10 when the task does not set one. set -euo pipefail -HERE=$(dirname ${BASH_SOURCE:-$0}) +HERE=$(dirname "${BASH_SOURCE:-$0}") HERE="$( cd -- "$HERE" > /dev/null 2>&1 && pwd )" +ROOT=$(dirname "$(dirname "$HERE")") + +# A .venv whose interpreter was removed breaks every `uv python find` and +# `uv sync`. It is a build artifact, so remove it and let `uv sync` recreate it. +# A removed base interpreter leaves a dangling symlink on Linux/macOS and a +# launcher that will not start on Windows, so probe by running the interpreter. +for _py in "$ROOT/.venv/bin/python3" "$ROOT/.venv/bin/python" "$ROOT/.venv/Scripts/python.exe"; do + if [ -e "$_py" ] || [ -L "$_py" ]; then + if ! "$_py" -c 'import sys' > /dev/null 2>&1; then + echo "Removing broken .venv (its interpreter will not start); uv sync will recreate it." + rm -rf "$ROOT/.venv" + fi + break + fi +done +unset _py # Source the env files to pick up common variables. -if [ -f $HERE/env.sh ]; then - . $HERE/env.sh +if [ -f "$HERE/env.sh" ]; then + . "$HERE/env.sh" fi # Get variables defined in test-env.sh. -if [ -f $HERE/test-env.sh ]; then - . $HERE/test-env.sh +if [ -f "$HERE/test-env.sh" ]; then + . "$HERE/test-env.sh" fi # Default to a known-good Python so behavior is deterministic when a task does @@ -59,15 +75,30 @@ function _toolchain_dir() { } # Make sure uv can provide the requested Python, downloading it if needed. +# If that fails, fall back to any available Python on local hosts; on CI, fail. function _ensure_python() { - local request="$1" - if uv python find "$request" > /dev/null 2>&1; then + local request="$1" out _fallback + if out=$(uv python find "$request" 2>&1); then return 0 fi - echo "Python \"$request\" was not found on this host; asking uv to install it..." + # Show why find failed: e.g. an interpreter uv cannot run, or none at all. + echo "Python \"$request\" was not found on this host:" >&2 + sed 's/^/ /' <<<"$out" >&2 + echo "Asking uv to install Python \"$request\"..." if uv python install "$request"; then return 0 fi + echo "uv could not install Python \"$request\"; looking for another interpreter..." + # Ignore UV_PYTHON and friends: they would steer the fallback right back to + # the broken interpreter. Local setup only: the Evergreen agent exports + # CI=true for every task command. + if [ "${CI:-}" != "true" ] && \ + _fallback=$(env -u UV_PYTHON -u UV_PYTHON_SEARCH_PATH -u UV_PYTHON_PREFERENCE \ + uv python find ">=3.9" 2>/dev/null); then + echo "Using fallback interpreter: $_fallback" + export UV_PYTHON="$_fallback" + return 0 + fi echo "ERROR: uv could not find or install Python \"$request\"." >&2 return 1 } diff --git a/.github/workflows/test-mod-wsgi.yml b/.github/workflows/test-mod-wsgi.yml index 2ae2310ab6..c10db479cb 100644 --- a/.github/workflows/test-mod-wsgi.yml +++ b/.github/workflows/test-mod-wsgi.yml @@ -159,7 +159,7 @@ jobs: uv pip install -r requirements/mod_wsgi.txt uv run --no-sync python tools/fail_if_no_c.py - id: setup-mongodb - uses: mongodb-labs/drivers-evergreen-tools@49da51cebc0060b4d699d57bdef30ee7e071de44 + uses: mongodb-labs/drivers-evergreen-tools@354a81692bfd2b654a38277b681d248507d17800 # v1.2.0 with: version: ${{ steps.versions.outputs.mongodb-version }} topology: "replica_set" diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index f5b1069e30..8a33ec381c 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -85,7 +85,7 @@ jobs: # The beta Python here relies on the action's prerelease default. python-version: ${{ matrix.python-version }} - id: setup-mongodb - uses: mongodb-labs/drivers-evergreen-tools@ec0b1497b3d351acbfc4fd7579bf3de4de0a1046 # v1.1.0 + uses: mongodb-labs/drivers-evergreen-tools@354a81692bfd2b654a38277b681d248507d17800 # v1.2.0 with: version: "${{ matrix.mongodb-version }}" - name: Run tests @@ -107,7 +107,7 @@ jobs: with: python-version: "3.10" - id: setup-mongodb - uses: mongodb-labs/drivers-evergreen-tools@ec0b1497b3d351acbfc4fd7579bf3de4de0a1046 # v1.1.0 + uses: mongodb-labs/drivers-evergreen-tools@354a81692bfd2b654a38277b681d248507d17800 # v1.2.0 with: version: "8.0" - name: Setup tests @@ -135,7 +135,7 @@ jobs: - name: Install dependencies run: just install - id: setup-mongodb - uses: mongodb-labs/drivers-evergreen-tools@ec0b1497b3d351acbfc4fd7579bf3de4de0a1046 # v1.1.0 + uses: mongodb-labs/drivers-evergreen-tools@354a81692bfd2b654a38277b681d248507d17800 # v1.2.0 with: version: "8.0" - name: Run tests @@ -194,12 +194,12 @@ jobs: - name: Install dependencies run: just install - id: setup-mongodb - uses: mongodb-labs/drivers-evergreen-tools@ec0b1497b3d351acbfc4fd7579bf3de4de0a1046 # v1.1.0 + uses: mongodb-labs/drivers-evergreen-tools@354a81692bfd2b654a38277b681d248507d17800 # v1.2.0 - name: Run tests run: | just integration-tests - id: setup-mongodb-ssl - uses: mongodb-labs/drivers-evergreen-tools@ec0b1497b3d351acbfc4fd7579bf3de4de0a1046 # v1.1.0 + uses: mongodb-labs/drivers-evergreen-tools@354a81692bfd2b654a38277b681d248507d17800 # v1.2.0 with: ssl: true - name: Run tests @@ -254,7 +254,7 @@ jobs: # Test sdist on lowest supported Python python-version: "3.9" - id: setup-mongodb - uses: mongodb-labs/drivers-evergreen-tools@ec0b1497b3d351acbfc4fd7579bf3de4de0a1046 # v1.1.0 + uses: mongodb-labs/drivers-evergreen-tools@354a81692bfd2b654a38277b681d248507d17800 # v1.2.0 - name: Run connect test from sdist shell: bash run: | @@ -278,7 +278,7 @@ jobs: with: python-version: "3.9" - id: setup-mongodb - uses: mongodb-labs/drivers-evergreen-tools@ec0b1497b3d351acbfc4fd7579bf3de4de0a1046 # v1.1.0 + uses: mongodb-labs/drivers-evergreen-tools@354a81692bfd2b654a38277b681d248507d17800 # v1.2.0 with: version: "8.0" - name: Run tests diff --git a/drivers-evergreen-tools b/drivers-evergreen-tools index ec0b1497b3..354a81692b 160000 --- a/drivers-evergreen-tools +++ b/drivers-evergreen-tools @@ -1 +1 @@ -Subproject commit ec0b1497b3d351acbfc4fd7579bf3de4de0a1046 +Subproject commit 354a81692bfd2b654a38277b681d248507d17800