CDRIVER-6042 Migrate Python scripts from Poetry to Astral UV #2039
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves CDRIVER-6042. Followup to mongodb/mongo-cxx-driver#1244.
Migrates our Python script configuration and runner from Poetry to Astral UV. This removes the need for manual virtual environment handling, package dependency installation steps, and Python binary compatibility and version management.
Tip
As a reminder, all
uv
commands should be invoked with--frozen
by default to avoid updating theuv.lock
file. TheUV_FROZEN
environment variable can also be set to1
,true
,on
, etc. instead.Scripts which are affected by these changes include:
.evergreen/scripts/clang-format-all.sh
.evergreen/config_generator/*
.evergreen/legacy_config_generator/*
.evergreen/scripts/build-docs.sh
These scripts and related docs have been updated to require/assume invocation via
uv run
. All necessary dependencies (e.g.clang-format
,shrub-py
,sphinx
, etc.) are managed by thepyproject.toml
file and implicitly installed during theuv run
command. As a CI optimization (not a requirement), the--only-group
flag is used to limit the set of packages downloaded for the given task (e.g.format
forclang-format
,docs
forsphinx
).Because Poetry is no longer used, the following helper scripts are removed by this PR:
tools/poetry.sh
(provided by user/system)tools/poetry.ps1
(provided by user/system)tools/python.sh
(handled by uv)Following DEVPROD-13413, most (but not quite all) EVG distros provide a system-installed
uv
binary. Due to the set of tasks requiring uv being relatively small compared to the C++ Driver, theuv-installer.sh
script andInstallUV
component function do not need to be ported over from the C++ Driver. Instead, theubuntu2004
distro (one of the distros currently missing a system-installeduv
) is removed from the list of allowed distros for theclang-format
task. As a result, all tasks which invokeuv
are on distros which provide a system-installeduv
binary (specifically,ubuntu2204
).All dependencies and affected scripts were tested with:
-p <python-version>
(Python versions 3.10 through 3.13).--no-project
(do not use an existing project or workspace).--isolated
(do not reuse the project's virtual environment).--with <dependency>
(to discover and minimize required dependencies).--resolution lowest-direct
(to validate minimum version requirements, but without lowering current requirements).--resolution highest
(the default; to validate forward compatibility with latest versions)This PR does not update minimum required versions for existing dependencies. However, this PR proposes relaxing the max version requirements so newer package versions may be used. Specifically,
>=
is used instead of~=
(equivalent to^
for Poetry). Only packages which must be pinned to a specific version use~=
, which is currently limited toclang-format
.Note
The
uv tree
command displays a helpful visualization of the current package dependency tree. This tree can be used to optimize the list of dependencies. For example,uv tree --outdated --resolution lowest-direct
for the currently proposed dependency list produces the following (abbreviated):Aside: I do not know to prevent
uv tree
with--resolution lowest-direct
from updating the lock file while still evaluating the lowest-direct tree as intended. Passing--frozen
returns thehighest
resolution tree (unmodified). 🤔Additional notes:
sphinx-autobuild
) are removed. Instead, the--with <package>
flag can be used when needed (e.g. see updated instructions in CONTRIBUTING.md). For local development environments,uv pip install
can also be used obtain additional packages without modifying the lock file.yamlordereddictloader
dependency, which is deprecated, has been replaced withyamlloader
instead. This is used by the legacy config generator. Since no prior minimum requirement exists, I've set it to the latest release version (1.5.1 due to 1.5.0 being yanked).mc-evg-generate
entry point, uv requires defining a build system. This PR proposes using Hatchling, the default choice for uv. This also allowsconfig_generator
to be defined as a package, enablingimport config_generator
by other Python scripts within this project (analogous topackages = [ include = "config_generator" ]
with Poetry).--fresh
CMake flag is added tobuild-docs.sh
so that the CMake cache will not incorrectly continue to reuse a Sphinx binary when the script is rerun with an updated Python virtual environment (possibly an entirely new, isolated virtual environment) which provides its own distinct Sphinx binary.RemovedInSphinx90Warning
warnings. These are deliberately ignored for now in favor of applying a<9.0
dependency requirement to avoid breaking changes when Sphinx 9.0 is released. These should be addressed by CDRIVER-6031.doc2path()
should be namedbase
, which is neitherabsolute
(current) norbasedir
(previous) following Fix Debian package build #1470 (CDRIVER-4773). I do not know what's going on with this function, but I've opted to remove the named parameter entirely in favor of simply passingTrue
. (@rcsanchez97 does this change break Debian doc builds again?)