Skip to content

Commit 8274db2

Browse files
authored
PYTHON-5203 Use uv from Python toolchain if available (mongodb#2200)
1 parent 0351992 commit 8274db2

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

.evergreen/scripts/configure-env.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,24 @@ cat <<EOT > expansion.yml
9292
DRIVERS_TOOLS: "$DRIVERS_TOOLS"
9393
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
9494
EOT
95+
96+
# If the toolchain is available, symlink binaries to the bin dir. This has to be done
97+
# after drivers-tools is cloned, since we might be using its binary dir.
98+
_bin_path=""
99+
if [ "Windows_NT" == "${OS:-}" ]; then
100+
_bin_path="/cygdrive/c/Python/Current/Scripts"
101+
elif [ "$(uname -s)" != "Darwin" ]; then
102+
_bin_path="/Library/Frameworks/Python.Framework/Versions/Current/bin"
103+
else
104+
_bin_path="/opt/python/Current/bin"
105+
fi
106+
if [ -d "${_bin_path}" ]; then
107+
_suffix=""
108+
if [ "Windows_NT" == "${OS:-}" ]; then
109+
_suffix=".exe"
110+
fi
111+
mkdir -p $PYMONGO_BIN_DIR
112+
ln -s ${_bin_path}/just${_suffix} $PYMONGO_BIN_DIR/just${_suffix}
113+
ln -s ${_bin_path}/uv${_suffix} $PYMONGO_BIN_DIR/uv${_suffix}
114+
ln -s ${_bin_path}/uvx${_suffix} $PYMONGO_BIN_DIR/uvx${_suffix}
115+
fi

.evergreen/scripts/install-dependencies.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ function _pip_install() {
2424
echo "Installing $2 using pip..."
2525
createvirtualenv "$(find_python3)" $_VENV_PATH
2626
python -m pip install $1
27+
_suffix=""
2728
if [ "Windows_NT" = "${OS:-}" ]; then
28-
ln -s "$(which $2)" $_BIN_DIR/$2.exe
29-
else
30-
ln -s "$(which $2)" $_BIN_DIR/$2
29+
_suffix=".exe"
30+
fi
31+
ln -s "$(which $2)" $_BIN_DIR/${2}${_suffix}
32+
# uv also comes with a uvx binary.
33+
if [ $2 == "uv" ]; then
34+
ln -s "$(which uvx)" $_BIN_DIR/uvx${_suffix}
3135
fi
3236
echo "Installed to ${_BIN_DIR}"
3337
echo "Installing $2 using pip... done."

.evergreen/scripts/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ def run_command(cmd: str | list[str], **kwargs: Any) -> None:
137137
cmd = " ".join(cmd)
138138
LOGGER.info("Running command '%s'...", cmd)
139139
kwargs.setdefault("check", True)
140-
subprocess.run(shlex.split(cmd), **kwargs) # noqa: PLW1510, S603
140+
try:
141+
subprocess.run(shlex.split(cmd), **kwargs) # noqa: PLW1510, S603
142+
except subprocess.CalledProcessError as e:
143+
LOGGER.error(e.output)
144+
LOGGER.error(str(e))
145+
sys.exit(e.returncode)
141146
LOGGER.info("Running command '%s'... done.", cmd)
142147

143148

.evergreen/utils.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,29 @@ set -eu
44

55
find_python3() {
66
PYTHON=""
7-
# Add a fallback system python3 if it is available and Python 3.9+.
8-
if is_python_39 "$(command -v python3)"; then
9-
PYTHON="$(command -v python3)"
10-
fi
117
# Find a suitable toolchain version, if available.
128
if [ "$(uname -s)" = "Darwin" ]; then
13-
# macos 11.00
14-
if [ -d "/Library/Frameworks/Python.Framework/Versions/3.10" ]; then
15-
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.10/bin/python3"
16-
# macos 10.14
17-
elif [ -d "/Library/Frameworks/Python.Framework/Versions/3.9" ]; then
18-
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.9/bin/python3"
19-
fi
9+
PYTHON="/Library/Frameworks/Python.Framework/Versions/Current/bin/python3"
2010
elif [ "Windows_NT" = "${OS:-}" ]; then # Magic variable in cygwin
21-
PYTHON="C:/python/Python39/python.exe"
11+
PYTHON="C:/python/Current/python.exe"
2212
else
2313
# Prefer our own toolchain, fall back to mongodb toolchain if it has Python 3.9+.
24-
if [ -f "/opt/python/3.9/bin/python3" ]; then
25-
PYTHON="/opt/python/3.9/bin/python3"
14+
if [ -f "/opt/python/Current/bin/python3" ]; then
15+
PYTHON="/opt/python/Current/bin/python3"
16+
elif is_python_39 "$(command -v /opt/mongodbtoolchain/v5/bin/python3)"; then
17+
PYTHON="/opt/mongodbtoolchain/v5/bin/python3"
2618
elif is_python_39 "$(command -v /opt/mongodbtoolchain/v4/bin/python3)"; then
2719
PYTHON="/opt/mongodbtoolchain/v4/bin/python3"
2820
elif is_python_39 "$(command -v /opt/mongodbtoolchain/v3/bin/python3)"; then
2921
PYTHON="/opt/mongodbtoolchain/v3/bin/python3"
3022
fi
3123
fi
24+
# Add a fallback system python3 if it is available and Python 3.9+.
25+
if [ -z "$PYTHON" ]; then
26+
if is_python_39 "$(command -v python3)"; then
27+
PYTHON="$(command -v python3)"
28+
fi
29+
fi
3230
if [ -z "$PYTHON" ]; then
3331
echo "Cannot test without python3.9+ installed!"
3432
exit 1

0 commit comments

Comments
 (0)