Skip to content

Commit 6b4b00d

Browse files
authored
chore(librarian): Remove all python runtimes except 3.14 from Dockerfile (#14826)
This PR removes all Python runtimes except 3.14 from the [librarian Dockerfile](https://github.com/googleapis/google-cloud-python/blob/main/.generator/Dockerfile) used to generate client libraries. I tested this change locally and did not encounter any issues.
1 parent c0baa32 commit 6b4b00d

File tree

3 files changed

+22
-35
lines changed

3 files changed

+22
-35
lines changed

.generator/Dockerfile

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,27 @@ RUN apt-get update && \
3636
&& apt-get clean && \
3737
rm -rf /var/lib/apt/lists/*
3838

39-
# Install multiple Python versions from source. `make altinstall` is used to
40-
# prevent replacing the system's default python binary.
41-
# TODO(http://github.com/googleapis/gapic-generator-python/issues/2435): Remove `3.10.18` when the linked issue is resolved.
42-
RUN for PYTHON_VERSION in 3.9.23 3.10.18 3.13.7 3.14.0; do \
43-
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \
44-
tar -xvf Python-${PYTHON_VERSION}.tgz && \
45-
cd Python-${PYTHON_VERSION} && \
39+
ENV PYTHON_VERSION=3.14
40+
41+
# The full Python version, including the minor version, is needed for download/install
42+
ENV PYTHON_VERSION_WITH_MINOR=3.14.0
43+
44+
# `make altinstall` is used to prevent replacing the system's default python binary.
45+
RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION_WITH_MINOR}/Python-${PYTHON_VERSION_WITH_MINOR}.tgz && \
46+
tar -xvf Python-${PYTHON_VERSION_WITH_MINOR}.tgz && \
47+
cd Python-${PYTHON_VERSION_WITH_MINOR} && \
4648
./configure --enable-optimizations --prefix=/usr/local && \
4749
make -j$(nproc) && \
4850
make altinstall && \
4951
cd / && \
50-
rm -rf Python-${PYTHON_VERSION}* \
51-
; done
52+
rm -rf Python-${PYTHON_VERSION_WITH_MINOR}*
5253

5354
# Install pip for each python version
5455
# TODO(http://github.com/googleapis/gapic-generator-python/issues/2435): Remove `3.10` when the linked issue is resolved.
5556
RUN wget --no-check-certificate -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' && \
56-
for PYTHON_VERSION in 3.9 3.10 3.13 3.14; do \
57-
python${PYTHON_VERSION} /tmp/get-pip.py; \
58-
done && \
57+
python${PYTHON_VERSION} /tmp/get-pip.py && \
5958
rm /tmp/get-pip.py
6059

61-
RUN /usr/local/bin/python3.9 -m venv bazel_env
62-
RUN . bazel_env/bin/activate
63-
6460
# Download/extract protoc
6561
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protoc-25.3-linux-x86_64.zip
6662
RUN unzip protoc-25.3-linux-x86_64.zip -d protoc
@@ -85,6 +81,8 @@ FROM marketplace.gcr.io/google/ubuntu2404
8581
# the live repo.
8682
ENV SYNTHTOOL_TEMPLATES="/synthtool/synthtool/gcp/templates"
8783

84+
ENV PYTHON_VERSION=3.14
85+
8886
# Install only the essential runtime libraries for Python.
8987
# These are the non "-dev" versions of the libraries used in the builder.
9088
RUN apt-get update && \
@@ -104,19 +102,8 @@ COPY --from=builder protoc/include /usr/local/include
104102
COPY --from=builder pandoc-binary/bin /usr/local/bin
105103
COPY --from=builder synthtool /synthtool
106104

107-
# Copy all Python interpreters, their pip executables, and their standard libraries from the builder.
108-
COPY --from=builder /usr/local/bin/python3.9 /usr/local/bin/
109-
COPY --from=builder /usr/local/lib/python3.9 /usr/local/lib/python3.9
110-
111-
# TODO(http://github.com/googleapis/gapic-generator-python/issues/2435): Remove `3.10` when the linked issue is resolved.
112-
COPY --from=builder /usr/local/bin/python3.10 /usr/local/bin/
113-
COPY --from=builder /usr/local/lib/python3.10 /usr/local/lib/python3.10
114-
115-
COPY --from=builder /usr/local/bin/python3.13 /usr/local/bin/
116-
COPY --from=builder /usr/local/lib/python3.13 /usr/local/lib/python3.13
117-
118-
COPY --from=builder /usr/local/bin/python3.14 /usr/local/bin/
119-
COPY --from=builder /usr/local/lib/python3.14 /usr/local/lib/python3.14
105+
COPY --from=builder /usr/local/bin/python${PYTHON_VERSION} /usr/local/bin/
106+
COPY --from=builder /usr/local/lib/python${PYTHON_VERSION} /usr/local/lib/python${PYTHON_VERSION}
120107

121108
# Set the working directory in the container.
122109
WORKDIR /app
@@ -126,12 +113,12 @@ WORKDIR /app
126113
# Install nox which is used for running client library tests.
127114
# Install starlark-pyo3 which is used to parse BUILD.bazel files.
128115
COPY .generator/requirements.in .
129-
RUN python3.9 -m pip install -r requirements.in
130-
RUN python3.9 -m pip install /synthtool
116+
RUN python${PYTHON_VERSION} -m pip install -r requirements.in
117+
RUN python${PYTHON_VERSION} -m pip install /synthtool
131118

132119
# Install build which is used to get the metadata of package config files.
133120
COPY .generator/requirements.in .
134-
RUN python3.9 -m pip install -r requirements.in
121+
RUN python${PYTHON_VERSION} -m pip install -r requirements.in
135122

136123
# Copy the CLI script into the container.
137124
COPY .generator/cli.py .
@@ -141,4 +128,4 @@ RUN chmod a+rx ./cli.py
141128
COPY .generator/parse_googleapis_content.py .
142129
RUN chmod a+rx ./parse_googleapis_content.py
143130

144-
ENTRYPOINT ["python3.9", "./cli.py"]
131+
ENTRYPOINT ["python3.14", "./cli.py"]

.generator/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ def _run_nox_sessions(library_id: str, repo: str):
875875
the config.yaml.
876876
"""
877877
sessions = [
878-
"unit-3.13(protobuf_implementation='upb')",
878+
"unit-3.14(protobuf_implementation='upb')",
879879
]
880880
current_session = None
881881
try:

.generator/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,15 +732,15 @@ def test_run_nox_sessions_success(mocker, mock_generate_request_data_for_nox):
732732
mock_run_individual_session = mocker.patch("cli._run_individual_session")
733733

734734
sessions_to_run = [
735-
"unit-3.13(protobuf_implementation='upb')",
735+
"unit-3.14(protobuf_implementation='upb')",
736736
]
737737
_run_nox_sessions("mock-library", "repo")
738738

739739
assert mock_run_individual_session.call_count == len(sessions_to_run)
740740
mock_run_individual_session.assert_has_calls(
741741
[
742742
mocker.call(
743-
"unit-3.13(protobuf_implementation='upb')", "mock-library", "repo"
743+
"unit-3.14(protobuf_implementation='upb')", "mock-library", "repo"
744744
),
745745
]
746746
)

0 commit comments

Comments
 (0)