Skip to content

Commit

Permalink
SERVER-72262 Bump Python minimum version to 3.9/3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
IamXander authored and Evergreen Agent committed Aug 2, 2023
1 parent b5e3b9b commit 209ce30
Show file tree
Hide file tree
Showing 24 changed files with 147 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.7
python_version = 3.10

disallow_untyped_defs = False
# Do not error on imported files since all imported files may not be mypy clean.
Expand Down
4 changes: 3 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import mongo.toolchain as mongo_toolchain
import mongo.generators as mongo_generators
import mongo.install_actions as install_actions

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

utc_starttime = datetime.utcnow()
Expand Down
36 changes: 31 additions & 5 deletions buildscripts/ciconfig/evergreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from __future__ import annotations

import datetime
import distutils.spawn
import shutil
import os
import subprocess
import structlog
import sys
import time
from typing import Set, List, Optional

import yaml
Expand All @@ -20,20 +20,46 @@
ENTERPRISE_MODULE_NAME = "enterprise"
ASAN_SIGNATURE = "detect_leaks=1"

LOGGER = structlog.get_logger(__name__)


def parse_evergreen_file(path, evergreen_binary="evergreen"):
"""Read an Evergreen file and return EvergreenProjectConfig instance."""
if evergreen_binary:
if not distutils.spawn.find_executable(evergreen_binary):
print(f"os.environ={os.environ}")
if not shutil.which(evergreen_binary):
# On windows in python3.8 there was an update to no longer use HOME in os.path.expanduser
# However, cygwin is weird and has HOME but not USERPROFILE
# So we just check if HOME is set and USERPROFILE is not
# Then we just set USERPROFILE and unset it after
# Bug is here: https://bugs.python.org/issue36264

prev_environ = os.environ.copy()
if sys.platform in ("win32", "cygwin"):
LOGGER.info(f"Previous os.environ={os.environ} before updating 'USERPROFILE'")
if 'HOME' in os.environ:
os.environ['USERPROFILE'] = os.environ['HOME']
else:
LOGGER.warn(
"'HOME' enviorment variable unset. This will likely cause us to be unable to find evergreen binary."
)

default_evergreen_location = os.path.expanduser(os.path.join("~", "evergreen"))

# Restore enviorment if it was modified above on windows
os.environ.clear()
os.environ.update(prev_environ)

if os.path.exists(default_evergreen_location):
evergreen_binary = default_evergreen_location
elif os.path.exists(f"{default_evergreen_location}.exe"):
evergreen_binary = f"{default_evergreen_location}.exe"
else:
raise EnvironmentError(
"Executable '{}' does not exist or is not in the PATH.".format(
evergreen_binary))
f"Executable {evergreen_binary} (default location: {default_evergreen_location}) does not exist or is not in the PATH. PATH={os.environ.get('PATH')}"
)
else:
evergreen_binary = shutil.which(evergreen_binary)

# Call 'evergreen evaluate path' to pre-process the project configuration file.
cmd = [evergreen_binary, "evaluate", path]
Expand Down
2 changes: 1 addition & 1 deletion buildscripts/linter/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _find_linter(linter, config_dict):
python_dir = os.path.dirname(sys.executable)
if sys.platform == "win32":
# On Windows, these scripts are installed in %PYTHONDIR%\scripts like
# 'C:\Python37\scripts', and have .exe extensions.
# 'C:\python\python310\scripts', and have .exe extensions.
python_dir = os.path.join(python_dir, "scripts")

cmd_str = os.path.join(python_dir, linter.cmd_name)
Expand Down
23 changes: 23 additions & 0 deletions buildscripts/resmokelib/utils/archival.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ def __init__(self, logger, archival_json_file="archive.json", limit_size_mb=0, l
def _get_s3_client():
# Since boto3 is a 3rd party module, we import locally.
import boto3
import botocore.session
botocore.session.Session()

if sys.platform in ("win32", "cygwin"):
# These overriden values can be found here
# https://github.com/boto/botocore/blob/13468bc9d8923eccd0816ce2dd9cd8de5a6f6e0e/botocore/configprovider.py#L49C7-L49C7
# This is due to the backwards breaking changed python introduced https://bugs.python.org/issue36264
botocore_session = botocore.session.Session(
session_vars={
'config_file': (
None,
'AWS_CONFIG_FILE',
os.path.join(os.environ['HOME'], '.aws', 'config'),
None,
),
'credentials_file': (
None,
'AWS_SHARED_CREDENTIALS_FILE',
os.path.join(os.environ['HOME'], '.aws', 'credentials'),
None,
),
})
boto3.setup_default_session(botocore_session=botocore_session)
return boto3.client("s3")

def archive_files_to_s3(self, display_name, input_files, s3_bucket, s3_path):
Expand Down
4 changes: 4 additions & 0 deletions buildscripts/tests/ciconfig/test_evergreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ class TestEvergreenProjectConfig(unittest.TestCase):

@classmethod
def setUpClass(cls):
env = os.environ.copy()
cls.conf = _evergreen.parse_evergreen_file(TEST_FILE_PATH, evergreen_binary=None)

# Assert there is no leakage of env variables from this function
assert env == os.environ

def test_invalid_path(self):
invalid_path = "non_existing_file"
with self.assertRaises(IOError):
Expand Down
6 changes: 3 additions & 3 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To build MongoDB, you will need:
* `libcurl4-gnutls-dev`
* On Ubuntu, the lzma library is required. Install `liblzma-dev`
* On Amazon Linux, the xz-devel library is required. `yum install xz-devel`
* Python 3.7.x and Pip modules:
* Python 3.9.x and Pip modules:
* See the section "Python Prerequisites" below.
* About 13 GB of free disk space for the core binaries (`mongod`,
`mongos`, and `mongo`) and about 600 GB for the install-all target.
Expand All @@ -43,7 +43,7 @@ The source for the tools is now available at
Python Prerequisites
---------------

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

Build requirements:
* Visual Studio 2022 version 17.0 or newer
* Python 3.7
* Python 3.9

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

Expand Down
2 changes: 1 addition & 1 deletion docs/golden_data_test_framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ buildscripts/golden_test.py setup
Run buildscripts/golden_test.py setup utility.
You may be asked for a password, when not running in "Run as administrator" shell.
```cmd
c:\python\Python37\python.exe buildscripts/golden_test.py setup
c:\python\python310\python.exe buildscripts/golden_test.py setup
```

### Manual Setup (Default config)
Expand Down
16 changes: 8 additions & 8 deletions etc/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ variables:
-j$(( $(grep -c ^processor /proc/cpuinfo) / 2 ))
--win-version-min=win10
num_scons_link_jobs_available: 0.5
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
ext: zip
scons_cache_scope: shared
multiversion_platform: windows
Expand Down Expand Up @@ -551,7 +551,7 @@ buildvariants:
-j$(bc <<< "$(grep -c '^processor' /proc/cpuinfo) / 1.8")
MONGO_DISTMOD=windows
num_scons_link_jobs_available: 0.2
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
ext: zip
scons_cache_scope: shared
multiversion_platform: windows
Expand Down Expand Up @@ -631,7 +631,7 @@ buildvariants:
burn_in_tests_build_variant: enterprise-windows-all-feature-flags-required
exe: ".exe"
content_type: application/zip
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
ext: zip
multiversion_platform: windows
multiversion_edition: enterprise
Expand Down Expand Up @@ -684,7 +684,7 @@ buildvariants:
burn_in_tests_build_variant: enterprise-windows-all-feature-flags-required
exe: ".exe"
content_type: application/zip
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
ext: zip
multiversion_platform: windows
multiversion_edition: enterprise
Expand Down Expand Up @@ -773,7 +773,7 @@ buildvariants:
-j$(bc <<< "$(grep -c '^processor' /proc/cpuinfo) / 1.5")
--win-version-min=win10
num_scons_link_jobs_available: 0.25
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
ext: zip
resmoke_jobs_max: 1
scons_cache_scope: shared
Expand Down Expand Up @@ -1890,7 +1890,7 @@ buildvariants:
LIBPATH="c:/sasl/lib"
-j$(( $(grep -c ^processor /proc/cpuinfo) / 2 ))
--win-version-min=win10
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
tasks:
- name: build_metrics_gen_TG

Expand Down Expand Up @@ -2908,7 +2908,7 @@ buildvariants:
- windows-vsCurrent-small
stepback: false
expansions:
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
tasks:
- name: win_shared_scons_cache_pruning

Expand Down Expand Up @@ -2975,7 +2975,7 @@ buildvariants:
LIBPATH="c:/sasl/lib"
-j$(( $(grep -c ^processor /proc/cpuinfo) / 2 ))
--win-version-min=win10
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
ext: zip
has_packages: false
scons_cache_scope: shared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ buildvariants:
-j$(bc <<< "$(grep -c '^processor' /proc/cpuinfo) / 1.8")
--win-version-min=win10
num_scons_link_jobs_available: 0.2
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
scons_cache_scope: shared
compile_variant: *windows-compile-required
tasks:
Expand Down
2 changes: 1 addition & 1 deletion etc/evergreen_yml_components/variants/in_memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ buildvariants:
LIBPATH="c:/sasl/lib" -j$(bc <<< "$(grep -c '^processor' /proc/cpuinfo) / 1.5")
--win-version-min=win10
num_scons_link_jobs_available: 0.25
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
test_flags: >-
--storageEngine=inMemory
--excludeWithAnyTags=requires_persistence,requires_journaling,incompatible_with_windows_tls
Expand Down
4 changes: 2 additions & 2 deletions etc/evergreen_yml_components/variants/misc_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ buildvariants:
--win-version-min=win10
--use-diagnostic-latches=off
num_scons_link_jobs_available: 0.25
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
ext: zip
scons_cache_scope: shared
large_distro_name: windows-vsCurrent-large
Expand Down Expand Up @@ -2580,7 +2580,7 @@ buildvariants:
--win-version-min=win10
--use-diagnostic-latches=off
num_scons_link_jobs_available: 0.25
python: '/cygdrive/c/python/python37/python.exe'
python: '/cygdrive/c/python/python39/python.exe'
ext: zip
scons_cache_scope: shared
multiversion_platform: windows
Expand Down
2 changes: 1 addition & 1 deletion etc/pip/components/external_auth.req
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# These are the dependencies of ldaptor
passlib == 1.7.1
passlib == 1.7.4
pyOpenSSL == 19.0.0; platform_machine == "s390x" or platform_machine == "ppc64le" # Needed for pinned cryptography package - see SERVER-70845
pyOpenSSL == 22.0.0; platform_machine != "s390x" and platform_machine != "ppc64le"
pyparsing == 2.4.0
Expand Down
2 changes: 1 addition & 1 deletion evergreen/prelude_python.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if [ "Windows_NT" = "$OS" ]; then
python='/cygdrive/c/python/python37/python.exe'
python='/cygdrive/c/python/python39/python.exe'
else
if [ -f /opt/mongodbtoolchain/v4/bin/python3 ]; then
python="/opt/mongodbtoolchain/v4/bin/python3"
Expand Down
8 changes: 3 additions & 5 deletions jstests/free_mon/libs/free_mon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Control the Free Monitoring Mock Webserver.
*/

load("jstests/libs/python.js");

// These faults must match the list of faults in mock_http_server.py, see the
// SUPPORTED_FAULT_TYPES list in mock_http_server.py
const FAULT_FAIL_REGISTER = "fail_register";
Expand All @@ -23,14 +25,10 @@ class FreeMonWebServer {
* @param {bool} disableFaultsOnStartup optionally disable fault on startup
*/
constructor(fault_type, disableFaultsOnStartup) {
this.python = "python3";
this.python = getPython3Binary();
this.disableFaultsOnStartup = disableFaultsOnStartup || false;
this.fault_type = fault_type;

if (_isWindows()) {
this.python = "python.exe";
}

print("Using python interpreter: " + this.python);
this.web_server_py = "jstests/free_mon/libs/mock_http_server.py";
this.control_py = "jstests/free_mon/libs/mock_http_control.py";
Expand Down
46 changes: 31 additions & 15 deletions jstests/libs/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,41 @@
function getPython3Binary() {
'use strict';

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

if (fileExists(cmd)) {
return cmd;
const paths = [
"/opt/mongodbtoolchain/v4/bin/python3",
"/cygdrive/c/python/python310/python.exe",
"c:/python/python310/python.exe"
];
for (let p of paths) {
if (fileExists(p)) {
print("Found python3 in default location " + p);
return p;
}
}

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

return "python";
// We are probs running on mac
print("Did not find python3 in a virtualenv or default location");
return "python3";
}
5 changes: 4 additions & 1 deletion jstests/noPassthrough/libs/backup_restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* }
*/

load("jstests/libs/python.js");

var BackupRestoreTest = function(options) {
"use strict";

Expand Down Expand Up @@ -123,7 +125,8 @@ var BackupRestoreTest = function(options) {
function _fsmClient(host) {
// Launch FSM client
const suite = 'concurrency_replication_for_backup_restore';
const resmokeCmd = 'python buildscripts/resmoke.py run --shuffle --continueOnFailure' +
const resmokeCmd = getPython3Binary() +
' buildscripts/resmoke.py run --shuffle --continueOnFailure' +
' --repeat=99999 --internalParam=is_inner_level --mongo=' +
MongoRunner.getMongoShellPath() + ' --shellConnString=mongodb://' + host +
' --suites=' + suite;
Expand Down
Loading

0 comments on commit 209ce30

Please sign in to comment.