Skip to content

Commit 209ce30

Browse files
IamXanderEvergreen Agent
authored and
Evergreen Agent
committed
SERVER-72262 Bump Python minimum version to 3.9/3.10
1 parent b5e3b9b commit 209ce30

File tree

24 files changed

+147
-69
lines changed

24 files changed

+147
-69
lines changed

.mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
python_version = 3.7
2+
python_version = 3.10
33

44
disallow_untyped_defs = False
55
# Do not error on imported files since all imported files may not be mypy clean.

SConstruct

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ import mongo.toolchain as mongo_toolchain
3838
import mongo.generators as mongo_generators
3939
import mongo.install_actions as install_actions
4040

41-
EnsurePythonVersion(3, 6)
41+
# TODO SERVER-79172
42+
# We cannot set the limit to python 3.10 since python 3.9 is needed for windows testing
43+
EnsurePythonVersion(3, 9)
4244
EnsureSConsVersion(3, 1, 1)
4345

4446
utc_starttime = datetime.utcnow()

buildscripts/ciconfig/evergreen.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from __future__ import annotations
77

88
import datetime
9-
import distutils.spawn
9+
import shutil
1010
import os
1111
import subprocess
12+
import structlog
1213
import sys
13-
import time
1414
from typing import Set, List, Optional
1515

1616
import yaml
@@ -20,20 +20,46 @@
2020
ENTERPRISE_MODULE_NAME = "enterprise"
2121
ASAN_SIGNATURE = "detect_leaks=1"
2222

23+
LOGGER = structlog.get_logger(__name__)
24+
2325

2426
def parse_evergreen_file(path, evergreen_binary="evergreen"):
2527
"""Read an Evergreen file and return EvergreenProjectConfig instance."""
2628
if evergreen_binary:
27-
if not distutils.spawn.find_executable(evergreen_binary):
29+
print(f"os.environ={os.environ}")
30+
if not shutil.which(evergreen_binary):
31+
# On windows in python3.8 there was an update to no longer use HOME in os.path.expanduser
32+
# However, cygwin is weird and has HOME but not USERPROFILE
33+
# So we just check if HOME is set and USERPROFILE is not
34+
# Then we just set USERPROFILE and unset it after
35+
# Bug is here: https://bugs.python.org/issue36264
36+
37+
prev_environ = os.environ.copy()
38+
if sys.platform in ("win32", "cygwin"):
39+
LOGGER.info(f"Previous os.environ={os.environ} before updating 'USERPROFILE'")
40+
if 'HOME' in os.environ:
41+
os.environ['USERPROFILE'] = os.environ['HOME']
42+
else:
43+
LOGGER.warn(
44+
"'HOME' enviorment variable unset. This will likely cause us to be unable to find evergreen binary."
45+
)
46+
2847
default_evergreen_location = os.path.expanduser(os.path.join("~", "evergreen"))
48+
49+
# Restore enviorment if it was modified above on windows
50+
os.environ.clear()
51+
os.environ.update(prev_environ)
52+
2953
if os.path.exists(default_evergreen_location):
3054
evergreen_binary = default_evergreen_location
3155
elif os.path.exists(f"{default_evergreen_location}.exe"):
3256
evergreen_binary = f"{default_evergreen_location}.exe"
3357
else:
3458
raise EnvironmentError(
35-
"Executable '{}' does not exist or is not in the PATH.".format(
36-
evergreen_binary))
59+
f"Executable {evergreen_binary} (default location: {default_evergreen_location}) does not exist or is not in the PATH. PATH={os.environ.get('PATH')}"
60+
)
61+
else:
62+
evergreen_binary = shutil.which(evergreen_binary)
3763

3864
# Call 'evergreen evaluate path' to pre-process the project configuration file.
3965
cmd = [evergreen_binary, "evaluate", path]

buildscripts/linter/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _find_linter(linter, config_dict):
8282
python_dir = os.path.dirname(sys.executable)
8383
if sys.platform == "win32":
8484
# On Windows, these scripts are installed in %PYTHONDIR%\scripts like
85-
# 'C:\Python37\scripts', and have .exe extensions.
85+
# 'C:\python\python310\scripts', and have .exe extensions.
8686
python_dir = os.path.join(python_dir, "scripts")
8787

8888
cmd_str = os.path.join(python_dir, linter.cmd_name)

buildscripts/resmokelib/utils/archival.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ def __init__(self, logger, archival_json_file="archive.json", limit_size_mb=0, l
126126
def _get_s3_client():
127127
# Since boto3 is a 3rd party module, we import locally.
128128
import boto3
129+
import botocore.session
130+
botocore.session.Session()
131+
132+
if sys.platform in ("win32", "cygwin"):
133+
# These overriden values can be found here
134+
# https://github.com/boto/botocore/blob/13468bc9d8923eccd0816ce2dd9cd8de5a6f6e0e/botocore/configprovider.py#L49C7-L49C7
135+
# This is due to the backwards breaking changed python introduced https://bugs.python.org/issue36264
136+
botocore_session = botocore.session.Session(
137+
session_vars={
138+
'config_file': (
139+
None,
140+
'AWS_CONFIG_FILE',
141+
os.path.join(os.environ['HOME'], '.aws', 'config'),
142+
None,
143+
),
144+
'credentials_file': (
145+
None,
146+
'AWS_SHARED_CREDENTIALS_FILE',
147+
os.path.join(os.environ['HOME'], '.aws', 'credentials'),
148+
None,
149+
),
150+
})
151+
boto3.setup_default_session(botocore_session=botocore_session)
129152
return boto3.client("s3")
130153

131154
def archive_files_to_s3(self, display_name, input_files, s3_bucket, s3_path):

buildscripts/tests/ciconfig/test_evergreen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ class TestEvergreenProjectConfig(unittest.TestCase):
1414

1515
@classmethod
1616
def setUpClass(cls):
17+
env = os.environ.copy()
1718
cls.conf = _evergreen.parse_evergreen_file(TEST_FILE_PATH, evergreen_binary=None)
1819

20+
# Assert there is no leakage of env variables from this function
21+
assert env == os.environ
22+
1923
def test_invalid_path(self):
2024
invalid_path = "non_existing_file"
2125
with self.assertRaises(IOError):

docs/building.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To build MongoDB, you will need:
1919
* `libcurl4-gnutls-dev`
2020
* On Ubuntu, the lzma library is required. Install `liblzma-dev`
2121
* On Amazon Linux, the xz-devel library is required. `yum install xz-devel`
22-
* Python 3.7.x and Pip modules:
22+
* Python 3.9.x and Pip modules:
2323
* See the section "Python Prerequisites" below.
2424
* About 13 GB of free disk space for the core binaries (`mongod`,
2525
`mongos`, and `mongo`) and about 600 GB for the install-all target.
@@ -43,7 +43,7 @@ The source for the tools is now available at
4343
Python Prerequisites
4444
---------------
4545

46-
In order to build MongoDB, Python 3.7+ is required, and several Python
46+
In order to build MongoDB, Python 3.9+ is required, and several Python
4747
modules must be installed. Python 3 is included in macOS 10.15 and later.
4848
For earlier macOS versions, Python 3 can be installed using Homebrew or
4949
MacPorts or similar.
@@ -131,7 +131,7 @@ Windows
131131

132132
Build requirements:
133133
* Visual Studio 2022 version 17.0 or newer
134-
* Python 3.7
134+
* Python 3.9
135135

136136
Or download a prebuilt binary for Windows at www.mongodb.org.
137137

docs/golden_data_test_framework.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ buildscripts/golden_test.py setup
180180
Run buildscripts/golden_test.py setup utility.
181181
You may be asked for a password, when not running in "Run as administrator" shell.
182182
```cmd
183-
c:\python\Python37\python.exe buildscripts/golden_test.py setup
183+
c:\python\python310\python.exe buildscripts/golden_test.py setup
184184
```
185185

186186
### Manual Setup (Default config)

etc/evergreen.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ variables:
168168
-j$(( $(grep -c ^processor /proc/cpuinfo) / 2 ))
169169
--win-version-min=win10
170170
num_scons_link_jobs_available: 0.5
171-
python: '/cygdrive/c/python/python37/python.exe'
171+
python: '/cygdrive/c/python/python39/python.exe'
172172
ext: zip
173173
scons_cache_scope: shared
174174
multiversion_platform: windows
@@ -551,7 +551,7 @@ buildvariants:
551551
-j$(bc <<< "$(grep -c '^processor' /proc/cpuinfo) / 1.8")
552552
MONGO_DISTMOD=windows
553553
num_scons_link_jobs_available: 0.2
554-
python: '/cygdrive/c/python/python37/python.exe'
554+
python: '/cygdrive/c/python/python39/python.exe'
555555
ext: zip
556556
scons_cache_scope: shared
557557
multiversion_platform: windows
@@ -631,7 +631,7 @@ buildvariants:
631631
burn_in_tests_build_variant: enterprise-windows-all-feature-flags-required
632632
exe: ".exe"
633633
content_type: application/zip
634-
python: '/cygdrive/c/python/python37/python.exe'
634+
python: '/cygdrive/c/python/python39/python.exe'
635635
ext: zip
636636
multiversion_platform: windows
637637
multiversion_edition: enterprise
@@ -684,7 +684,7 @@ buildvariants:
684684
burn_in_tests_build_variant: enterprise-windows-all-feature-flags-required
685685
exe: ".exe"
686686
content_type: application/zip
687-
python: '/cygdrive/c/python/python37/python.exe'
687+
python: '/cygdrive/c/python/python39/python.exe'
688688
ext: zip
689689
multiversion_platform: windows
690690
multiversion_edition: enterprise
@@ -773,7 +773,7 @@ buildvariants:
773773
-j$(bc <<< "$(grep -c '^processor' /proc/cpuinfo) / 1.5")
774774
--win-version-min=win10
775775
num_scons_link_jobs_available: 0.25
776-
python: '/cygdrive/c/python/python37/python.exe'
776+
python: '/cygdrive/c/python/python39/python.exe'
777777
ext: zip
778778
resmoke_jobs_max: 1
779779
scons_cache_scope: shared
@@ -1890,7 +1890,7 @@ buildvariants:
18901890
LIBPATH="c:/sasl/lib"
18911891
-j$(( $(grep -c ^processor /proc/cpuinfo) / 2 ))
18921892
--win-version-min=win10
1893-
python: '/cygdrive/c/python/python37/python.exe'
1893+
python: '/cygdrive/c/python/python39/python.exe'
18941894
tasks:
18951895
- name: build_metrics_gen_TG
18961896

@@ -2908,7 +2908,7 @@ buildvariants:
29082908
- windows-vsCurrent-small
29092909
stepback: false
29102910
expansions:
2911-
python: '/cygdrive/c/python/python37/python.exe'
2911+
python: '/cygdrive/c/python/python39/python.exe'
29122912
tasks:
29132913
- name: win_shared_scons_cache_pruning
29142914

@@ -2975,7 +2975,7 @@ buildvariants:
29752975
LIBPATH="c:/sasl/lib"
29762976
-j$(( $(grep -c ^processor /proc/cpuinfo) / 2 ))
29772977
--win-version-min=win10
2978-
python: '/cygdrive/c/python/python37/python.exe'
2978+
python: '/cygdrive/c/python/python39/python.exe'
29792979
ext: zip
29802980
has_packages: false
29812981
scons_cache_scope: shared

etc/evergreen_yml_components/variants/compile_static_analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ buildvariants:
205205
-j$(bc <<< "$(grep -c '^processor' /proc/cpuinfo) / 1.8")
206206
--win-version-min=win10
207207
num_scons_link_jobs_available: 0.2
208-
python: '/cygdrive/c/python/python37/python.exe'
208+
python: '/cygdrive/c/python/python39/python.exe'
209209
scons_cache_scope: shared
210210
compile_variant: *windows-compile-required
211211
tasks:

etc/evergreen_yml_components/variants/in_memory.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ buildvariants:
9595
LIBPATH="c:/sasl/lib" -j$(bc <<< "$(grep -c '^processor' /proc/cpuinfo) / 1.5")
9696
--win-version-min=win10
9797
num_scons_link_jobs_available: 0.25
98-
python: '/cygdrive/c/python/python37/python.exe'
98+
python: '/cygdrive/c/python/python39/python.exe'
9999
test_flags: >-
100100
--storageEngine=inMemory
101101
--excludeWithAnyTags=requires_persistence,requires_journaling,incompatible_with_windows_tls

etc/evergreen_yml_components/variants/misc_release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,7 @@ buildvariants:
25142514
--win-version-min=win10
25152515
--use-diagnostic-latches=off
25162516
num_scons_link_jobs_available: 0.25
2517-
python: '/cygdrive/c/python/python37/python.exe'
2517+
python: '/cygdrive/c/python/python39/python.exe'
25182518
ext: zip
25192519
scons_cache_scope: shared
25202520
large_distro_name: windows-vsCurrent-large
@@ -2580,7 +2580,7 @@ buildvariants:
25802580
--win-version-min=win10
25812581
--use-diagnostic-latches=off
25822582
num_scons_link_jobs_available: 0.25
2583-
python: '/cygdrive/c/python/python37/python.exe'
2583+
python: '/cygdrive/c/python/python39/python.exe'
25842584
ext: zip
25852585
scons_cache_scope: shared
25862586
multiversion_platform: windows

etc/pip/components/external_auth.req

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# These are the dependencies of ldaptor
2-
passlib == 1.7.1
2+
passlib == 1.7.4
33
pyOpenSSL == 19.0.0; platform_machine == "s390x" or platform_machine == "ppc64le" # Needed for pinned cryptography package - see SERVER-70845
44
pyOpenSSL == 22.0.0; platform_machine != "s390x" and platform_machine != "ppc64le"
55
pyparsing == 2.4.0

evergreen/prelude_python.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if [ "Windows_NT" = "$OS" ]; then
2-
python='/cygdrive/c/python/python37/python.exe'
2+
python='/cygdrive/c/python/python39/python.exe'
33
else
44
if [ -f /opt/mongodbtoolchain/v4/bin/python3 ]; then
55
python="/opt/mongodbtoolchain/v4/bin/python3"

jstests/free_mon/libs/free_mon.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Control the Free Monitoring Mock Webserver.
44
*/
55

6+
load("jstests/libs/python.js");
7+
68
// These faults must match the list of faults in mock_http_server.py, see the
79
// SUPPORTED_FAULT_TYPES list in mock_http_server.py
810
const FAULT_FAIL_REGISTER = "fail_register";
@@ -23,14 +25,10 @@ class FreeMonWebServer {
2325
* @param {bool} disableFaultsOnStartup optionally disable fault on startup
2426
*/
2527
constructor(fault_type, disableFaultsOnStartup) {
26-
this.python = "python3";
28+
this.python = getPython3Binary();
2729
this.disableFaultsOnStartup = disableFaultsOnStartup || false;
2830
this.fault_type = fault_type;
2931

30-
if (_isWindows()) {
31-
this.python = "python.exe";
32-
}
33-
3432
print("Using python interpreter: " + this.python);
3533
this.web_server_py = "jstests/free_mon/libs/mock_http_server.py";
3634
this.control_py = "jstests/free_mon/libs/mock_http_control.py";

jstests/libs/python.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,41 @@
33
function getPython3Binary() {
44
'use strict';
55

6-
let cmd = '/opt/mongodbtoolchain/v4/bin/python3';
7-
if (_isWindows()) {
8-
const paths = ["c:/python36/python.exe", "c:/python/python36/python.exe"];
9-
for (let p of paths) {
10-
if (fileExists(p)) {
11-
cmd = p;
12-
break;
13-
}
14-
}
6+
// On windows it is important to use python vs python3
7+
// or else we will pick up a python that is not in our venv
8+
clearRawMongoProgramOutput();
9+
assert.eq(runNonMongoProgram("python", "--version"), 0);
10+
const pythonVersion = rawMongoProgramOutput(); // Will look like "Python 3.10.4\n"
11+
const usingPython39 = /Python 3\.9/.exec(pythonVersion);
12+
const usingPython310 = /Python 3\.10/.exec(pythonVersion);
13+
if (usingPython310) {
14+
print(
15+
"Found python 3.10 by default. Likely this is because we are using a virtual enviorment.");
16+
return "python";
17+
} else if (usingPython39) {
18+
// TODO: SERVER-79172
19+
// Once the above ticket is complete we should stop using python 3.9 on windows and upgrade
20+
// to python 310 everywhere To solve: grep for python39 and fix instances of it
21+
print(
22+
"Found python 3.9 by default. Likely this is because we are using a windows virtual enviorment.");
23+
return "python";
1524
}
1625

17-
if (fileExists(cmd)) {
18-
return cmd;
26+
const paths = [
27+
"/opt/mongodbtoolchain/v4/bin/python3",
28+
"/cygdrive/c/python/python310/python.exe",
29+
"c:/python/python310/python.exe"
30+
];
31+
for (let p of paths) {
32+
if (fileExists(p)) {
33+
print("Found python3 in default location " + p);
34+
return p;
35+
}
1936
}
2037

21-
clearRawMongoProgramOutput();
22-
assert.eq(runNonMongoProgram("python", "--version"), 0);
23-
const pythonVersion = rawMongoProgramOutput();
2438
assert(/Python 3/.exec(pythonVersion));
2539

26-
return "python";
40+
// We are probs running on mac
41+
print("Did not find python3 in a virtualenv or default location");
42+
return "python3";
2743
}

jstests/noPassthrough/libs/backup_restore.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* }
2020
*/
2121

22+
load("jstests/libs/python.js");
23+
2224
var BackupRestoreTest = function(options) {
2325
"use strict";
2426

@@ -123,7 +125,8 @@ var BackupRestoreTest = function(options) {
123125
function _fsmClient(host) {
124126
// Launch FSM client
125127
const suite = 'concurrency_replication_for_backup_restore';
126-
const resmokeCmd = 'python buildscripts/resmoke.py run --shuffle --continueOnFailure' +
128+
const resmokeCmd = getPython3Binary() +
129+
' buildscripts/resmoke.py run --shuffle --continueOnFailure' +
127130
' --repeat=99999 --internalParam=is_inner_level --mongo=' +
128131
MongoRunner.getMongoShellPath() + ' --shellConnString=mongodb://' + host +
129132
' --suites=' + suite;

0 commit comments

Comments
 (0)