Skip to content

PYTHON-6005 & DRIVERS-3564 Fix ensure_uv Python selection and active-venv install - #842

Merged
blink1073 merged 29 commits into
mongodb-labs:masterfrom
blink1073:PYTHON-6005-ensure-uv-fixes
Sep 18, 2026
Merged

blink1073 merged 29 commits into
mongodb-labs:masterfrom
blink1073:PYTHON-6005-ensure-uv-fixes

Conversation

@blink1073

@blink1073 blink1073 commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

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

  • Update the logic to prefer the latest mongodb toolchain python over the system python unconditionall.
  • Install uv into an active venv (upgrading pip first) rather than using --user, which pip refuses inside a venv.
  • Add a per-PR test-ensure-uv.sh regression test for the active-venv and pip-without-venv cases. This is the bulk of the diff.
  • Add a tests-rhel82-arm64 buildvariant (with step to clear any uv added by a previous run), proving the toolchain is chosen when the system python3 is too old.
  • Drop the obsolete fallback-venv assertion in test-remote-kms-provisioning.sh.
  • Update the Dockerfiles to make sure pip is available, removing the need for the venv fallback pass there.

Test Plan

  • make lint clean; config.yml parses; bash -n on changed scripts; test-ensure-uv.sh passes; drivers-tools Evergreen patch green.
  • Passing build with Node OIDC to verify that the active venv case still works.

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.
@blink1073 blink1073 changed the title [PYTHON-6005]: Fix ensure_uv Python selection and active-venv install PYTHON-6005 & DRIVERS-3564 Fix ensure_uv Python selection and active-venv install Sep 11, 2026
@blink1073
blink1073 requested a balanced review from Copilot September 11, 2026 23:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 uv directly 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.

Comment thread .evergreen/tests/test-ensure-uv.sh Resolved
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread .evergreen/tests/test-ensure-uv.sh Resolved
Comment thread .evergreen/tests/test-ensure-uv.sh Resolved
@blink1073
blink1073 requested a balanced review from Copilot September 14, 2026 15:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread .evergreen/tests/test-ensure-uv.sh Resolved
Comment thread .evergreen/ensure-uv.sh Resolved
…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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation matches the stated behavior and includes targeted cross-platform regression coverage.

Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

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.
@blink1073
blink1073 marked this pull request as ready for review September 14, 2026 20:41
@blink1073
blink1073 requested a review from a team as a code owner September 14, 2026 20:41
Comment thread .evergreen/tests/test-ensure-uv.sh Resolved
Comment thread .evergreen/ensure-uv.sh Resolved
Comment thread .evergreen/tests/test-ensure-uv.sh Resolved
eramongodb
eramongodb previously approved these changes Sep 16, 2026

@eramongodb eramongodb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion remaining; otherwise, LGTM.

Comment thread .evergreen/ensure-uv.sh Resolved
blink1073 and others added 2 commits September 16, 2026 15:39
Co-authored-by: Ezra Chung <88335979+eramongodb@users.noreply.github.com>
@blink1073
blink1073 force-pushed the PYTHON-6005-ensure-uv-fixes branch from 2cd9310 to e4c93a0 Compare September 17, 2026 00:36
@blink1073

Copy link
Copy Markdown
Member Author

I added the "current" toolchain the most likely candidate to have an up-to-date python, and added tests specifically for windows-vsCurrent and windows-2022-latest to prevent regressions on those hosts.

Comment thread .evergreen/ensure-uv.sh Resolved
Comment thread .evergreen/tests/test-ensure-uv.sh Resolved
Comment thread .evergreen/ensure-uv.sh Resolved
…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 eramongodb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last remark, but otherwise LGTM.

Comment thread .evergreen/config.yml
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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@blink1073
blink1073 merged commit 63fb776 into mongodb-labs:master Sep 18, 2026
129 of 131 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants