Skip to content

Commit 29d9b8c

Browse files
lsierantfealebenpae
authored andcommitted
Bump python to 3.13 (#4083)
# Summary This patch bumps python version we use **locally and in CI** from 3.9 to 3.13. No customer-facing changes here. Changes: - unified python version in `PYTHON_VERSION` env var defined in root-context - exception is for race variant where the distro used doesn't contain python 3.13 yet (3.12 is used) - new script: `scripts/dev/recreate_python_venv.sh` which removes and creates new, properly initialized python venv - this script is also used in evergreen so we always create venv in one way - simplified referencing of python venv in evergreen.yaml to one `python_venv` task and simplified usages so that the most tasks just references `setup_building_host` which also sets up venv - modified dev tooling installation script `scripts/dev/install.sh` to create venv as well (calls `recreate_python_venv.sh`) ## Proof of Work [EVG](https://spruce.mongodb.com/version/67a89e9412bd170007fb3be9/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC) is green (minus one task failing also on master) logged python version [on the evg host](https://parsley.mongodb.com/evergreen/ops_manager_kubernetes_e2e_mdb_kind_ubi_cloudqa_e2e_replica_set_config_map_patch_46f54a608a7ce7e973d45c63aceb0efbdaf26707_67a89e9412bd170007fb3be9_25_02_09_12_24_53/0/task?bookmarks=0%2C1481&selectedLineRange=L473&shareLine=473) ``` [2025/02/09 13:37:34.373] Current python path: /data/mci/ee887af178b064cce3f8cebe0b52bb31/src/github.com/10gen/ops-manager-kubernetes/venv/bin/python [2025/02/09 13:37:34.374] Python 3.13.2 ``` and logged version when we start the tests [in the e2e test pod](https://parsley.mongodb.com/evergreen/ops_manager_kubernetes_e2e_mdb_kind_ubi_cloudqa_e2e_replica_set_config_map_patch_46f54a608a7ce7e973d45c63aceb0efbdaf26707_67a89e9412bd170007fb3be9_25_02_09_12_24_53/0/task?bookmarks=0%2C1481&selectedLineRange=L1098&shareLine=1098): ``` [2025/02/09 13:39:32.922] platform linux -- Python 3.13.2, pytest-7.4.3, pluggy-1.5.0 -- /venv/bin/python3 ``` ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [ ] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you checked for release_note changes? ## Reminder (Please remove this when merging) - Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible - Our Short Guide for PRs: [Link](REDACTED) - Remember the following Communication Standards - use comment prefixes for clarity: * **blocking**: Must be addressed before approval. * **follow-up**: Can be addressed in a later PR or ticket. * **q**: Clarifying question. * **nit**: Non-blocking suggestions. * **note**: Side-note, non-actionable. Example: Praise * --> no prefix is considered a question
1 parent b2e3306 commit 29d9b8c

26 files changed

+141
-139
lines changed

.evergreen-functions.yml

Lines changed: 35 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
variables:
22
- &e2e_include_expansions_in_env
33
include_expansions_in_env:
4+
- ARTIFACTORY_PASSWORD
5+
- ARTIFACTORY_USERNAME
6+
- GRS_PASSWORD
7+
- GRS_USERNAME
8+
- OVERRIDE_VERSION_ID
9+
- PKCS11_URI
10+
- SILK_CLIENT_ID
11+
- SILK_CLIENT_SECRET
12+
- branch_name
13+
- build_id
14+
- build_variant
15+
- distro
16+
- e2e_cloud_qa_apikey_owner_ubi_cloudqa
17+
- e2e_cloud_qa_orgid_owner_ubi_cloudqa
18+
- e2e_cloud_qa_user_owner_ubi_cloudqa
419
- ecr_registry
520
- ecr_registry_needs_auth
6-
- openshift_url
7-
- openshift_token
8-
- workdir
21+
- execution
22+
- github_commit
23+
- image_name
24+
- include_tags
25+
- is_patch
926
- mms_eng_test_aws_access_key
10-
- mms_eng_test_aws_secret
1127
- mms_eng_test_aws_region
12-
- OVERRIDE_VERSION_ID
13-
- version_id
14-
- task_name
15-
- e2e_cloud_qa_user_owner_ubi_cloudqa
16-
- e2e_cloud_qa_apikey_owner_ubi_cloudqa
17-
- e2e_cloud_qa_orgid_owner_ubi_cloudqa
18-
- otel_trace_id
19-
- otel_parent_id
28+
- mms_eng_test_aws_secret
29+
- openshift_token
30+
- openshift_url
2031
- otel_collector_endpoint
21-
- branch_name
32+
- otel_parent_id
33+
- otel_trace_id
34+
- pin_tag_at
35+
- registry
2236
- requester
23-
- is_patch
24-
- github_commit
25-
- build_variant
26-
- execution
27-
- build_id
37+
- skip_tags
38+
- task_name
39+
- triggered_by_git_tag
40+
- version_id
41+
- workdir
2842

2943
functions:
3044

@@ -59,17 +73,11 @@ functions:
5973
echo "Finished switching context"
6074
6175
python_venv: &python_venv
62-
command: subprocess.exec
63-
type: setup
64-
params:
65-
command: /opt/python/3.9/bin/python3 -m venv --upgrade-deps ./venv
66-
67-
python_requirements: &python_requirements
6876
command: subprocess.exec
6977
type: setup
7078
params:
7179
working_dir: src/github.com/10gen/ops-manager-kubernetes
72-
command: scripts/evergreen/run_python.sh -m pip install -r requirements.txt --quiet --no-warn-script-location
80+
command: scripts/dev/recreate_python_venv.sh
7381

7482
"clone":
7583
- command: subprocess.exec
@@ -167,13 +175,6 @@ functions:
167175
add_to_path:
168176
- ${workdir}/bin
169177
binary: scripts/evergreen/setup_preflight.sh
170-
# The python binary is in a different location for RHEL machines so we can't use the same process
171-
# for creating the virtual environment.
172-
- command: subprocess.exec
173-
type: setup
174-
params:
175-
command: python3 -m venv --upgrade-deps ./venv
176-
- *python_requirements
177178

178179
setup_prepare_openshift_bundles:
179180
- command: subprocess.exec
@@ -227,8 +228,6 @@ functions:
227228
binary: scripts/dev/configure_docker_auth.sh
228229

229230
lint_repo:
230-
- *python_venv
231-
- *python_requirements
232231
- command: subprocess.exec
233232
type: setup
234233
params:
@@ -251,6 +250,7 @@ functions:
251250
- *setup_aws
252251
- *configure_docker_auth
253252
- *setup_docker_datadir
253+
- *python_venv
254254

255255
prune_docker_resources:
256256
- command: subprocess.exec
@@ -369,8 +369,6 @@ functions:
369369
command: scripts/evergreen/prepare_aws.sh
370370

371371
build-dockerfiles:
372-
- *python_venv
373-
- *python_requirements
374372
- command: subprocess.exec
375373
type: setup
376374
params:
@@ -470,8 +468,6 @@ functions:
470468
- ${workdir}
471469

472470
pipeline:
473-
- *python_venv
474-
- *python_requirements
475471
- *switch_context
476472
- command: shell.exec
477473
type: setup
@@ -487,32 +483,11 @@ functions:
487483
type: setup
488484
params:
489485
shell: bash
490-
include_expansions_in_env:
491-
- version_id
492-
- registry
493-
- image_name
494-
- skip_tags
495-
- include_tags
496-
- distro
497-
- is_patch
498-
- GRS_USERNAME
499-
- GRS_PASSWORD
500-
- PKCS11_URI
501-
- ARTIFACTORY_USERNAME
502-
- ARTIFACTORY_PASSWORD
503-
- triggered_by_git_tag
504-
- pin_tag_at
505-
- SILK_CLIENT_ID
506-
- SILK_CLIENT_SECRET
507-
- otel_trace_id
508-
- otel_parent_id
509-
- otel_collector_endpoint
486+
<<: *e2e_include_expansions_in_env
510487
working_dir: src/github.com/10gen/ops-manager-kubernetes
511488
binary: scripts/evergreen/run_python.sh pipeline.py --include ${image_name} --parallel --sign
512489

513490
teardown_cloud_qa_all:
514-
- *python_venv
515-
- *python_requirements
516491
- *switch_context
517492
- command: shell.exec
518493
type: setup
@@ -639,8 +614,6 @@ functions:
639614
files: [ "src/github.com/10gen/ops-manager-kubernetes/*.suite", "src/github.com/10gen/ops-manager-kubernetes/public/tools/multicluster/*.suite", "src/github.com/10gen/ops-manager-kubernetes/docker/mongodb-enterprise-init-ops-manager/mmsconfiguration/*.suite" ]
640615

641616
test_python_unit:
642-
- *python_venv
643-
- *python_requirements
644617
- command: shell.exec
645618
type: test
646619
params:
@@ -651,8 +624,6 @@ functions:
651624
make python-tests
652625
653626
test_sboms:
654-
- *python_venv
655-
- *python_requirements
656627
- command: shell.exec
657628
type: test
658629
params:
@@ -664,8 +635,6 @@ functions:
664635
665636
generate_perf_tests_tasks:
666637
- *switch_context
667-
- *python_venv
668-
- *python_requirements
669638
- command: shell.exec
670639
type: setup
671640
params:

.evergreen.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ task_groups:
539539
setup_group_can_fail_task: true
540540
setup_group:
541541
- func: clone
542+
- func: python_venv
542543
- func: download_kube_tools
543544
- func: setup_shellcheck
544545
tasks:

.githooks/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
set -Eeou pipefail
44

55
source scripts/dev/set_env_context.sh
6-
if [ -f "${workdir}"/venv/bin/activate ]; then
7-
source "${workdir}"/venv/bin/activate
6+
if [ -f "${PROJECT_DIR}"/venv/bin/activate ]; then
7+
source "${PROJECT_DIR}"/venv/bin/activate
88
fi
99

1010
if [[ -z "${EVERGREEN_MODE:-}" ]]; then

constraints.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

docker/mongodb-enterprise-tests/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#
77
# Ref: https://cryptography.io/en/latest/installation/#building-cryptography-on-linux
88
#
9-
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.9-slim as builder
9+
ARG PYTHON_VERSION
10+
11+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:${PYTHON_VERSION}-slim as builder
1012

1113

1214
RUN apt-get -qq update \
@@ -18,7 +20,7 @@ COPY requirements.txt requirements.txt
1820
RUN python3 -m venv /venv && . /venv/bin/activate && python3 -m pip install -r requirements.txt
1921

2022

21-
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.9-slim
23+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:${PYTHON_VERSION}-slim
2224

2325
RUN apt-get -qq update \
2426
&& apt-get -y -qq install \

docker/mongodb-enterprise-tests/README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,7 @@ have done this, you can proceed to complete the Python installation.
6767

6868
### Installing Python and Dependencies ###
6969

70-
You should have Python 3.6 installed, create a virtualenv and install
71-
the dependencies on the `requirements.txt` file. The following is an
72-
example on how to achieve this:
73-
74-
75-
* First time install only: Create a virtualenv
76-
``` bash
77-
python3.6 -m pip install venv --user
78-
python3.6 -m venv venv
79-
80-
source venv/bin/activate
81-
PIP_CONSTRAINT=constraints.txt python -m pip install -r requirements.txt
82-
```
70+
Run `scripts/dev/install.sh` or `scripts/dev/recreate_python_venv.sh` to install necessary tools and create python virtualenv.
8371

8472
* After the first run, when coming back to the project it should be
8573
required to `activate` your virtual environment once again.

inventories/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ images:
88
- name: build
99
task_type: docker_build
1010
dockerfile: Dockerfile
11+
buildargs:
12+
PYTHON_VERSION: $(inputs.params.python_version)
1113
output:
1214
- registry: $(inputs.params.registry)/mongodb-enterprise-tests
1315
tag: latest

pipeline.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
1818
from dataclasses import dataclass
1919
from datetime import datetime, timedelta
20-
from distutils.dir_util import copy_tree
2120
from queue import Queue
2221
from typing import Callable, Dict, Iterable, List, Optional, Set, Tuple, Union
2322

@@ -459,12 +458,18 @@ def build_tests_image(build_configuration: BuildConfiguration):
459458
shutil.rmtree(public_dest, ignore_errors=True)
460459

461460
# Copy directories and files (recursive copy)
462-
copy_tree(helm_src, helm_dest)
463-
copy_tree(public_src, public_dest)
461+
shutil.copytree(helm_src, helm_dest)
462+
shutil.copytree(public_src, public_dest)
464463
shutil.copyfile("release.json", "docker/mongodb-enterprise-tests/release.json")
465464
shutil.copyfile("requirements.txt", requirements_dest)
466465

467-
sonar_build_image(image_name, build_configuration, {}, "inventories/test.yaml")
466+
python_version = os.getenv("PYTHON_VERSION", "")
467+
if python_version == "":
468+
raise Exception("Missing PYTHON_VERSION environment variable")
469+
470+
buildargs = dict({"python_version": python_version})
471+
472+
sonar_build_image(image_name, build_configuration, buildargs, "inventories/test.yaml")
468473

469474

470475
def build_operator_image(build_configuration: BuildConfiguration):

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ kubernetes==17.17.0
1212
pymongo==4.6.3
1313
pytest==7.4.3
1414
pytest-asyncio==0.14.0
15-
PyYAML==5.4.1
15+
PyYAML==6.0.2
1616
urllib3==1.26.19
1717
cryptography==43.0.1
1818
python-dateutil==2.9.0
@@ -40,7 +40,7 @@ autopep8==1.5.7
4040
flake8-isort==4.0.0
4141
mypy==1.14.1
4242
types-freezegun==0.1.4
43-
types-PyYAML==5.4.3
43+
types-PyYAML==6.0.2
4444
types-pytz==2021.1.0
4545
types-python-dateutil==0.1.4
4646
pipupgrade==1.12.0

scripts/dev/contexts/e2e_operator_race_ubi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ export TEST_POD_CLUSTER=kind-e2e-cluster-1
1616
export test_pod_cluster=kind-e2e-cluster-1
1717
export ops_manager_version="cloud_qa"
1818
export BUILD_WITH_RACE_DETECTION=true
19+
20+
# there is no python 3.13 in ubuntu1804-xlarge
21+
export PYTHON_VERSION=3.12

0 commit comments

Comments
 (0)