From aa8322e1ce6225b150410985b76d2e0bacf14000 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Wed, 17 Apr 2024 15:50:15 -0700 Subject: [PATCH 1/2] PYTHON-2048 Add test case for better error behavior (#1606) --- test/mockupdb/test_standalone_shard.py | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test/mockupdb/test_standalone_shard.py diff --git a/test/mockupdb/test_standalone_shard.py b/test/mockupdb/test_standalone_shard.py new file mode 100644 index 000000000..8d388cf74 --- /dev/null +++ b/test/mockupdb/test_standalone_shard.py @@ -0,0 +1,57 @@ +# Copyright 2024-present MongoDB, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Test errors that come from a standalone shard.""" +from __future__ import annotations + +import unittest + +from mockupdb import MockupDB, going + +from pymongo import MongoClient +from pymongo.errors import OperationFailure + + +class TestStandaloneShard(unittest.TestCase): + # See PYTHON-2048 and SERVER-44591. + def test_bulk_txn_error_message(self): + server = MockupDB(auto_ismaster={"maxWireVersion": 8}) + server.run() + self.addCleanup(server.stop) + client = MongoClient(server.uri) + self.addCleanup(client.close) + + with self.assertRaisesRegex( + OperationFailure, "This MongoDB deployment does not support retryable writes" + ): + with going(client.db.collection.insert_many, [{}, {}]): + request = server.receives() + request.reply( + { + "n": 0, + "ok": 1.0, + "writeErrors": [ + { + "code": 20, + "codeName": "IllegalOperation", + "errmsg": "Transaction numbers are only allowed on a replica set member or mongos", + "index": 0, + } + ], + } + ) + + +if __name__ == "__main__": + unittest.main() From a421c662e60095591432a57f43b7e441d6f314ed Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 17 Apr 2024 17:58:35 -0500 Subject: [PATCH 2/2] PYTHON-4373 Use requirements files for deps (#1605) --- .readthedocs.yaml | 2 +- MANIFEST.in | 3 +- requirements.txt | 1 + requirements/aws.txt | 1 + .../docs.txt | 0 requirements/encryption.txt | 3 ++ requirements/gssapi.txt | 2 + requirements/ocsp.txt | 12 +++++ requirements/snappy.txt | 1 + requirements/test.txt | 1 + requirements/zstd.txt | 1 + setup.py | 45 ++++++------------- tox.ini | 2 +- 13 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 requirements.txt create mode 100644 requirements/aws.txt rename doc/docs-requirements.txt => requirements/docs.txt (100%) create mode 100644 requirements/encryption.txt create mode 100644 requirements/gssapi.txt create mode 100644 requirements/ocsp.txt create mode 100644 requirements/snappy.txt create mode 100644 requirements/test.txt create mode 100644 requirements/zstd.txt diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 39c86fff0..a3693074f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -16,7 +16,7 @@ python: # Install pymongo itself. - method: pip path: . - - requirements: doc/docs-requirements.txt + - requirements: requirements/docs.txt build: os: ubuntu-22.04 diff --git a/MANIFEST.in b/MANIFEST.in index b74a716df..bca389a74 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,6 +2,7 @@ include README.md include LICENSE include THIRD-PARTY-NOTICES include *.ini +include requirements.txt exclude .coveragerc exclude .git-blame-ignore-revs exclude .pre-commit-config.yaml @@ -16,9 +17,9 @@ recursive-include doc *.js recursive-include doc *.png include doc/Makefile include doc/_templates/layout.html -include doc/docs-requirements.txt include doc/make.bat include doc/static/periodic-executor-refs.dot +recursive-include requirements *.txt recursive-include tools *.py include tools/README.rst include green_framework_test.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..bdc0d7edc --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +dnspython>=1.16.0,<3.0.0 diff --git a/requirements/aws.txt b/requirements/aws.txt new file mode 100644 index 000000000..06e30c11c --- /dev/null +++ b/requirements/aws.txt @@ -0,0 +1 @@ +pymongo-auth-aws>=1.1.0,<2.0.0 diff --git a/doc/docs-requirements.txt b/requirements/docs.txt similarity index 100% rename from doc/docs-requirements.txt rename to requirements/docs.txt diff --git a/requirements/encryption.txt b/requirements/encryption.txt new file mode 100644 index 000000000..bae6115eb --- /dev/null +++ b/requirements/encryption.txt @@ -0,0 +1,3 @@ +pymongo-auth-aws>=1.1.0,<2.0.0 +pymongocrypt>=1.6.0,<2.0.0 +certifi;os.name=='nt' or sys_platform=='darwin' diff --git a/requirements/gssapi.txt b/requirements/gssapi.txt new file mode 100644 index 000000000..7f156b9ce --- /dev/null +++ b/requirements/gssapi.txt @@ -0,0 +1,2 @@ +pykerberos;os.name!='nt' +winkerberos>=0.5.0;os.name=='nt' diff --git a/requirements/ocsp.txt b/requirements/ocsp.txt new file mode 100644 index 000000000..6570b0905 --- /dev/null +++ b/requirements/ocsp.txt @@ -0,0 +1,12 @@ +# PyOpenSSL 17.0.0 introduced support for OCSP. 17.1.0 introduced +# a related feature we need. 17.2.0 fixes a bug +# in set_default_verify_paths we should really avoid. +# service_identity 18.1.0 introduced support for IP addr matching. +# Fallback to certifi on Windows if we can't load CA certs from the system +# store and just use certifi on macOS. +# https://www.pyopenssl.org/en/stable/api/ssl.html#OpenSSL.SSL.Context.set_default_verify_paths +certifi;os.name=='nt' or sys_platform=='darwin' +pyopenssl>=17.2.0 +requests<3.0.0 +cryptography>=2.5 +service_identity>=18.1.0 diff --git a/requirements/snappy.txt b/requirements/snappy.txt new file mode 100644 index 000000000..9bb71204b --- /dev/null +++ b/requirements/snappy.txt @@ -0,0 +1 @@ +python-snappy diff --git a/requirements/test.txt b/requirements/test.txt new file mode 100644 index 000000000..91e898f3c --- /dev/null +++ b/requirements/test.txt @@ -0,0 +1 @@ +pytest>=7 diff --git a/requirements/zstd.txt b/requirements/zstd.txt new file mode 100644 index 000000000..864700d2b --- /dev/null +++ b/requirements/zstd.txt @@ -0,0 +1 @@ +zstandard diff --git a/setup.py b/setup.py index b4f78fd72..599ea0e4a 100644 --- a/setup.py +++ b/setup.py @@ -137,43 +137,26 @@ by this python implementation.\n ext_modules = [] -dependencies = [ - "dnspython>=1.16.0,<3.0.0", -] +def parse_reqs_file(fname): + with open(fname) as fid: + lines = [li.strip() for li in fid.readlines()] + return [li for li in lines if li and not li.startswith("#")] + + +dependencies = parse_reqs_file("requirements.txt") extras_require = dict( - aws=[ - "pymongo-auth-aws>=1.1.0,<2.0.0", - ], - encryption=[ - "pymongo[aws]", - "pymongocrypt>=1.6.0,<2.0.0", - "certifi;os.name=='nt' or sys_platform=='darwin'", - ], - gssapi=["pykerberos;os.name!='nt'", "winkerberos>=0.5.0;os.name=='nt'"], - # PyOpenSSL 17.0.0 introduced support for OCSP. 17.1.0 introduced - # a related feature we need. 17.2.0 fixes a bug - # in set_default_verify_paths we should really avoid. - # service_identity 18.1.0 introduced support for IP addr matching. - # Fallback to certifi on Windows if we can't load CA certs from the system - # store and just use certifi on macOS. - # https://www.pyopenssl.org/en/stable/api/ssl.html#OpenSSL.SSL.Context.set_default_verify_paths - ocsp=[ - "certifi;os.name=='nt' or sys_platform=='darwin'", - "pyopenssl>=17.2.0", - "requests<3.0.0", - "cryptography>=2.5", - "service_identity>=18.1.0", - ], - snappy=["python-snappy"], + aws=parse_reqs_file("requirements/aws.txt"), + encryption=parse_reqs_file("requirements/encryption.txt"), + gssapi=parse_reqs_file("requirements/gssapi.txt"), + ocsp=parse_reqs_file("requirements/ocsp.txt"), + snappy=parse_reqs_file("requirements/snappy.txt"), # PYTHON-3423 Removed in 4.3 but kept here to avoid pip warnings. srv=[], tls=[], # PYTHON-2133 Removed in 4.0 but kept here to avoid pip warnings. - zstd=[ - "zstandard", - ], - test=["pytest>=7"], + zstd=parse_reqs_file("requirements/zstd.txt"), + test=parse_reqs_file("requirements/test.txt"), ) setup( diff --git a/tox.ini b/tox.ini index d41102012..eb9ae204e 100644 --- a/tox.ini +++ b/tox.ini @@ -144,7 +144,7 @@ commands = [testenv:doc] description = build sphinx docs deps = - -rdoc/docs-requirements.txt + -rrequirements/docs.txt commands = sphinx-build -W -b html doc ./doc/_build/html