Skip to content

Commit

Permalink
Add Python 3.13 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ulgens committed Oct 27, 2024
1 parent 23b9ec4 commit 1f651a0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
27 changes: 24 additions & 3 deletions python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This list must match the versions specified in
# python/lib/dependabot/python/language_version_manager.rb: PRE_INSTALLED_PYTHON_VERSIONS
ARG PY_3_13=3.13.0
ARG PY_3_12=3.12.5
ARG PY_3_11=3.11.9
ARG PY_3_10=3.10.15
Expand All @@ -8,6 +9,7 @@ ARG PY_3_8=3.8.20
ARG PYENV_VERSION=v2.4.16

FROM ghcr.io/dependabot/dependabot-updater-core as python-core
ARG PY_3_13
ARG PY_3_12
ARG PY_3_11
ARG PY_3_10
Expand Down Expand Up @@ -120,6 +122,24 @@ RUN find $PYTHON_INSTALL_LOCATION/bin -type f -exec sed -i "1s|^#!/usr/local/bin
# Ensure pyenv works and it's the python version we expect
RUN PYENV_VERSION=$PY_3_12 pyenv exec python --version | grep "Python $PY_3_12" || exit 1
RUN bash /opt/python/helpers/build $PY_3_12
# This python environment occupies ~0.5 GB and gets used for a fraction of jobs, so store it compressed.
RUN cd $PYENV_ROOT/versions \
&& tar -acf $PY_3_12.tar.zst $PY_3_12

## 3.13
# Docker doesn't support parametrizing `COPY --from:python:$PY_1_23-bookworm`, so work around it using an alias.
# TODO: If upstream adds support for Ubuntu, use that instead of Debian as the base suffix: https://github.com/docker-library/python/pull/791
FROM docker.io/library/python:$PY_3_13-bookworm as upstream-python-3.13
FROM python-core as python-3.13
ARG PYTHON_INSTALL_LOCATION="$PYENV_ROOT/versions/$PY_3_13"
COPY --from=upstream-python-3.13 --chown=dependabot:dependabot /usr/local/bin $PYTHON_INSTALL_LOCATION/bin
COPY --from=upstream-python-3.13 --chown=dependabot:dependabot /usr/local/include $PYTHON_INSTALL_LOCATION/include
COPY --from=upstream-python-3.13 --chown=dependabot:dependabot /usr/local/lib $PYTHON_INSTALL_LOCATION/lib
# `pip` and other scripts need their shebangs rewritten for the new location
RUN find $PYTHON_INSTALL_LOCATION/bin -type f -exec sed -i "1s|^#!/usr/local/bin/python|#!${PYTHON_INSTALL_LOCATION}/bin/python|" {} +
# Ensure pyenv works and it's the python version we expect
RUN PYENV_VERSION=$PY_3_13 pyenv exec python --version | grep "Python $PY_3_13" || exit 1
RUN bash /opt/python/helpers/build $PY_3_13
# This is the default Python, so no need to tar it

FROM python-core
Expand Down Expand Up @@ -152,9 +172,10 @@ COPY --from=python-3.8 $PYENV_ROOT/versions/$PY_3_8.tar.zst $PYENV_ROOT/versions
COPY --from=python-3.9 $PYENV_ROOT/versions/$PY_3_9.tar.zst $PYENV_ROOT/versions/$PY_3_9.tar.zst
COPY --from=python-3.10 $PYENV_ROOT/versions/$PY_3_10.tar.zst $PYENV_ROOT/versions/$PY_3_10.tar.zst
COPY --from=python-3.11 $PYENV_ROOT/versions/$PY_3_11.tar.zst $PYENV_ROOT/versions/$PY_3_11.tar.zst
COPY --from=python-3.12 $PYENV_ROOT/versions/ $PYENV_ROOT/versions/
COPY --from=python-3.12 $PYENV_ROOT/versions/$PY_3_12.tar.zst $PYENV_ROOT/versions/$PY_3_12.tar.zst
COPY --from=python-3.13 $PYENV_ROOT/versions/ $PYENV_ROOT/versions/

# Copy the output of the build script, it should be identical across Python versions
COPY --from=python-3.12 /opt/python/ /opt/python/
COPY --from=python-3.13 /opt/python/ /opt/python/

RUN pyenv global $PY_3_12
RUN pyenv global $PY_3_13
1 change: 1 addition & 0 deletions python/lib/dependabot/python/language_version_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Python
class LanguageVersionManager
# This list must match the versions specified at the top of `python/Dockerfile`
PRE_INSTALLED_PYTHON_VERSIONS = %w(
3.13.0
3.12.5
3.11.9
3.10.15
Expand Down
2 changes: 1 addition & 1 deletion python/spec/dependabot/python/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@

it "exposes the expected ecosystem_versions metric" do
expect(file_fetcher_instance.ecosystem_versions).to eq({
languages: { python: { "max" => "3.12", "raw" => "unknown" } }
languages: { python: { "max" => "3.13", "raw" => "unknown" } }
})
end
end
Expand Down

0 comments on commit 1f651a0

Please sign in to comment.