Skip to content

Commit 227fcbf

Browse files
authored
Stop compiling Python using --with-system-expat (#1925)
The upstream Python test suite (which gets run when compiling with PGO enabled) fails with the `libexpat` in Ubuntu 22.04. In #1661, I previously added what I hoped would be a temporarily workaround until the failures were fixed upstream, however, the Python maintainers say they don't guarantee compatibility with distro `expat`, and that it's up to us to test for compatibility and patch if we want to use the distro version. However, this isn't viable given that we're neither a Linux distro maintainer, a CPython maintainer or an expat maintainer. Instead, like the upstream Docker Hub Python images (who were also affected by this issue), we will switch the `expat` bundled within the CPython sources, which is actually what the upstream CPython project tests in its CI. This means users won't get security updates for free via the base image, and will instead need to update their Python patch versions instead as newer versions are vendored in CPython. However, this is the least worst alternative for now. I'm doing this now, since otherwise I'll need to generate another patch series for the soon to be released Python 3.14. Note: This change only affects Python versions compiled/released after this merges. Existing Python versions on S3 are unaffected for now (unless they ever get recompiled in the future). For more details, see: python/cpython#125067 (comment) GUS-W-17414073.
1 parent 5f8ddb6 commit 227fcbf

4 files changed

Lines changed: 2 additions & 36 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- Stopped using `--with-system-expat` when compiling new Python versions. ([#1925](https://github.com/heroku/heroku-buildpack-python/pull/1925))
56

67
## [v312] - 2025-10-05
78

builds/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ RUN apt-get update --error-on=any \
1717
COPY --from=cosign /ko-app/cosign /usr/local/bin/cosign
1818

1919
WORKDIR /tmp
20-
COPY build_python_runtime.sh python-3.13-ubuntu-22.04-libexpat-workaround.patch .
20+
COPY build_python_runtime.sh .

builds/build_python_runtime.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ cosign verify-blob \
8383
tar --extract --file python.tgz --strip-components=1 --directory "${SRC_DIR}"
8484
cd "${SRC_DIR}"
8585

86-
# Work around PGO profile test failures with Python 3.13 on Ubuntu 22.04, due to the tests
87-
# checking the raw libexpat version which doesn't account for Ubuntu backports:
88-
# https://github.com/heroku/heroku-buildpack-python/pull/1661#issuecomment-2405259352
89-
# https://github.com/python/cpython/issues/125067
90-
if [[ "${PYTHON_MAJOR_VERSION}" == "3.13" && "${STACK}" == "heroku-22" ]]; then
91-
patch -p1 </tmp/python-3.13-ubuntu-22.04-libexpat-workaround.patch
92-
fi
93-
9486
# Aim to keep this roughly consistent with the options used in the Python Docker images,
9587
# for maximum compatibility / most battle-tested build configuration:
9688
# https://github.com/docker-library/python
@@ -110,9 +102,6 @@ CONFIGURE_OPTS=(
110102
# Skip running `ensurepip` as part of install, since the buildpack installs a curated
111103
# version of pip itself (which ensures it's consistent across Python patch releases).
112104
"--with-ensurepip=no"
113-
# Build the `pyexpat` module using the `expat` library in the base image (which will
114-
# automatically receive security updates), rather than CPython's vendored version.
115-
"--with-system-expat"
116105
)
117106

118107
if [[ "${PYTHON_MAJOR_VERSION}" != +(3.9) ]]; then

builds/python-3.13-ubuntu-22.04-libexpat-workaround.patch

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)