Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions .generator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,25 @@ RUN apt-get update && \
&& apt-get clean && \
rm -rf /var/lib/apt/lists/*

# `make altinstall` is used to prevent replacing the system's default python binary.
ENV PYTHON_VERSION=3.14

# The full Python version, including the minor version, is needed for download/install
# TODO(https://github.com/googleapis/librarian/issues/2945): Remove `3.13` when the linked issue is resolved.
RUN for PYTHON_VERSION_WITH_MINOR in 3.13.9 3.14.0; do \
wget https://www.python.org/ftp/python/${PYTHON_VERSION_WITH_MINOR}/Python-${PYTHON_VERSION_WITH_MINOR}.tgz && \
ENV PYTHON_VERSION_WITH_MINOR=3.14.2

# `make altinstall` is used to prevent replacing the system's default python binary.
RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION_WITH_MINOR}/Python-${PYTHON_VERSION_WITH_MINOR}.tgz && \
tar -xvf Python-${PYTHON_VERSION_WITH_MINOR}.tgz && \
cd Python-${PYTHON_VERSION_WITH_MINOR} && \
./configure --enable-optimizations --prefix=/usr/local && \
make -j$(nproc) && \
make altinstall && \
cd / && \
rm -rf Python-${PYTHON_VERSION_WITH_MINOR}* \
; done
rm -rf Python-${PYTHON_VERSION_WITH_MINOR}*


# Install pip for each python version
# TODO(https://github.com/googleapis/librarian/issues/2945): Remove `3.13` when the linked issue is resolved.
RUN for PYTHON_VERSION in 3.13 3.14; do \
wget --no-check-certificate -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' && \
RUN wget --no-check-certificate -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' && \
python${PYTHON_VERSION} /tmp/get-pip.py && \
rm /tmp/get-pip.py \
; done
rm /tmp/get-pip.py
Comment on lines +49 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To reduce the number of layers in the Docker image and improve build efficiency, it's a good practice to combine consecutive RUN commands. You can merge the Python installation and pip installation steps into a single RUN command.

RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION_WITH_MINOR}/Python-${PYTHON_VERSION_WITH_MINOR}.tgz && \
    tar -xvf Python-${PYTHON_VERSION_WITH_MINOR}.tgz && \
    cd Python-${PYTHON_VERSION_WITH_MINOR} && \
    ./configure --enable-optimizations --prefix=/usr/local && \
    make -j$(nproc) && \
    make altinstall && \
    cd / && \
    rm -rf Python-${PYTHON_VERSION_WITH_MINOR}* && \
    wget --no-check-certificate -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' && \
    python${PYTHON_VERSION} /tmp/get-pip.py && \
    rm /tmp/get-pip.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to keep them separate as this helps provide quicker development iterations when we need to make changes to the Dockerfile. During local development, the install step takes a long time to complete. If we need to make changes to the pip installation, then the python runtime installation won't be cached. We'll have to repeat it again.


# Download/extract protoc
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protoc-25.3-linux-x86_64.zip
Expand Down Expand Up @@ -112,10 +110,6 @@ COPY --from=builder synthtool /synthtool
COPY --from=builder /usr/local/bin/python${PYTHON_VERSION_DEFAULT} /usr/local/bin/
COPY --from=builder /usr/local/lib/python${PYTHON_VERSION_DEFAULT} /usr/local/lib/python${PYTHON_VERSION_DEFAULT}

# TODO(https://github.com/googleapis/librarian/issues/2945): Remove `3.13` when the linked issue is resolved.
COPY --from=builder /usr/local/bin/python3.13 /usr/local/bin
COPY --from=builder /usr/local/lib/python3.13 /usr/local/lib/python3.13

# Set the working directory in the container.
WORKDIR /app

Expand Down
11 changes: 1 addition & 10 deletions .generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,16 +995,7 @@ def _run_nox_sessions(library_id: str, repo: str, is_mono_repo: bool):
the config.yaml.
is_mono_repo(bool): True if the current repository is a mono-repo.
"""
path_to_library = f"{repo}/packages/{library_id}" if is_mono_repo else repo
_python_314_supported = Path(
f"{path_to_library}/testing/constraints-3.14.txt"
).exists()

if _python_314_supported:
session_runtime = "3.14"
else:
session_runtime = "3.13"

session_runtime = "3.14"
sessions = [
f"unit-{session_runtime}(protobuf_implementation='upb')",
]
Expand Down
10 changes: 3 additions & 7 deletions .generator/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,26 +776,22 @@ def test_run_individual_session_failure(mocker):


@pytest.mark.parametrize(
"is_mono_repo,py314_constraints_file_exists, nox_session_python_runtime",
"is_mono_repo, nox_session_python_runtime",
[
(False, True, "3.14"),
(True, True, "3.14"),
(True, False, "3.13"),
(False, False, "3.13"),
(False, "3.14"),
(True, "3.14"),
],
)
def test_run_nox_sessions_success(
mocker,
mock_generate_request_data_for_nox,
is_mono_repo,
py314_constraints_file_exists,
nox_session_python_runtime,
):
"""Tests that _run_nox_sessions successfully runs all specified sessions."""
mocker.patch("cli._read_json_file", return_value=mock_generate_request_data_for_nox)
mocker.patch("cli._get_library_id", return_value="mock-library")
mock_run_individual_session = mocker.patch("cli._run_individual_session")
mocker.patch("pathlib.Path.exists", return_value=py314_constraints_file_exists)

sessions_to_run = [
f"unit-{nox_session_python_runtime}(protobuf_implementation='upb')",
Expand Down
Loading