Skip to content

Commit aa636d4

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-python-driver into PYTHON-4576
2 parents 7e46c4a + 8034bae commit aa636d4

File tree

150 files changed

+9265
-2061
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+9265
-2061
lines changed

.evergreen/config.yml

Lines changed: 688 additions & 245 deletions
Large diffs are not rendered by default.

.evergreen/hatch.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@ if [ -n "$SKIP_HATCH" ]; then
1818
run_hatch() {
1919
bash ./.evergreen/run-tests.sh
2020
}
21-
elif $PYTHON_BINARY -m hatch --version; then
22-
run_hatch() {
23-
$PYTHON_BINARY -m hatch run "$@"
24-
}
25-
else # No toolchain hatch present, set up virtualenv before installing hatch
21+
else # Set up virtualenv before installing hatch
2622
# Use a random venv name because the encryption tasks run this script multiple times in the same run.
2723
ENV_NAME=hatchenv-$RANDOM
2824
createvirtualenv "$PYTHON_BINARY" $ENV_NAME
2925
# shellcheck disable=SC2064
3026
trap "deactivate; rm -rf $ENV_NAME" EXIT HUP
3127
python -m pip install -q hatch
28+
29+
# Ensure hatch does not write to user or global locations.
30+
touch hatch_config.toml
31+
HATCH_CONFIG=$(pwd)/hatch_config.toml
32+
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
33+
HATCH_CONFIG=$(cygpath -m "$HATCH_CONFIG")
34+
fi
35+
export HATCH_CONFIG
36+
hatch config restore
37+
hatch config set dirs.data "$(pwd)/.hatch/data"
38+
hatch config set dirs.cache "$(pwd)/.hatch/cache"
39+
3240
run_hatch() {
3341
python -m hatch run "$@"
3442
}

.evergreen/resync-specs.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ do
7676
atlas-data-lake-testing|data_lake)
7777
cpjson atlas-data-lake-testing/tests/ data_lake
7878
;;
79+
bson-binary-vector|bson_binary_vector)
80+
cpjson bson-binary-vector/tests/ bson_binary_vector
81+
;;
7982
bson-corpus|bson_corpus)
8083
cpjson bson-corpus/tests/ bson_corpus
8184
;;

.evergreen/run-tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ set -o xtrace
3030

3131
AUTH=${AUTH:-noauth}
3232
SSL=${SSL:-nossl}
33-
TEST_SUITES=""
33+
TEST_SUITES=${TEST_SUITES:-}
3434
TEST_ARGS="${*:1}"
3535

3636
export PIP_QUIET=1 # Quiet by default
@@ -257,9 +257,9 @@ if [ -z "$GREEN_FRAMEWORK" ]; then
257257
# Use --capture=tee-sys so pytest prints test output inline:
258258
# https://docs.pytest.org/en/stable/how-to/capture-stdout-stderr.html
259259
if [ -z "$TEST_SUITES" ]; then
260-
python -m pytest -v --capture=tee-sys --durations=5 --maxfail=10 $TEST_ARGS
260+
python -m pytest -v --capture=tee-sys --durations=5 $TEST_ARGS
261261
else
262-
python -m pytest -v --capture=tee-sys --durations=5 --maxfail=10 -m $TEST_SUITES $TEST_ARGS
262+
python -m pytest -v --capture=tee-sys --durations=5 -m $TEST_SUITES $TEST_ARGS
263263
fi
264264
else
265265
python green_framework_test.py $GREEN_FRAMEWORK -v $TEST_ARGS

.evergreen/scripts/generate_config.py

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
# /// script
2+
# requires-python = ">=3.9"
3+
# dependencies = [
4+
# "shrub.py>=3.2.0",
5+
# "pyyaml>=6.0.2"
6+
# ]
7+
# ///
8+
9+
# Note: Run this file with `hatch run`, `pipx run`, or `uv run`.
10+
from __future__ import annotations
11+
12+
from dataclasses import dataclass
13+
from itertools import cycle, product, zip_longest
14+
from typing import Any
15+
16+
from shrub.v3.evg_build_variant import BuildVariant
17+
from shrub.v3.evg_project import EvgProject
18+
from shrub.v3.evg_task import EvgTaskRef
19+
from shrub.v3.shrub_service import ShrubService
20+
21+
##############
22+
# Globals
23+
##############
24+
25+
ALL_VERSIONS = ["4.0", "4.4", "5.0", "6.0", "7.0", "8.0", "rapid", "latest"]
26+
CPYTHONS = ["3.9", "3.10", "3.11", "3.12", "3.13"]
27+
PYPYS = ["pypy3.9", "pypy3.10"]
28+
ALL_PYTHONS = CPYTHONS + PYPYS
29+
MIN_MAX_PYTHON = [CPYTHONS[0], CPYTHONS[-1]]
30+
BATCHTIME_WEEK = 10080
31+
AUTH_SSLS = [("auth", "ssl"), ("noauth", "ssl"), ("noauth", "nossl")]
32+
TOPOLOGIES = ["standalone", "replica_set", "sharded_cluster"]
33+
SYNCS = ["sync", "async"]
34+
DISPLAY_LOOKUP = dict(
35+
ssl=dict(ssl="SSL", nossl="NoSSL"),
36+
auth=dict(auth="Auth", noauth="NoAuth"),
37+
test_suites=dict(default="Sync", default_async="Async"),
38+
coverage=dict(coverage="cov"),
39+
)
40+
HOSTS = dict()
41+
42+
43+
@dataclass
44+
class Host:
45+
name: str
46+
run_on: str
47+
display_name: str
48+
expansions: dict[str, str]
49+
50+
51+
_macos_expansions = dict( # CSOT tests are unreliable on slow hosts.
52+
SKIP_CSOT_TESTS="true"
53+
)
54+
55+
HOSTS["rhel8"] = Host("rhel8", "rhel87-small", "RHEL8", dict())
56+
HOSTS["win64"] = Host("win64", "windows-64-vsMulti-small", "Win64", _macos_expansions)
57+
HOSTS["win32"] = Host("win32", "windows-64-vsMulti-small", "Win32", _macos_expansions)
58+
HOSTS["macos"] = Host("macos", "macos-14", "macOS", _macos_expansions)
59+
HOSTS["macos-arm64"] = Host("macos-arm64", "macos-14-arm64", "macOS Arm64", _macos_expansions)
60+
61+
62+
##############
63+
# Helpers
64+
##############
65+
66+
67+
def create_variant(
68+
task_names: list[str],
69+
display_name: str,
70+
*,
71+
python: str | None = None,
72+
version: str | None = None,
73+
host: str | None = None,
74+
**kwargs: Any,
75+
) -> BuildVariant:
76+
"""Create a build variant for the given inputs."""
77+
task_refs = [EvgTaskRef(name=n) for n in task_names]
78+
kwargs.setdefault("expansions", dict())
79+
expansions = kwargs.pop("expansions", dict()).copy()
80+
host = host or "rhel8"
81+
run_on = [HOSTS[host].run_on]
82+
name = display_name.replace(" ", "-").lower()
83+
if python:
84+
expansions["PYTHON_BINARY"] = get_python_binary(python, host)
85+
if version:
86+
expansions["VERSION"] = version
87+
expansions.update(HOSTS[host].expansions)
88+
expansions = expansions or None
89+
return BuildVariant(
90+
name=name,
91+
display_name=display_name,
92+
tasks=task_refs,
93+
expansions=expansions,
94+
run_on=run_on,
95+
**kwargs,
96+
)
97+
98+
99+
def get_python_binary(python: str, host: str) -> str:
100+
"""Get the appropriate python binary given a python version and host."""
101+
if host in ["win64", "win32"]:
102+
if host == "win32":
103+
base = "C:/python/32"
104+
else:
105+
base = "C:/python"
106+
python = python.replace(".", "")
107+
return f"{base}/Python{python}/python.exe"
108+
109+
if host == "rhel8":
110+
return f"/opt/python/{python}/bin/python3"
111+
112+
if host in ["macos", "macos-arm64"]:
113+
return f"/Library/Frameworks/Python.Framework/Versions/{python}/bin/python3"
114+
115+
raise ValueError(f"no match found for python {python} on {host}")
116+
117+
118+
def get_display_name(base: str, host: str, **kwargs) -> str:
119+
"""Get the display name of a variant."""
120+
display_name = f"{base} {HOSTS[host].display_name}"
121+
for key, value in kwargs.items():
122+
name = value
123+
if key == "version":
124+
if value not in ["rapid", "latest"]:
125+
name = f"v{value}"
126+
elif key == "python":
127+
if not value.startswith("pypy"):
128+
name = f"py{value}"
129+
elif key.lower() in DISPLAY_LOOKUP:
130+
name = DISPLAY_LOOKUP[key.lower()][value]
131+
else:
132+
raise ValueError(f"Missing display handling for {key}")
133+
display_name = f"{display_name} {name}"
134+
return display_name
135+
136+
137+
def zip_cycle(*iterables, empty_default=None):
138+
"""Get all combinations of the inputs, cycling over the shorter list(s)."""
139+
cycles = [cycle(i) for i in iterables]
140+
for _ in zip_longest(*iterables):
141+
yield tuple(next(i, empty_default) for i in cycles)
142+
143+
144+
def generate_yaml(tasks=None, variants=None):
145+
"""Generate the yaml for a given set of tasks and variants."""
146+
project = EvgProject(tasks=tasks, buildvariants=variants)
147+
out = ShrubService.generate_yaml(project)
148+
# Dedent by two spaces to match what we use in config.yml
149+
lines = [line[2:] for line in out.splitlines()]
150+
print("\n".join(lines)) # noqa: T201
151+
152+
153+
##############
154+
# Variants
155+
##############
156+
157+
158+
def create_ocsp_variants() -> list[BuildVariant]:
159+
variants = []
160+
batchtime = BATCHTIME_WEEK * 2
161+
expansions = dict(AUTH="noauth", SSL="ssl", TOPOLOGY="server")
162+
base_display = "OCSP test"
163+
164+
# OCSP tests on rhel8 with all servers v4.4+ and all python versions.
165+
versions = [v for v in ALL_VERSIONS if v != "4.0"]
166+
for version, python in zip_cycle(versions, ALL_PYTHONS):
167+
host = "rhel8"
168+
variant = create_variant(
169+
[".ocsp"],
170+
get_display_name(base_display, host, version, python),
171+
python=python,
172+
version=version,
173+
host=host,
174+
expansions=expansions,
175+
batchtime=batchtime,
176+
)
177+
variants.append(variant)
178+
179+
# OCSP tests on Windows and MacOS.
180+
# MongoDB servers on these hosts do not staple OCSP responses and only support RSA.
181+
for host, version in product(["win64", "macos"], ["4.4", "8.0"]):
182+
python = CPYTHONS[0] if version == "4.4" else CPYTHONS[-1]
183+
variant = create_variant(
184+
[".ocsp-rsa !.ocsp-staple"],
185+
get_display_name(base_display, host, version, python),
186+
python=python,
187+
version=version,
188+
host=host,
189+
expansions=expansions,
190+
batchtime=batchtime,
191+
)
192+
variants.append(variant)
193+
194+
return variants
195+
196+
197+
def create_server_variants() -> list[BuildVariant]:
198+
variants = []
199+
200+
# Run the full matrix on linux with min and max CPython, and latest pypy.
201+
host = "rhel8"
202+
for python, (auth, ssl) in product([*MIN_MAX_PYTHON, PYPYS[-1]], AUTH_SSLS):
203+
display_name = f"Test {host}"
204+
expansions = dict(AUTH=auth, SSL=ssl, COVERAGE="coverage")
205+
display_name = get_display_name("Test", host, python=python, **expansions)
206+
variant = create_variant(
207+
[f".{t}" for t in TOPOLOGIES],
208+
display_name,
209+
python=python,
210+
host=host,
211+
tags=["coverage_tag"],
212+
expansions=expansions,
213+
)
214+
variants.append(variant)
215+
216+
# Test the rest of the pythons on linux.
217+
for python, (auth, ssl), topology in zip_cycle(
218+
CPYTHONS[1:-1] + PYPYS[:-1], AUTH_SSLS, TOPOLOGIES
219+
):
220+
display_name = f"Test {host}"
221+
expansions = dict(AUTH=auth, SSL=ssl)
222+
display_name = get_display_name("Test", host, python=python, **expansions)
223+
variant = create_variant(
224+
[f".{topology}"],
225+
display_name,
226+
python=python,
227+
host=host,
228+
expansions=expansions,
229+
)
230+
variants.append(variant)
231+
232+
# Test a subset on each of the other platforms.
233+
for host in ("macos", "macos-arm64", "win64", "win32"):
234+
for (python, (auth, ssl), topology), sync in product(
235+
zip_cycle(MIN_MAX_PYTHON, AUTH_SSLS, TOPOLOGIES), SYNCS
236+
):
237+
test_suite = "default" if sync == "sync" else "default_async"
238+
expansions = dict(AUTH=auth, SSL=ssl, TEST_SUITES=test_suite)
239+
display_name = get_display_name("Test", host, python=python, **expansions)
240+
variant = create_variant(
241+
[f".{topology}"],
242+
display_name,
243+
python=python,
244+
host=host,
245+
expansions=expansions,
246+
)
247+
variants.append(variant)
248+
249+
return variants
250+
251+
252+
##################
253+
# Generate Config
254+
##################
255+
256+
generate_yaml(variants=create_server_variants())

.evergreen/utils.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ set -o xtrace
44

55
find_python3() {
66
PYTHON=""
7-
# Add a fallback system python3 if it is available and Python 3.8+.
8-
if is_python_38 "$(command -v python3)"; then
7+
# Add a fallback system python3 if it is available and Python 3.9+.
8+
if is_python_39 "$(command -v python3)"; then
99
PYTHON="$(command -v python3)"
1010
fi
1111
# Find a suitable toolchain version, if available.
@@ -14,23 +14,23 @@ find_python3() {
1414
if [ -d "/Library/Frameworks/Python.Framework/Versions/3.10" ]; then
1515
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.10/bin/python3"
1616
# macos 10.14
17-
elif [ -d "/Library/Frameworks/Python.Framework/Versions/3.8" ]; then
18-
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.8/bin/python3"
17+
elif [ -d "/Library/Frameworks/Python.Framework/Versions/3.9" ]; then
18+
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.9/bin/python3"
1919
fi
2020
elif [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
21-
PYTHON="C:/python/Python38/python.exe"
21+
PYTHON="C:/python/Python39/python.exe"
2222
else
23-
# Prefer our own toolchain, fall back to mongodb toolchain if it has Python 3.8+.
24-
if [ -f "/opt/python/3.8/bin/python3" ]; then
25-
PYTHON="/opt/python/3.8/bin/python3"
26-
elif is_python_38 "$(command -v /opt/mongodbtoolchain/v4/bin/python3)"; then
23+
# 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"
26+
elif is_python_39 "$(command -v /opt/mongodbtoolchain/v4/bin/python3)"; then
2727
PYTHON="/opt/mongodbtoolchain/v4/bin/python3"
28-
elif is_python_38 "$(command -v /opt/mongodbtoolchain/v3/bin/python3)"; then
28+
elif is_python_39 "$(command -v /opt/mongodbtoolchain/v3/bin/python3)"; then
2929
PYTHON="/opt/mongodbtoolchain/v3/bin/python3"
3030
fi
3131
fi
3232
if [ -z "$PYTHON" ]; then
33-
echo "Cannot test without python3.8+ installed!"
33+
echo "Cannot test without python3.9+ installed!"
3434
exit 1
3535
fi
3636
echo "$PYTHON"
@@ -96,15 +96,15 @@ testinstall () {
9696
fi
9797
}
9898

99-
# Function that returns success if the provided Python binary is version 3.8 or later
99+
# Function that returns success if the provided Python binary is version 3.9 or later
100100
# Usage:
101-
# is_python_38 /path/to/python
101+
# is_python_39 /path/to/python
102102
# * param1: Python binary
103-
is_python_38() {
103+
is_python_39() {
104104
if [ -z "$1" ]; then
105105
return 1
106-
elif $1 -c "import sys; exit(sys.version_info[:2] < (3, 8))"; then
107-
# runs when sys.version_info[:2] >= (3, 8)
106+
elif $1 -c "import sys; exit(sys.version_info[:2] < (3, 9))"; then
107+
# runs when sys.version_info[:2] >= (3, 9)
108108
return 0
109109
else
110110
return 1

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
uses: actions/checkout@v4
4040
with:
4141
ref: ${{ inputs.ref }}
42-
- uses: actions/setup-python@v3
42+
- uses: actions/setup-python@v5
4343

4444
# Initializes the CodeQL tools for scanning.
4545
- name: Initialize CodeQL

0 commit comments

Comments
 (0)