PYTHON-3968 Allow pymongo to be installed in tox when C extension fails to build (#1409)

This commit is contained in:
Shane Harvey 2023-10-27 18:06:19 -07:00 committed by GitHub
parent 58a36e9838
commit 7bb9a73b2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -68,7 +68,7 @@ https://pymongo.readthedocs.io/en/stable/installation.html#osx
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 @@ https://pymongo.readthedocs.io/en/stable/installation.html#osx
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 @@ ext_modules = [
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(

View File

@ -48,9 +48,11 @@ labels = # Use labels and -m instead of -e so that tox -m <label> fails instantl
description = run base set of unit tests with no extra functionality
extras =
test
allowlist_externals =
.evergreen/check-c-extensions.sh
commands =
python --version
python setup.py build_ext -i
.evergreen/check-c-extensions.sh
pytest -v --durations=5 --maxfail=10 {posargs}
[testenv:test-eg]