From 07fe79686e9b2028974b07d99d7d9c4faf1b3c02 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Fri, 27 Oct 2023 13:13:49 -0700 Subject: [PATCH 1/3] PYTHON-3968 Revert "PYTHON-3760 Add C extension building as part of tox test environment (#1255)" This reverts commit 2a4dc9cb0c0e3ed93ff2002f696690dab6e64dfa. --- setup.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/setup.py b/setup.py index c8f0f712d6..17d2995676 100644 --- a/setup.py +++ b/setup.py @@ -68,8 +68,6 @@ def run(self): try: build_ext.run(self) except Exception: - if "TOX_ENV_NAME" in os.environ: - raise e = sys.exc_info()[1] sys.stdout.write("%s\n" % str(e)) warnings.warn( @@ -86,8 +84,6 @@ def build_extension(self, ext): try: build_ext.build_extension(self, ext) except Exception: - if "TOX_ENV_NAME" in os.environ: - raise e = sys.exc_info()[1] sys.stdout.write("%s\n" % str(e)) warnings.warn( From d8c29d17e89d3e984d721ada2c4d7004a85b22a4 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Fri, 27 Oct 2023 14:21:51 -0700 Subject: [PATCH 2/3] PYTHON-3968 Allow pymongo to be installed in tox when C extension fails to build --- .evergreen/check-c-extensions.sh | 11 +++++++++++ .evergreen/run-perf-tests.sh | 1 - .evergreen/run-tests.sh | 9 ++------- setup.py | 8 +++++++- tox.ini | 4 +++- 5 files changed, 23 insertions(+), 10 deletions(-) create mode 100755 .evergreen/check-c-extensions.sh diff --git a/.evergreen/check-c-extensions.sh b/.evergreen/check-c-extensions.sh new file mode 100755 index 0000000000..cb51ceed4a --- /dev/null +++ b/.evergreen/check-c-extensions.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -o errexit # Exit the script with error if any of the commands fail + +# Supported/used environment variables: +# C_EXTENSIONS Pass --no_ext to skip installing the C extensions. + +PYTHON_IMPL=$(python -c "import platform; print(platform.python_implementation())") +if [ -z "$C_EXTENSIONS" ] && [ "$PYTHON_IMPL" = "CPython" ]; then + PYMONGO_C_EXT_MUST_BUILD=1 python setup.py build_ext -i + python tools/fail_if_no_c.py +fi diff --git a/.evergreen/run-perf-tests.sh b/.evergreen/run-perf-tests.sh index 91d4b72a7f..72be38e03d 100644 --- a/.evergreen/run-perf-tests.sh +++ b/.evergreen/run-perf-tests.sh @@ -14,7 +14,6 @@ export TEST_PATH="${PROJECT_DIRECTORY}/driver-performance-test-data" export OUTPUT_FILE="${PROJECT_DIRECTORY}/results.json" export PYTHON_BINARY=/opt/mongodbtoolchain/v3/bin/python3 -export C_EXTENSIONS=1 export PERF_TEST=1 bash ./.evergreen/tox.sh -m test-eg diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 444608efa7..8a31a96a3c 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -8,7 +8,7 @@ set -o xtrace # AUTH Set to enable authentication. Defaults to "noauth" # SSL Set to enable SSL. Defaults to "nossl" # GREEN_FRAMEWORK The green framework to test with, if any. -# C_EXTENSIONS If non-empty, c extensions are enabled. +# C_EXTENSIONS Pass --no_ext to skip installing the C extensions. # COVERAGE If non-empty, run the test suite with coverage. # COMPRESSORS If non-empty, install appropriate compressor. # LIBMONGOCRYPT_URL The URL to download libmongocrypt. @@ -272,12 +272,7 @@ fi PIP_QUIET=0 python -m pip list if [ -z "$GREEN_FRAMEWORK" ]; then - if [ -z "$C_EXTENSIONS" ] && [ "$PYTHON_IMPL" = "CPython" ]; then - python setup.py build_ext -i - # This will set a non-zero exit status if either import fails, - # causing this script to exit. - python -c "from bson import _cbson; from pymongo import _cmessage" - fi + .evergreen/check-c-extensions.sh python -m pytest -v --durations=5 --maxfail=10 $TEST_ARGS else python green_framework_test.py $GREEN_FRAMEWORK -v $TEST_ARGS diff --git a/setup.py b/setup.py index 17d2995676..45e2f03ec0 100644 --- a/setup.py +++ b/setup.py @@ -68,6 +68,8 @@ def run(self): try: build_ext.run(self) except Exception: + if os.environ.get("PYMONGO_C_EXT_MUST_BUILD"): + raise e = sys.exc_info()[1] sys.stdout.write("%s\n" % str(e)) warnings.warn( @@ -84,6 +86,8 @@ def build_extension(self, ext): try: build_ext.build_extension(self, ext) except Exception: + if os.environ.get("PYMONGO_C_EXT_MUST_BUILD"): + raise e = sys.exc_info()[1] sys.stdout.write("%s\n" % str(e)) warnings.warn( @@ -115,9 +119,11 @@ def build_extension(self, ext): ] -if "--no_ext" in sys.argv or os.environ.get("NO_EXT"): +if "--no_ext" in sys.argv: sys.argv.remove("--no_ext") ext_modules = [] +if os.environ.get("NO_EXT"): + ext_modules = [] elif sys.platform.startswith("java") or sys.platform == "cli" or "PyPy" in sys.version: sys.stdout.write( """ diff --git a/tox.ini b/tox.ini index 9fb2400d36..d54449fe85 100644 --- a/tox.ini +++ b/tox.ini @@ -48,9 +48,11 @@ labels = # Use labels and -m instead of -e so that tox -m