Skip to content

Commit

Permalink
[Backport 7.58.x] Bump Python 3 to 3.12 (#18212) (#18706)
Browse files Browse the repository at this point in the history
* Bump Python 3 to 3.12 (#18212)

* bump py version to 3.12

* update dbm dev container

* update builders and build deps

* fix python string

* Build lxml dependencies for linux x64 (#18467)

* fix rmq version

* fix gunicorn tests

* Fix lock file generation

* comment out if clause to force dep resolution

* bump python to 3.12.6

* fix python on Windows sha

* remove DD_PYTHON2 unbound variable

* fix hatch errors

* remove setup.py files

* fix CI

* revert datadog_checks_test_helper

---------

Co-authored-by: Alex Lopez <[email protected]>
Co-authored-by: Ilia Kurenkov <[email protected]>
Co-authored-by: Alex Lopez <[email protected]>
(cherry picked from commit 69cffd9)

* fix build-deps.yaml

* Fix dependency build for macOS (#18581)

* Add workflow file to cache key on macos job

* Remove reference to DD_PYTHON2 which is no longer set

* Trigger the build in master when the workflow file changes

* remove changelog entries

---------

Co-authored-by: Alex Lopez <[email protected]>
  • Loading branch information
Kyle-Neale and alopezz authored Sep 30, 2024
1 parent 57f418f commit 4796d58
Show file tree
Hide file tree
Showing 414 changed files with 695 additions and 611 deletions.
4 changes: 2 additions & 2 deletions .builders/images/linux-aarch64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ RUN yum install -y perl-IPC-Cmd perl-CPANPLUS && \
ldconfig

# Compile and install Python 3
ENV PYTHON3_VERSION=3.11.8
ENV PYTHON3_VERSION=3.12.6
RUN yum install -y libffi-devel && \
DOWNLOAD_URL="https://python.org/ftp/python/{{version}}/Python-{{version}}.tgz" \
VERSION="${PYTHON3_VERSION}" \
SHA256="d3019a613b9e8761d260d9ebe3bd4df63976de30464e5c0189566e1ae3f61889" \
SHA256="85a4c1be906d20e5c5a69f2466b00da769c221d6a684acfd3a514dbf5bf10a66" \
RELATIVE_PATH="Python-{{version}}" \
bash install-from-source.sh \
--prefix=/opt/python/${PYTHON_VERSION} \
Expand Down
34 changes: 32 additions & 2 deletions .builders/images/linux-x86_64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ RUN yum install -y perl-IPC-Cmd perl-CPANPLUS && \
ldconfig

# Compile and install Python 3
ENV PYTHON3_VERSION=3.11.8
ENV PYTHON3_VERSION=3.12.6
RUN yum install -y libffi-devel && \
DOWNLOAD_URL="https://python.org/ftp/python/{{version}}/Python-{{version}}.tgz" \
VERSION="${PYTHON3_VERSION}" \
SHA256="d3019a613b9e8761d260d9ebe3bd4df63976de30464e5c0189566e1ae3f61889" \
SHA256="85a4c1be906d20e5c5a69f2466b00da769c221d6a684acfd3a514dbf5bf10a66" \
RELATIVE_PATH="Python-{{version}}" \
bash install-from-source.sh --prefix=/opt/python/${PYTHON_VERSION} --with-ensurepip=yes --enable-ipv6 --with-dbmliborder=
ENV PATH="/opt/python/${PYTHON_VERSION}/bin:${PATH}"
Expand All @@ -82,6 +82,36 @@ RUN \
RELATIVE_PATH="krb5-{{version}}/src" \
bash install-from-source.sh --without-keyutils --without-system-verto --without-libedit --disable-static

# libxml & libxslt for lxml
RUN \
DOWNLOAD_URL="https://download.gnome.org/sources/libxml2/2.12/libxml2-{{version}}.tar.xz" \
VERSION="2.12.6" \
SHA256="889c593a881a3db5fdd96cc9318c87df34eb648edfc458272ad46fd607353fbb" \
RELATIVE_PATH="libxml2-{{version}}" \
bash install-from-source.sh \
--without-iconv \
--without-python \
--without-icu \
--without-debug \
--without-mem-debug \
--without-run-debug \
--without-legacy \
--without-catalog \
--without-docbook \
--disable-static

RUN \
DOWNLOAD_URL="https://download.gnome.org/sources/libxslt/1.1/libxslt-{{version}}.tar.xz" \
VERSION="1.1.39" \
SHA256="2a20ad621148339b0759c4d4e96719362dee64c9a096dbba625ba053846349f0" \
RELATIVE_PATH="libxslt-{{version}}" \
bash install-from-source.sh \
--without-python \
--without-crypto \
--without-profiler \
--without-debugger \
--disable-static

# libpq and pg_config as needed by psycopg2
RUN \
DOWNLOAD_URL="https://ftp.postgresql.org/pub/source/v{{version}}/postgresql-{{version}}.tar.bz2" \
Expand Down
4 changes: 0 additions & 4 deletions .builders/images/macos-x86_64/builder_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ set -euxo pipefail
"${DD_PYTHON3}" -m pip install --no-warn-script-location virtualenv
"${DD_PYTHON3}" -m virtualenv py3

"${DD_PYTHON2}" -m pip install --no-warn-script-location --upgrade pip
"${DD_PYTHON2}" -m pip install --no-warn-script-location virtualenv
"${DD_PYTHON2}" -m virtualenv py2

# Install always with our own prefix path
mkdir -p "${DD_PREFIX_PATH}"
cp "${DD_MOUNT_DIR}/build_context/install-from-source.sh" .
Expand Down
12 changes: 6 additions & 6 deletions .builders/images/windows-x86_64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ RUN Get-RemoteFile `
Approve-File -Path $($Env:USERPROFILE + '\.cargo\bin\rustc.exe') -Hash $Env:RUSTC_HASH

# Install Python 3
ENV PYTHON_VERSION="3.11.7"
ENV PYTHON_VERSION="3.12.6"
RUN Get-RemoteFile `
-Uri https://www.python.org/ftp/python/$Env:PYTHON_VERSION/python-$Env:PYTHON_VERSION-amd64.exe `
-Path python-$Env:PYTHON_VERSION-amd64.exe `
-Hash 'c117c6444494bbe4cc937e8a5a61899d53f7f5c5bc573c5d130304e457d54024'; `
-Hash '5914748e6580e70bedeb7c537a0832b3071de9e09a2e4e7e3d28060616045e0a'; `
Start-Process -Wait python-$Env:PYTHON_VERSION-amd64.exe -ArgumentList '/quiet', 'InstallAllUsers=1'; `
Remove-Item python-$Env:PYTHON_VERSION-amd64.exe; `
& 'C:\Program Files\Python311\python.exe' -m pip install --no-warn-script-location --upgrade pip; `
& 'C:\Program Files\Python311\python.exe' -m pip install --no-warn-script-location virtualenv; `
& 'C:\Program Files\Python311\python.exe' -m virtualenv 'C:\py3'; `
Add-ToPath -Append 'C:\Program Files\Python311'
& 'C:\Program Files\Python312\python.exe' -m pip install --no-warn-script-location --upgrade pip; `
& 'C:\Program Files\Python312\python.exe' -m pip install --no-warn-script-location virtualenv; `
& 'C:\Program Files\Python312\python.exe' -m virtualenv 'C:\py3'; `
Add-ToPath -Append 'C:\Program Files\Python312'

# Install Python 2
ENV PYTHON_VERSION="2.7.18"
Expand Down
25 changes: 21 additions & 4 deletions .builders/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def default_python_version() -> str:
return match.group(1)


@cache
def target_python_for_major(python_major: str):
return '2.7' if python_major == '2' else default_python_version()


def is_compatible_wheel(
target_name: str,
target_python_major: str,
Expand All @@ -44,7 +49,7 @@ def is_compatible_wheel(
platform: str,
) -> bool:
if interpreter.startswith('cp'):
target_python = '2.7' if target_python_major == '2' else default_python_version()
target_python = target_python_for_major(target_python_major)
expected_tag = f'cp{target_python_major}' if abi == 'abi3' else f'cp{target_python}'.replace('.', '')
if expected_tag not in interpreter:
return False
Expand All @@ -59,8 +64,17 @@ def is_compatible_wheel(
return True


def generate_lock_file(requirements_file: Path, lock_file: Path) -> None:
target, _, python_version = lock_file.stem.rpartition('_')
def generate_lock_file(
requirements_file: Path,
lock_file_folder: Path,
target: str,
python_version: str,
) -> None:
python_target = target_python_for_major(python_version)
# The lockfiles contain the major.minor Python version
# so that the Agent can transition safely
lock_file = lock_file_folder / f'{target}_{python_target}.txt'

python_major = python_version[-1]

dependencies: dict[str, str] = {}
Expand Down Expand Up @@ -135,7 +149,10 @@ def main():
for python_version in target.iterdir():
if python_version.name.startswith('py'):
generate_lock_file(
python_version / 'frozen.txt', LOCK_FILE_DIR / f'{target.name}_{python_version.name}.txt'
python_version / 'frozen.txt',
LOCK_FILE_DIR,
target.name,
python_version.name.strip('py'),
)

if (image_digest_file := target / 'image_digest').is_file():
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This dockerfile is used to build the devcontainer environment.
# more info about vscode devcontainer: https://code.visualstudio.com/docs/devcontainers/containers
FROM mcr.microsoft.com/devcontainers/python:1-3.11-bullseye
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bullseye
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y liblz4-dev libunwind-dev ca-certificates curl gnupg
# Docker and docker-compose installation
RUN install -m 0755 -d /etc/apt/keyrings
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/dbm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This dockerfile is used to build the devcontainer environment.
# more info about vscode devcontainer: https://code.visualstudio.com/docs/devcontainers/containers
FROM mcr.microsoft.com/devcontainers/python:1-3.11-bullseye
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bullseye
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y liblz4-dev libunwind-dev ca-certificates curl gnupg
# Docker and docker-compose installation
RUN install -m 0755 -d /etc/apt/keyrings
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/dbm/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"privileged": true,
"features": {
"ghcr.io/devcontainers/features/python:1": {
"version": "3.11"
"version": "3.12"
}
},
"customizations": {
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// When updating it, modify both the base Dockerfile and the devcontainer.json reference.
// Ref: https://github.com/devcontainers/features/blob/562305d37b97d47331d96306ffc2a0a3cce55e64/src/python/install.sh#L10
"ghcr.io/devcontainers/features/python:1": {
"version": "3.11"
"version": "3.12"
}
},

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-ddev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defaults:

env:
APP_NAME: ddev
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
PYOXIDIZER_VERSION: "0.24.0"

jobs:
Expand Down
24 changes: 7 additions & 17 deletions .github/workflows/build-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- master
- 7.*.*
paths:
- .github/workflows/build-deps.yml
- .builders/**
- agent_requirements.in

Expand All @@ -28,7 +29,7 @@ defaults:

env:
PYTHONUNBUFFERED: "1"
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
DIRECT_DEPENDENCY_FILE: agent_requirements.in
# https://reproducible-builds.org/specs/source-date-epoch/
SOURCE_DATE_EPOCH: "1580601600"
Expand Down Expand Up @@ -108,7 +109,7 @@ jobs:
if: matrix.job.image == 'linux-aarch64'
run: |
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-py311_24.1.2-0-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh
wget https://repo.anaconda.com/miniconda/Miniconda3-py312_24.5.0-0-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
~/miniconda3/bin/conda init bash
Expand Down Expand Up @@ -145,7 +146,6 @@ jobs:
if: steps.changed-files.outputs.builders_any_changed == 'true' && matrix.job.image == 'linux-aarch64'
run: |-
sudo /home/runner/miniconda3/bin/python .builders/build.py ${{ matrix.job.image }} --python 3 ${{ env.OUT_DIR }}/py3
sudo /home/runner/miniconda3/bin/python .builders/build.py ${{ matrix.job.image }} --python 2 ${{ env.OUT_DIR }}/py2
# Give ownership of the output back to the user
sudo chown ${USER} ${{ env.OUT_DIR }}
Expand All @@ -154,20 +154,17 @@ jobs:
run: |-
digest=$(jq -r '.["${{ matrix.job.image }}"]' .deps/image_digests.json)
sudo /home/runner/miniconda3/bin/python .builders/build.py ${{ matrix.job.image }} --python 3 ${{ env.OUT_DIR }}/py3 --digest $digest
sudo /home/runner/miniconda3/bin/python .builders/build.py ${{ matrix.job.image }} --python 2 ${{ env.OUT_DIR }}/py2 --digest $digest
- name: Build image and wheels
if: steps.changed-files.outputs.builders_any_changed == 'true' && matrix.job.image != 'linux-aarch64'
run: |-
python .builders/build.py ${{ matrix.job.image }} --python 3 ${{ env.OUT_DIR }}/py3
python .builders/build.py ${{ matrix.job.image }} --python 2 ${{ env.OUT_DIR }}/py2
- name: Pull image and build wheels
if: steps.changed-files.outputs.builders_any_changed != 'true' && matrix.job.image != 'linux-aarch64'
run: |-
digest=$(jq -r '.["${{ matrix.job.image }}"]' .deps/image_digests.json)
python .builders/build.py ${{ matrix.job.image }} --python 3 ${{ env.OUT_DIR }}/py3 --digest $digest
python .builders/build.py ${{ matrix.job.image }} --python 2 ${{ env.OUT_DIR }}/py2 --digest $digest
- name: Change permissions
if: matrix.job.image == 'linux-aarch64'
Expand Down Expand Up @@ -204,8 +201,7 @@ jobs:
env:
TARGET_NAME: macos-x86_64
OUT_DIR: output/macos-x86_64
DD_PYTHON3: "/Library/Frameworks/Python.framework/Versions/3.11/bin/python"
DD_PYTHON2: "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"
DD_PYTHON3: "/Library/Frameworks/Python.framework/Versions/3.12/bin/python"

steps:
- name: Set up environment
Expand All @@ -218,15 +214,11 @@ jobs:
- name: Set up Python
env:
# Despite the name, this is built for the macOS 11 SDK on arm64 and 10.9+ on intel
PYTHON3_DOWNLOAD_URL: "https://www.python.org/ftp/python/3.11.5/python-3.11.5-macos11.pkg"
PYTHON2_DOWNLOAD_URL: "https://www.python.org/ftp/python/2.7.18/python-2.7.18-macosx10.9.pkg"
PYTHON3_DOWNLOAD_URL: "https://www.python.org/ftp/python/3.12.6/python-3.12.6-macos11.pkg"
run: |-
curl "$PYTHON3_DOWNLOAD_URL" -o python3.pkg
sudo installer -pkg python3.pkg -target /
curl "$PYTHON2_DOWNLOAD_URL" -o python2.pkg
sudo installer -pkg python2.pkg -target /
- name: Checkout code
uses: actions/checkout@v4

Expand All @@ -241,7 +233,7 @@ jobs:
with:
path: |
~/builder_root
key: macos-deps-builder-root-cache-${{ hashFiles('./.builders/images/macos/*', './.builders/images/*', './.builders/deps/*', './.builders/build.py') }}
key: macos-deps-builder-root-cache-${{ hashFiles('./.builders/images/macos/*', './.builders/images/*', './.builders/deps/*', './.builders/build.py', './.github/workflows/build-deps.yml') }}

- name: Run the build
env:
Expand All @@ -256,8 +248,6 @@ jobs:
mkdir ~/builder_root
${DD_PYTHON3} .builders/build.py ${{ env.TARGET_NAME }} --builder-root ~/builder_root --python 3 ${{ env.OUT_DIR }}/py3
fi
# At this point we can always skip builder setup since it's equivalent for python versions
${DD_PYTHON3} .builders/build.py ${{ env.TARGET_NAME }} --builder-root ~/builder_root --python 2 ${{ env.OUT_DIR }}/py2 --skip-setup
- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -342,4 +332,4 @@ jobs:
### Additional Notes
This PR was automatically generated by the following workflow:
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
2 changes: 1 addition & 1 deletion .github/workflows/cache-shared-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
os: [ubuntu-22.04, windows-2022]

env:
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compute-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defaults:
shell: bash

env:
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
MATRIX_SCRIPT: "ddev/src/ddev/utils/scripts/ci_matrix.py"

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'
cache: 'pip'

- name: Upgrade Python packaging tools
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-quick-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defaults:
shell: bash

env:
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
CHECK_SCRIPT: "ddev/src/ddev/utils/scripts/check_pr.py"

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'

- name: Upgrade Python packaging tools
run: pip install --disable-pip-version-check --upgrade pip setuptools wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'

- name: Upgrade Python packaging tools
run: pip install --disable-pip-version-check --upgrade pip setuptools wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-hash-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'

- id: files
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
runs-on: ubuntu-22.04

env:
PYTHON_VERSION: "3.11"
PYTHON_VERSION: "3.12"
TARGET: ${{ github.event_name == 'pull_request' && 'changed' || '' }}

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ jobs:

env:
FORCE_COLOR: "1"
PYTHON_VERSION: "${{ inputs.python-version || '3.11' }}"
PYTHON_FILTER: "${{ (inputs.test-py2 && !inputs.test-py3) && '2.7' || (!inputs.test-py2 && inputs.test-py3) && (inputs.python-version || '3.11') || '' }}"
PYTHON_VERSION: "${{ inputs.python-version || '3.12' }}"
PYTHON_FILTER: "${{ (inputs.test-py2 && !inputs.test-py3) && '2.7' || (!inputs.test-py2 && inputs.test-py3) && (inputs.python-version || '3.12') || '' }}"
SKIP_ENV_NAME: "${{ (inputs.test-py2 && !inputs.test-py3) && 'py3.*' || (!inputs.test-py2 && inputs.test-py3) && 'py2.*' || '' }}"
# Windows E2E requires Windows containers
DDEV_E2E_AGENT: "${{ inputs.platform == 'windows' && (inputs.agent-image-windows || 'datadog/agent-dev:master-py3-win-servercore') || inputs.agent-image }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-agent-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: 3.12
- name: Install ddev from local folder
run: |-
pip install -e ./datadog_checks_dev[cli]
Expand Down
Loading

0 comments on commit 4796d58

Please sign in to comment.