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 c8f0f712d6..a711e246bf 100644 --- a/setup.py +++ b/setup.py @@ -68,7 +68,7 @@ def run(self): try: build_ext.run(self) except Exception: - if "TOX_ENV_NAME" in os.environ: + if os.environ.get("PYMONGO_C_EXT_MUST_BUILD"): raise e = sys.exc_info()[1] sys.stdout.write("%s\n" % str(e)) @@ -86,7 +86,7 @@ def build_extension(self, ext): try: build_ext.build_extension(self, ext) except Exception: - if "TOX_ENV_NAME" in os.environ: + if os.environ.get("PYMONGO_C_EXT_MUST_BUILD"): raise e = sys.exc_info()[1] sys.stdout.write("%s\n" % str(e)) @@ -120,7 +120,10 @@ def build_extension(self, ext): if "--no_ext" in sys.argv or os.environ.get("NO_EXT"): - sys.argv.remove("--no_ext") + try: + sys.argv.remove("--no_ext") + except ValueError: + pass 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