Skip to content

Commit d423bc3

Browse files
authored
Merge branch 'master' into PYTHON-2390
2 parents 382a94c + 668bd82 commit d423bc3

File tree

10 files changed

+89
-63
lines changed

10 files changed

+89
-63
lines changed

.evergreen/run-tests.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ else
2525
exit 1
2626
fi
2727

28-
# List the packages.
29-
uv sync ${UV_ARGS} --reinstall --quiet
30-
uv pip list
31-
3228
# Start the test runner.
33-
uv run ${UV_ARGS} .evergreen/scripts/run_tests.py "$@"
29+
uv run ${UV_ARGS} --reinstall .evergreen/scripts/run_tests.py "$@"
3430

3531
popd

.evergreen/scripts/generate_config_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def generate_yaml(tasks=None, variants=None):
273273
out = ShrubService.generate_yaml(project)
274274
# Dedent by two spaces to match what we use in config.yml
275275
lines = [line[2:] for line in out.splitlines()]
276-
print("\n".join(lines)) # noqa: T201
276+
print("\n".join(lines))
277277

278278

279279
##################

.evergreen/scripts/resync-all-specs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def resync_specs(directory: pathlib.Path, errored: dict[str, str]) -> None:
1313
"""Actually sync the specs"""
14-
print("Beginning to sync specs") # noqa: T201
14+
print("Beginning to sync specs")
1515
for spec in os.scandir(directory):
1616
if not spec.is_dir():
1717
continue
@@ -27,11 +27,11 @@ def resync_specs(directory: pathlib.Path, errored: dict[str, str]) -> None:
2727
)
2828
except CalledProcessError as exc:
2929
errored[spec.name] = exc.stderr
30-
print("Done syncing specs") # noqa: T201
30+
print("Done syncing specs")
3131

3232

3333
def apply_patches():
34-
print("Beginning to apply patches") # noqa: T201
34+
print("Beginning to apply patches")
3535
subprocess.run(["bash", "./.evergreen/remove-unimplemented-tests.sh"], check=True) # noqa: S603, S607
3636
subprocess.run(
3737
["git apply -R --allow-empty --whitespace=fix ./.evergreen/spec-patch/*"], # noqa: S607
@@ -95,7 +95,7 @@ def write_summary(errored: dict[str, str], new: list[str], filename: Optional[st
9595
pr_body += "\n"
9696
if pr_body != "":
9797
if filename is None:
98-
print(f"\n{pr_body}") # noqa: T201
98+
print(f"\n{pr_body}")
9999
else:
100100
with open(filename, "w") as f:
101101
# replacements made for proper json

.evergreen/scripts/run_tests.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
from pathlib import Path
1111
from shutil import which
1212

13+
try:
14+
import importlib_metadata
15+
except ImportError:
16+
from importlib import metadata as importlib_metadata
17+
18+
1319
import pytest
1420
from utils import DRIVERS_TOOLS, LOGGER, ROOT, run_command
1521

@@ -23,6 +29,21 @@
2329
SUB_TEST_NAME = os.environ.get("SUB_TEST_NAME")
2430

2531

32+
def list_packages():
33+
packages = dict()
34+
for distribution in importlib_metadata.distributions():
35+
packages[distribution.name] = distribution
36+
print("Package Version URL")
37+
print("------------------- ----------- ----------------------------------------------------")
38+
for name in sorted(packages):
39+
distribution = packages[name]
40+
url = ""
41+
if distribution.origin is not None:
42+
url = distribution.origin.url
43+
print(f"{name:20s}{distribution.version:12s}{url}")
44+
print("------------------- ----------- ----------------------------------------------------\n")
45+
46+
2647
def handle_perf(start_time: datetime):
2748
end_time = datetime.now()
2849
elapsed_secs = (end_time - start_time).total_seconds()
@@ -121,6 +142,9 @@ def handle_aws_lambda() -> None:
121142

122143

123144
def run() -> None:
145+
# List the installed packages.
146+
list_packages()
147+
124148
# Handle green framework first so they can patch modules.
125149
if GREEN_FRAMEWORK:
126150
handle_green_framework()

.evergreen/scripts/setup_tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ def handle_test_env() -> None:
346346
setup_libmongocrypt()
347347

348348
# TODO: Test with 'pip install pymongocrypt'
349-
UV_ARGS.append("--group pymongocrypt_source")
349+
UV_ARGS.append(
350+
"--with pymongocrypt@git+https://github.com/mongodb/libmongocrypt@master#subdirectory=bindings/python"
351+
)
350352

351353
# Use the nocrypto build to avoid dependency issues with older windows/python versions.
352354
BASE = ROOT / "libmongocrypt/nocrypto"

pymongo/asynchronous/collection.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,18 +2144,18 @@ async def count_documents(
21442144
if comment is not None:
21452145
kwargs["comment"] = comment
21462146
pipeline.append({"$group": {"_id": 1, "n": {"$sum": 1}}})
2147-
cmd = {"aggregate": self._name, "pipeline": pipeline, "cursor": {}}
21482147
if "hint" in kwargs and not isinstance(kwargs["hint"], str):
21492148
kwargs["hint"] = helpers_shared._index_document(kwargs["hint"])
21502149
collation = validate_collation_or_none(kwargs.pop("collation", None))
2151-
cmd.update(kwargs)
21522150

21532151
async def _cmd(
21542152
session: Optional[AsyncClientSession],
21552153
_server: Server,
21562154
conn: AsyncConnection,
21572155
read_preference: Optional[_ServerMode],
21582156
) -> int:
2157+
cmd: dict[str, Any] = {"aggregate": self._name, "pipeline": pipeline, "cursor": {}}
2158+
cmd.update(kwargs)
21592159
result = await self._aggregate_one_result(
21602160
conn, read_preference, cmd, collation, session
21612161
)
@@ -3194,26 +3194,27 @@ async def distinct(
31943194
"""
31953195
if not isinstance(key, str):
31963196
raise TypeError(f"key must be an instance of str, not {type(key)}")
3197-
cmd = {"distinct": self._name, "key": key}
31983197
if filter is not None:
31993198
if "query" in kwargs:
32003199
raise ConfigurationError("can't pass both filter and query")
32013200
kwargs["query"] = filter
32023201
collation = validate_collation_or_none(kwargs.pop("collation", None))
3203-
cmd.update(kwargs)
3204-
if comment is not None:
3205-
cmd["comment"] = comment
32063202
if hint is not None:
32073203
if not isinstance(hint, str):
32083204
hint = helpers_shared._index_document(hint)
3209-
cmd["hint"] = hint # type: ignore[assignment]
32103205

32113206
async def _cmd(
32123207
session: Optional[AsyncClientSession],
32133208
_server: Server,
32143209
conn: AsyncConnection,
32153210
read_preference: Optional[_ServerMode],
32163211
) -> list: # type: ignore[type-arg]
3212+
cmd = {"distinct": self._name, "key": key}
3213+
cmd.update(kwargs)
3214+
if comment is not None:
3215+
cmd["comment"] = comment
3216+
if hint is not None:
3217+
cmd["hint"] = hint # type: ignore[assignment]
32173218
return (
32183219
await self._command(
32193220
conn,
@@ -3248,27 +3249,26 @@ async def _find_and_modify(
32483249
f"return_document must be ReturnDocument.BEFORE or ReturnDocument.AFTER, not {type(return_document)}"
32493250
)
32503251
collation = validate_collation_or_none(kwargs.pop("collation", None))
3251-
cmd = {"findAndModify": self._name, "query": filter, "new": return_document}
3252-
if let is not None:
3253-
common.validate_is_mapping("let", let)
3254-
cmd["let"] = let
3255-
cmd.update(kwargs)
3256-
if projection is not None:
3257-
cmd["fields"] = helpers_shared._fields_list_to_dict(projection, "projection")
3258-
if sort is not None:
3259-
cmd["sort"] = helpers_shared._index_document(sort)
3260-
if upsert is not None:
3261-
validate_boolean("upsert", upsert)
3262-
cmd["upsert"] = upsert
32633252
if hint is not None:
32643253
if not isinstance(hint, str):
32653254
hint = helpers_shared._index_document(hint)
3266-
3267-
write_concern = self._write_concern_for_cmd(cmd, session)
3255+
write_concern = self._write_concern_for_cmd(kwargs, session)
32683256

32693257
async def _find_and_modify_helper(
32703258
session: Optional[AsyncClientSession], conn: AsyncConnection, retryable_write: bool
32713259
) -> Any:
3260+
cmd = {"findAndModify": self._name, "query": filter, "new": return_document}
3261+
if let is not None:
3262+
common.validate_is_mapping("let", let)
3263+
cmd["let"] = let
3264+
cmd.update(kwargs)
3265+
if projection is not None:
3266+
cmd["fields"] = helpers_shared._fields_list_to_dict(projection, "projection")
3267+
if sort is not None:
3268+
cmd["sort"] = helpers_shared._index_document(sort)
3269+
if upsert is not None:
3270+
validate_boolean("upsert", upsert)
3271+
cmd["upsert"] = upsert
32723272
acknowledged = write_concern.acknowledged
32733273
if array_filters is not None:
32743274
if not acknowledged:

pymongo/synchronous/collection.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,18 +2143,18 @@ def count_documents(
21432143
if comment is not None:
21442144
kwargs["comment"] = comment
21452145
pipeline.append({"$group": {"_id": 1, "n": {"$sum": 1}}})
2146-
cmd = {"aggregate": self._name, "pipeline": pipeline, "cursor": {}}
21472146
if "hint" in kwargs and not isinstance(kwargs["hint"], str):
21482147
kwargs["hint"] = helpers_shared._index_document(kwargs["hint"])
21492148
collation = validate_collation_or_none(kwargs.pop("collation", None))
2150-
cmd.update(kwargs)
21512149

21522150
def _cmd(
21532151
session: Optional[ClientSession],
21542152
_server: Server,
21552153
conn: Connection,
21562154
read_preference: Optional[_ServerMode],
21572155
) -> int:
2156+
cmd: dict[str, Any] = {"aggregate": self._name, "pipeline": pipeline, "cursor": {}}
2157+
cmd.update(kwargs)
21582158
result = self._aggregate_one_result(conn, read_preference, cmd, collation, session)
21592159
if not result:
21602160
return 0
@@ -3187,26 +3187,27 @@ def distinct(
31873187
"""
31883188
if not isinstance(key, str):
31893189
raise TypeError(f"key must be an instance of str, not {type(key)}")
3190-
cmd = {"distinct": self._name, "key": key}
31913190
if filter is not None:
31923191
if "query" in kwargs:
31933192
raise ConfigurationError("can't pass both filter and query")
31943193
kwargs["query"] = filter
31953194
collation = validate_collation_or_none(kwargs.pop("collation", None))
3196-
cmd.update(kwargs)
3197-
if comment is not None:
3198-
cmd["comment"] = comment
31993195
if hint is not None:
32003196
if not isinstance(hint, str):
32013197
hint = helpers_shared._index_document(hint)
3202-
cmd["hint"] = hint # type: ignore[assignment]
32033198

32043199
def _cmd(
32053200
session: Optional[ClientSession],
32063201
_server: Server,
32073202
conn: Connection,
32083203
read_preference: Optional[_ServerMode],
32093204
) -> list: # type: ignore[type-arg]
3205+
cmd = {"distinct": self._name, "key": key}
3206+
cmd.update(kwargs)
3207+
if comment is not None:
3208+
cmd["comment"] = comment
3209+
if hint is not None:
3210+
cmd["hint"] = hint # type: ignore[assignment]
32103211
return (
32113212
self._command(
32123213
conn,
@@ -3241,27 +3242,26 @@ def _find_and_modify(
32413242
f"return_document must be ReturnDocument.BEFORE or ReturnDocument.AFTER, not {type(return_document)}"
32423243
)
32433244
collation = validate_collation_or_none(kwargs.pop("collation", None))
3244-
cmd = {"findAndModify": self._name, "query": filter, "new": return_document}
3245-
if let is not None:
3246-
common.validate_is_mapping("let", let)
3247-
cmd["let"] = let
3248-
cmd.update(kwargs)
3249-
if projection is not None:
3250-
cmd["fields"] = helpers_shared._fields_list_to_dict(projection, "projection")
3251-
if sort is not None:
3252-
cmd["sort"] = helpers_shared._index_document(sort)
3253-
if upsert is not None:
3254-
validate_boolean("upsert", upsert)
3255-
cmd["upsert"] = upsert
32563245
if hint is not None:
32573246
if not isinstance(hint, str):
32583247
hint = helpers_shared._index_document(hint)
3259-
3260-
write_concern = self._write_concern_for_cmd(cmd, session)
3248+
write_concern = self._write_concern_for_cmd(kwargs, session)
32613249

32623250
def _find_and_modify_helper(
32633251
session: Optional[ClientSession], conn: Connection, retryable_write: bool
32643252
) -> Any:
3253+
cmd = {"findAndModify": self._name, "query": filter, "new": return_document}
3254+
if let is not None:
3255+
common.validate_is_mapping("let", let)
3256+
cmd["let"] = let
3257+
cmd.update(kwargs)
3258+
if projection is not None:
3259+
cmd["fields"] = helpers_shared._fields_list_to_dict(projection, "projection")
3260+
if sort is not None:
3261+
cmd["sort"] = helpers_shared._index_document(sort)
3262+
if upsert is not None:
3263+
validate_boolean("upsert", upsert)
3264+
cmd["upsert"] = upsert
32653265
acknowledged = write_concern.acknowledged
32663266
if array_filters is not None:
32673267
if not acknowledged:

pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ coverage = [
6060
mockupdb = [
6161
"mockupdb@git+https://github.com/mongodb-labs/mongo-mockup-db@master"
6262
]
63-
pymongocrypt_source = [
64-
"pymongocrypt@git+https://github.com/mongodb/libmongocrypt@master#subdirectory=bindings/python"
65-
]
6663
perf = ["simplejson"]
6764
typing = [
6865
"mypy==1.18.1",
@@ -238,6 +235,7 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?)|dummy.*)$"
238235

239236
[tool.ruff.lint.per-file-ignores]
240237
"pymongo/__init__.py" = ["E402"]
238+
".evergreen/scripts/*.py" = ["T201"]
241239
"test/*.py" = ["PT", "E402", "PLW", "SIM", "E741", "PTH", "S", "B904", "E722", "T201",
242240
"RET", "ARG", "F405", "B028", "PGH001", "B018", "F403", "RUF015", "E731", "B007",
243241
"UP031", "F401", "B023", "F811"]

requirements/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pytest>=8.2
22
pytest-asyncio>=0.24.0
3+
importlib_metadata>=7.0;python_version < "3.13"

uv.lock

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

0 commit comments

Comments
 (0)