Skip to content

Commit 9da8ebc

Browse files
authored
DRIVERS-3253 add support for uv.lock in install-cli.sh (#678)
1 parent 98f6b0e commit 9da8ebc

File tree

9 files changed

+364
-35
lines changed

9 files changed

+364
-35
lines changed

.evergreen/install-cli.sh

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ if ! command -V uv &>/dev/null; then
6969
echo "Installing uv using pip..."
7070
venvcreate "$DRIVERS_TOOLS_PYTHON" "$_venv_dir"
7171
# Install uv into the newly created venv.
72-
python -m pip install -q --force-reinstall -r requirements-cli.txt
72+
python -m pip install -q --force-reinstall uv
7373
_suffix=""
7474
# Symlink uv and uvx binaries.
7575
_install_dir="${DRIVERS_TOOLS}/.bin"
@@ -99,32 +99,40 @@ uv venv venv &>/dev/null
9999
popd >/dev/null # $SCRIPT_DIR
100100
pushd "$TARGET_DIR" >/dev/null
101101

102+
# uv requires UV_TOOL_BIN_DIR is `C:\a\b\c` instead of `/cygdrive/c/a/b/c` on Windows.
103+
if [[ "${OSTYPE:?}" == cygwin ]]; then
104+
UV_TOOL_BIN_DIR="$(cygpath -aw .)"
105+
else
106+
UV_TOOL_BIN_DIR="$(pwd)"
107+
fi
108+
export UV_TOOL_BIN_DIR
109+
110+
# Pin the uv binary version used by subsequent commands.
111+
uv tool install -q --force "uv~=0.8.0"
112+
PATH="${UV_TOOL_BIN_DIR:?}:${PATH:-}"
113+
command -V uv
114+
uv --version
115+
116+
# Workaround for https://github.com/astral-sh/uv/issues/5815.
117+
uv export --quiet --frozen --format requirements.txt -o uv-requirements.txt
118+
119+
# Support overriding lockfile dependencies.
120+
if [[ ! -f "${DRIVERS_TOOLS_INSTALL_CLI_OVERRIDES:-}" ]]; then
121+
printf "" >|"${DRIVERS_TOOLS_INSTALL_CLI_OVERRIDES:="uv-override-dependencies.txt"}"
122+
fi
123+
102124
declare uv_install_args
103125
uv_install_args=(
104126
--quiet
105127
--force
106128
--editable
107-
--with certifi
129+
--with-requirements uv-requirements.txt
130+
--overrides "${DRIVERS_TOOLS_INSTALL_CLI_OVERRIDES:?}"
108131
)
132+
uv tool install "${uv_install_args[@]:?}" .
109133

110-
# Preserve pymongo compatibility with the requested server version.
111-
case "${MONGODB_VERSION:-"latest"}" in
112-
3.6) uv_install_args+=(--with "pymongo<4.11") ;;
113-
4.0) uv_install_args+=(--with "pymongo<4.14") ;;
114-
esac
115-
116-
# On Windows, we have to do a bit of path manipulation.
117-
if [ "Windows_NT" == "${OS:-}" ]; then
118-
TMP_DIR=$(cygpath -m "$(mktemp -d)")
119-
PATH="$SCRIPT_DIR/venv/Scripts:$PATH"
120-
UV_TOOL_BIN_DIR=${TMP_DIR} uv tool install "${uv_install_args[@]:?}" .
121-
filenames=$(ls ${TMP_DIR})
122-
for filename in $filenames; do
123-
mv $TMP_DIR/$filename "$1/${filename//.exe/}"
124-
done
125-
rm -rf $TMP_DIR
126-
else
127-
UV_TOOL_BIN_DIR=$(pwd) uv tool install "${uv_install_args[@]:?}" .
128-
fi
134+
# Support running tool executables on Windows without including the ".exe" suffix.
135+
find . -maxdepth 1 -type f -name '*.exe' -exec \
136+
bash -c "ln -sf \"\$0\" \"\$(echo \"\$0\" | sed -E -e 's|(.*)\.exe|\1|')\"" {} \;
129137

130138
popd >/dev/null # "$TARGET_DIR"

.evergreen/orchestration/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66
name = "drivers-orchestration"
77
version = "0.1.0"
88
description = 'Scripts for drivers orchestration'
9-
requires-python = ">=3.8"
9+
requires-python = ">=3.9"
1010
license = "MIT"
1111
keywords = []
1212
authors = [

.evergreen/orchestration/setup.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33

44
set -o errexit
55

6-
SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
7-
. $SCRIPT_DIR/../handle-paths.sh
6+
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
7+
. "${SCRIPT_DIR:?}/../handle-paths.sh"
8+
9+
export DRIVERS_TOOLS_INSTALL_CLI_OVERRIDES
10+
DRIVERS_TOOLS_INSTALL_CLI_OVERRIDES="${SCRIPT_DIR:?}/uv-override-dependencies.txt"
11+
printf "" >|"${DRIVERS_TOOLS_INSTALL_CLI_OVERRIDES:?}"
12+
13+
# Preserve pymongo compatibility with the requested server version.
14+
case "${MONGODB_VERSION:-"latest"}" in
15+
3.6) echo "pymongo<4.11" >>"${DRIVERS_TOOLS_INSTALL_CLI_OVERRIDES:?}" ;;
16+
4.0) echo "pymongo<4.14" >>"${DRIVERS_TOOLS_INSTALL_CLI_OVERRIDES:?}" ;;
17+
esac
818

919
# Install CLIs into this directory (default path for $PROJECT_ORCHESTRATION_HOME
1020
# and $MONGO_ORCHESTRATION_HOME) and the parent directory ($DRIVERS_TOOLS).
11-
bash $SCRIPT_DIR/../install-cli.sh $SCRIPT_DIR/..
12-
bash $SCRIPT_DIR/../install-cli.sh $SCRIPT_DIR
21+
bash "${SCRIPT_DIR:?}/../install-cli.sh" "${SCRIPT_DIR:?}/.."
22+
bash "${SCRIPT_DIR:?}/../install-cli.sh" "${SCRIPT_DIR:?}"

.evergreen/orchestration/uv.lock

Lines changed: 282 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.evergreen/requirements-cli.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

.evergreen/requirements-in-cli.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.evergreen/uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ container_id.txt
136136
bin
137137
perf-report.md
138138
perf-report.txt
139+
uv-requirements.txt
140+
uv-override-dependencies.txt
139141

140142
# Azure functions.
141143
.python_packages/

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,34 @@ export TLS_PEM_KEY_FILE=<path-to>/server.pem
105105
export TLS_CA_FILE=<path-to>/ca.pem
106106
```
107107

108+
## Updating Dependencies
109+
110+
The MongoDB server management scripts under [`.evergreen/orchestration`](https://github.com/mongodb-labs/drivers-evergreen-tools/tree/master/.evergreen/orchestration)
111+
depend on [PyMongo](https://pymongo.readthedocs.io/en/stable/). Package dependencies are pinned by the
112+
[`.evergreen/orchestration/uv.lock`](https://github.com/eramongodb/drivers-evergreen-tools/blob/master/.evergreen/orchestration/uv.lock)
113+
lockfile. When the lockfile is updated, ensure the updated PyMongo version still supports old server versions which are
114+
still in use by downstream projects.
115+
116+
If a [recent release](https://pymongo.readthedocs.io/en/stable/changelog.html) of PyMongo drops support for an old
117+
server version that is still in use by downstream projects, add a dependency override to
118+
[`.evergreen/orchestration/setup.sh`](https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/orchestration/setup.sh).
119+
Otherwise, an error similar to the following may occur during mongo-orchestration operations (e.g. with server 4.0 and
120+
PyMongo 4.14):
121+
122+
```
123+
[ERROR] mongo_orchestration.apps:68 - ...
124+
Traceback (most recent call last):
125+
...
126+
File ".../drivers-orchestration/lib/python3.13/site-packages/pymongo/synchronous/topology.py", line 369, in _select_servers_loop
127+
self._description.check_compatible()
128+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
129+
File ".../drivers-orchestration/lib/python3.13/site-packages/pymongo/topology_description.py", line 168, in check_compatible
130+
raise ConfigurationError(self._incompatible_err)
131+
pymongo.errors.ConfigurationError: Server at localhost:27017 reports wire version 7, but this version of PyMongo requires at least 8 (MongoDB 4.2).
132+
```
133+
134+
The dependency override may be removed once all downstream projects have also dropped support for the old server version.
135+
108136
## Linters and Formatters
109137

110138
This repo uses [pre-commit](https://pre-commit.com/) for managing linting and formatting of the codebase.

0 commit comments

Comments
 (0)