Repository navigation
PYTHON-6005 & DRIVERS-3564 Fix ensure_uv Python selection and active-venv install - #842
Conversation
ensure_uv now prefers the MongoDB toolchain python3 over the system one, so RHEL 8 hosts whose system python3 is 3.6 (too old for uv) use the toolchain and can install uv. It also installs uv into an active venv rather than failing on pip's refusal to take --user inside one. Add a per-PR regression test for the missing install shapes, and a tests-rhel82-arm64 variant with clear_persisted_uv that proves the toolchain is chosen when the system python3 is too old.
Preferring the MongoDB toolchain over the system python3 broke the active-venv case (the Node OIDC tests): on a toolchain host ensure_uv picked the toolchain interpreter, so uv was installed --user instead of into the venv. Prefer the active venv's interpreter when VIRTUAL_ENV is set, keeping the toolchain as the fallback for the RHEL 8 (3.6 system python) case.
ensure_uv now installs uv into an active venv, but the sibling test-remote-kms-provisioning.sh test_inside_active_venv still asserted uv came from the fallback venv, so the PR-tagged docker test would fail. Drop that obsolete check; the new test-ensure-uv.sh covers the active-venv path. Also recognize a Windows active venv (Scripts/python.exe) so the in-venv branch is not dead code there.
There was a problem hiding this comment.
🟡 Changes recommended
The new Windows-specific active-venv behavior is skipped by its regression test.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Updates ensure_uv to select compatible Python installations and support active virtual environments.
Changes:
- Prefer active-venv or MongoDB toolchain Python.
- Install
uvdirectly into active virtual environments. - Add regression tests and RHEL ARM64 CI coverage.
File summaries
| File | Description |
|---|---|
.evergreen/ensure-uv.sh |
Revises Python selection and uv installation. |
.evergreen/tests/test-ensure-uv.sh |
Adds installation regression tests. |
.evergreen/tests/test-remote-kms-provisioning.sh |
Removes obsolete fallback-venv assertion. |
.evergreen/config.yml |
Adds test task and RHEL ARM64 variant. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The test skipped everything but Linux/macOS, so the Windows active-venv path added in ensure-uv.sh ($VIRTUAL_ENV/Scripts/python.exe) was untested while test-ensure-uv still runs on the windows tests-all matrix. Detect Cygwin/Git-Bash and use the venv's Scripts dir and uv.exe accordingly.
There was a problem hiding this comment.
🟡 Changes recommended
The regression test can falsely pass on Windows and fail rather than skip when venv creation is unavailable.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
The test’s PATH filtering can hide Python alongside uv, causing false failures.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
…on it The local rhel8 and ubuntu22.04 images call ensure_uv (via run-mongodb.sh -> orchestration/setup.sh -> install-cli.sh), which prefers pip but silently falls back to a venv. Neither image installed pip, so the pip path was never exercised in the docker tests and a missing pip was masked. Install pip in both images (python3.11-pip on rhel8, ensurepip on ubuntu, which ships no python3.11-pip), and have the docker test entrypoint fail on 'python3 -m pip --version' so a missing install goes red instead of being hidden by the venv fallback. Drop the now-outdated comment claiming the images have venv but no pip.
- test-ensure-uv.sh: use the pre-resolved PY_BIN instead of a bare python3 in the no-venv case, so reset_env can keep dropping uv-containing PATH entries without hiding a co-located interpreter (review comment). - ensure-uv.sh: describe the real install order (active venv, then pip install --user, then the fallback venv) instead of claiming the first attempt is always pip install --user.
…PATH hash Shadow preinstalled uv with a failing stub in the regression test instead of dropping whole PATH entries, so interpreters co-located with uv (e.g. uv and python3 under /usr/local/bin) stay available. Bash caches the location of a command on first lookup, so ensure_uv kept resolving uv to the stub after installing a fresh one and wrongly reported failure. Clear the command hash after each install so ensure_uv re-scans PATH and finds the uv it just installed.
There was a problem hiding this comment.
🟡 Changes recommended
Ubuntu disables system-level ensurepip, causing the updated Ubuntu Docker build to fail.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Balanced
ensurepip is correct for the deadsnakes python3.11, but fall back to bootstrapping pip from bootstrap.pypa.io in case a future base python ever disables ensurepip, so the docker build cannot silently break.
mongodl resolves the 'latest' enterprise build via a presigned S3 URL that needs secretsmanager on the 'drivers/devprod-release-infrastructure' vault. The default instance role cannot read that vault, so the otel test fell back to it and failed. Forward the assumed-role credentials (as run docker test already does) so mongodl uses the drivers_test_secrets_role.
eramongodb
left a comment
There was a problem hiding this comment.
Minor suggestion remaining; otherwise, LGTM.
Co-authored-by: Ezra Chung <88335979+eramongodb@users.noreply.github.com>
…o PYTHON-6005-ensure-uv-fixes
…sfle, and ensure-uv tests
2cd9310 to
e4c93a0
Compare
|
I added the "current" toolchain the most likely candidate to have an up-to-date python, and added tests specifically for |
…le, and ensure-uv tests
… and force-reinstall uv with pip --user
…ath comment, and docker pip Lower the Current-interpreter gate to Python 3.8, matching uv's requirement. Drop mingw/msys from the ensure-uv test's platform case; Evergreen Windows hosts run Cygwin only. Strip the inaccurate cygpath comment. Drop the get-pip.py fallback from the ubuntu22.04 image; ensurepip works on the deadsnakes interpreter, verified in a container, and test-entrypoint.sh fails loudly if pip is ever missing.
eramongodb
left a comment
There was a problem hiding this comment.
One last remark, but otherwise LGTM.
| script: | | ||
| if [ "${clear_persisted_uv|}" = "true" ]; then | ||
| echo "Removing any uv an earlier task left behind, so ensure_uv has to pick an interpreter." | ||
| rm -f "$HOME/.local/bin/uv" |
There was a problem hiding this comment.
It's somewhat 🤔❓ to unconditionally modify the user environment in a manner which may break other tasks running on this EVG host, but EVG tasks technically shouldn't make assumptions about the state of the host anyways (including user directories), so I'm left with mixed feelings but no particular suggestion here.
There was a problem hiding this comment.
My thoughts:
- The fact that we're writing into $HOME at all is a bit suspect
- We're only doing this on the one host
- The tasks run one at a time, so worst case the next user of the host has to bootstrap it again
PYTHON-6005
DRIVERS-3564
Summary
Bug fix and cleanup pass for ensure_uv. The bug for PYTHON-6005 was that we were selecting the system python3 on
tests-rhel82-arm64, which is Python 3.6.We also further improve the use case for Node with OIDC by installing uv into an active venv rather than making another temp venv.
There are also some new tests and improvements to the Dockerfiles.
Changes in this PR
--user, which pip refuses inside a venv.test-ensure-uv.shregression test for the active-venv and pip-without-venv cases. This is the bulk of the diff.tests-rhel82-arm64buildvariant (with step to clear any uv added by a previous run), proving the toolchain is chosen when the system python3 is too old.test-remote-kms-provisioning.sh.Test Plan
make lintclean;config.ymlparses;bash -non changed scripts;test-ensure-uv.shpasses; drivers-tools Evergreen patch green.