Skip to content

Commit ed3ae41

Browse files
authored
PYTHON-3983 Clean up handling of PYTHON_BINARY (#1382)
1 parent 5565572 commit ed3ae41

File tree

6 files changed

+57
-60
lines changed

6 files changed

+57
-60
lines changed

.evergreen/config.yml

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,6 @@ functions:
7979
export PATH="$MONGODB_BINARIES:$PATH"
8080
export PROJECT="${project}"
8181
export PIP_QUIET=1
82-
ENSURE_TOOLCHAIN_PYTHON_BINARY: |
83-
# Make sure PYTHON_BINARY is set to a suitable toolchain python.
84-
if [ -z "$PYTHON_BINARY" ]; then
85-
if [ "$(uname -s)" = "Darwin" ]; then
86-
export PYTHON_BINARY=/Library/Frameworks/Python.Framework/Versions/3.9/bin/python3
87-
elif [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
88-
export PYTHON_BINARY=/cygdrive/c/python/Python39/python
89-
else
90-
export PYTHON_BINARY=/opt/python/3.9/bin/python3
91-
fi
92-
fi
9382
EOT
9483
9584
# Load the expansion file to make an evergreen variable with the current unique version
@@ -502,12 +491,8 @@ functions:
502491
export DB_PASSWORD="${DRIVERS_ATLAS_LAMBDA_PASSWORD}"
503492
fi
504493
505-
export PYTHON_BINARY=${PYTHON_BINARY}
506-
if [ -z "$PYTHON_BINARY" ]; then
507-
export PYTHON_BINARY=${python3_binary}
508-
fi
509-
510494
GREEN_FRAMEWORK=${GREEN_FRAMEWORK} \
495+
PYTHON_BINARY=${PYTHON_BINARY} \
511496
C_EXTENSIONS=${C_EXTENSIONS} \
512497
COVERAGE=${COVERAGE} \
513498
COMPRESSORS=${COMPRESSORS} \
@@ -678,7 +663,6 @@ functions:
678663
include_expansions_in_env: ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"]
679664
script: |
680665
${PREPARE_SHELL}
681-
${ENSURE_TOOLCHAIN_PYTHON_BINARY}
682666
bash .evergreen/run-mongodb-oidc-test.sh
683667
684668
"run aws auth test with aws credentials as environment variables":
@@ -1630,8 +1614,6 @@ tasks:
16301614
tags: ["no-server"]
16311615
commands:
16321616
- func: "run tests"
1633-
vars:
1634-
PYTHON_BINARY: /opt/python/3.7/bin/python3
16351617

16361618
- name: "atlas-connect"
16371619
tags: ["atlas-connect"]
@@ -2108,7 +2090,6 @@ tasks:
21082090
vars:
21092091
VERSION: "latest"
21102092
TOPOLOGY: "server"
2111-
PYTHON_BINARY: "/opt/mongodbtoolchain/v3/bin/python3"
21122093
- func: "run tests"
21132094
# }}}
21142095
- name: "coverage-report"
@@ -2260,7 +2241,6 @@ axes:
22602241
skip_EC2_auth_test: true
22612242
skip_ECS_auth_test: true
22622243
skip_web_identity_auth_test: true
2263-
python3_binary: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
22642244
libmongocrypt_url: https://s3.amazonaws.com/mciuploads/libmongocrypt/macos/master/latest/libmongocrypt.tar.gz
22652245
- id: macos-1100
22662246
display_name: "macOS 11.00"
@@ -2269,7 +2249,6 @@ axes:
22692249
skip_EC2_auth_test: true
22702250
skip_ECS_auth_test: true
22712251
skip_web_identity_auth_test: true
2272-
python3_binary: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
22732252
libmongocrypt_url: https://s3.amazonaws.com/mciuploads/libmongocrypt/macos/master/latest/libmongocrypt.tar.gz
22742253
- id: macos-1100-arm64
22752254
display_name: "macOS 11.00 Arm64"
@@ -2278,21 +2257,18 @@ axes:
22782257
skip_EC2_auth_test: true
22792258
skip_ECS_auth_test: true
22802259
skip_web_identity_auth_test: true
2281-
python3_binary: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
22822260
libmongocrypt_url: https://s3.amazonaws.com/mciuploads/libmongocrypt/macos/master/latest/libmongocrypt.tar.gz
22832261
- id: rhel7
22842262
display_name: "RHEL 7.x"
22852263
run_on: rhel79-small
22862264
batchtime: 10080 # 7 days
22872265
variables:
2288-
python3_binary: "/opt/python/3.8/bin/python3"
22892266
libmongocrypt_url: https://s3.amazonaws.com/mciuploads/libmongocrypt/rhel-70-64-bit/master/latest/libmongocrypt.tar.gz
22902267
- id: rhel8
22912268
display_name: "RHEL 8.x"
22922269
run_on: rhel87-small
22932270
batchtime: 10080 # 7 days
22942271
variables:
2295-
python3_binary: "/opt/python/3.8/bin/python3"
22962272
libmongocrypt_url: https://s3.amazonaws.com/mciuploads/libmongocrypt/rhel-80-64-bit/master/latest/libmongocrypt.tar.gz
22972273
- id: rhel80-fips
22982274
display_name: "RHEL 8.0 FIPS"
@@ -2304,14 +2280,10 @@ axes:
23042280
display_name: "Ubuntu 22.04"
23052281
run_on: ubuntu2204-small
23062282
batchtime: 10080 # 7 days
2307-
variables:
2308-
python3_binary: python3
23092283
- id: ubuntu-18.04
23102284
display_name: "Ubuntu 18.04"
23112285
run_on: ubuntu1804-small
23122286
batchtime: 10080 # 7 days
2313-
variables:
2314-
python3_binary: python3
23152287
- id: rhel83-zseries
23162288
display_name: "RHEL 8.3 (zSeries)"
23172289
run_on: rhel83-zseries-small
@@ -2334,7 +2306,6 @@ axes:
23342306
skip_ECS_auth_test: true
23352307
skip_EC2_auth_test: true
23362308
skip_web_identity_auth_test: true
2337-
python3_binary: "C:/python/Python38/python.exe"
23382309
venv_bin_dir: "Scripts"
23392310
libmongocrypt_url: https://s3.amazonaws.com/mciuploads/libmongocrypt/windows-test/master/latest/libmongocrypt.tar.gz
23402311

@@ -2476,14 +2447,6 @@ axes:
24762447
variables:
24772448
PYTHON_BINARY: "/opt/python/pypy3.10/bin/pypy3"
24782449

2479-
- id: python-version-mac
2480-
display_name: "Python"
2481-
values:
2482-
- id: "system-python3"
2483-
display_name: "Python3"
2484-
variables:
2485-
PYTHON_BINARY: "python3"
2486-
24872450
- id: python-version-windows
24882451
display_name: "Python"
24892452
values:
@@ -3166,7 +3129,6 @@ buildvariants:
31663129
- matrix_name: "aws-auth-test-mac"
31673130
matrix_spec:
31683131
platform: [macos-1014]
3169-
python-version-mac: ["system-python3"]
31703132
display_name: "MONGODB-AWS Auth ${platform} ${python-version-mac}"
31713133
tasks:
31723134
- name: "aws-auth-test-4.4"

.evergreen/run-mongodb-aws-test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ echo "Running MONGODB-AWS authentication tests"
1818
# ensure no secrets are printed in log files
1919
set +x
2020

21+
. ./.evergreen/utils.sh
22+
PYTHON_BINARY=$(find_python3)
23+
2124
# Try to source exported AWS Secrets
2225
if [ -f ./secrets-export.sh ]; then
2326
source ./secrets-export.sh

.evergreen/run-mongodb-oidc-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ fi
1313

1414
# Get the drivers secrets. Use an existing secrets file first.
1515
if [ ! -f "./secrets-export.sh" ]; then
16-
bash .evergreen/tox.sh -m aws-secrets -- drivers/oidc
16+
bash ${DRIVERS_TOOLS}/.evergreen/auth_aws/setup_secrets.sh drivers/oidc
1717
fi
1818
source ./secrets-export.sh
1919

2020
# # If the file did not have our creds, get them from the vault.
2121
if [ -z "$OIDC_ATLAS_URI_SINGLE" ]; then
22-
bash .evergreen/tox.sh -m aws-secrets -- drivers/oidc
22+
bash ${DRIVERS_TOOLS}/.evergreen/auth_aws/setup_secrets.sh drivers/oidc
2323
source ./secrets-export.sh
2424
fi
2525

.evergreen/tox.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
#!/bin/bash
22
set -o errexit # Exit the script with error if any of the commands fail
3+
set -x
34

45
. .evergreen/utils.sh
56

67
if [ -z "$PYTHON_BINARY" ]; then
7-
# Use Python 3 from the server toolchain to test on ARM, POWER or zSeries if a
8-
# system python3 doesn't exist or exists but is older than 3.7.
9-
if is_python_37 "$(command -v python3)"; then
10-
PYTHON_BINARY=$(command -v python3)
11-
elif is_python_37 "$(command -v /opt/mongodbtoolchain/v3/bin/python3)"; then
12-
PYTHON_BINARY=$(command -v /opt/mongodbtoolchain/v3/bin/python3)
13-
else
14-
echo "Cannot test without python3.7+ installed!"
15-
fi
8+
PYTHON_BINARY=$(find_python3)
169
fi
1710

1811
if $PYTHON_BINARY -m tox --version; then

.evergreen/utils.sh

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,59 @@
22

33
set -o xtrace
44

5+
find_python3() {
6+
PYTHON=""
7+
# Add a fallback system python3 if it is available and Python 3.7+.
8+
if is_python_37 "$(command -v python3)"; then
9+
PYTHON="$(command -v python3)"
10+
fi
11+
# Find a suitable toolchain version, if available.
12+
if [ "$(uname -s)" = "Darwin" ]; then
13+
# macos 11.00
14+
if [ -d "/Library/Frameworks/Python.Framework/Versions/3.10" ]; then
15+
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.10/bin/python3"
16+
# macos 10.14
17+
elif [ -d "/Library/Frameworks/Python.Framework/Versions/3.7" ]; then
18+
PYTHON="/Library/Frameworks/Python.Framework/Versions/3.7/bin/python3"
19+
fi
20+
elif [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
21+
PYTHON="C:/python/Python37/python.exe"
22+
else
23+
# Prefer our own toolchain, fall back to mongodb toolchain if it has Python 3.7+.
24+
if [ -f "/opt/python/3.7/bin/python3" ]; then
25+
PYTHON="/opt/python/3.7/bin/python3"
26+
elif is_python_37 "$(command -v /opt/mongodbtoolchain/v4/bin/python3)"; then
27+
PYTHON="/opt/mongodbtoolchain/v4/bin/python3"
28+
elif is_python_37 "$(command -v /opt/mongodbtoolchain/v3/bin/python3)"; then
29+
PYTHON="/opt/mongodbtoolchain/v3/bin/python3"
30+
fi
31+
fi
32+
if [ -z "$PYTHON" ]; then
33+
echo "Cannot test without python3.7+ installed!"
34+
exit 1
35+
fi
36+
echo "$PYTHON"
37+
}
38+
539
# Usage:
640
# createvirtualenv /path/to/python /output/path/for/venv
741
# * param1: Python binary to use for the virtualenv
842
# * param2: Path to the virtualenv to create
943
createvirtualenv () {
1044
PYTHON=$1
1145
VENVPATH=$2
12-
if $PYTHON -m virtualenv --version; then
46+
# Prefer venv
47+
VENV="$PYTHON -m venv"
48+
if [ "$(uname -s)" = "Darwin" ]; then
1349
VIRTUALENV="$PYTHON -m virtualenv"
14-
elif $PYTHON -m venv -h > /dev/null; then
15-
# System virtualenv might not be compatible with the python3 on our path
16-
VIRTUALENV="$PYTHON -m venv"
1750
else
18-
echo "Cannot test without virtualenv"
19-
exit 1
51+
VIRTUALENV=$(command -v virtualenv 2>/dev/null || echo "$PYTHON -m virtualenv")
52+
VIRTUALENV="$VIRTUALENV -p $PYTHON"
53+
fi
54+
if ! $VENV $VENVPATH 2>/dev/null; then
55+
# Workaround for bug in older versions of virtualenv.
56+
$VIRTUALENV $VENVPATH 2>/dev/null || $VIRTUALENV $VENVPATH
2057
fi
21-
# Workaround for bug in older versions of virtualenv.
22-
$VIRTUALENV $VENVPATH || $PYTHON -m venv $VENVPATH
2358
if [ "Windows_NT" = "$OS" ]; then
2459
# Workaround https://bugs.python.org/issue32451:
2560
# mongovenv/Scripts/activate: line 3: $'\r': command not found
@@ -31,7 +66,7 @@ createvirtualenv () {
3166

3267
export PIP_QUIET=1
3368
python -m pip install --upgrade pip
34-
python -m pip install --upgrade setuptools wheel tox
69+
python -m pip install --upgrade setuptools tox
3570
}
3671

3772
# Usage:

test/test_index_management.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ def setUpClass(cls) -> None:
6767
password = os.environ["DB_PASSWORD"]
6868
cls.client = MongoClient(url, username=username, password=password)
6969
cls.client.drop_database(_NAME)
70-
cls.addClassCleanup(cls.client.close)
7170
cls.db = cls.client.test_search_index_prose
7271

72+
@classmethod
73+
def tearDownClass(cls):
74+
cls.client.drop_database(_NAME)
75+
cls.client.close()
76+
7377
def wait_for_ready(self, coll, name=_NAME, predicate=None):
7478
"""Wait for a search index to be ready."""
7579
indices: list[Mapping[str, Any]] = []

0 commit comments

Comments
 (0)