Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aa7c65b
feat: add build command
parthea Jul 22, 2025
3933663
lint
parthea Jul 22, 2025
8178b9f
update comment
parthea Jul 22, 2025
4653b5b
Merge branch 'main' of https://github.com/googleapis/google-cloud-pyt…
parthea Jul 23, 2025
ea31579
increase timeout to 2 hours
parthea Jul 23, 2025
0e89af2
update test
parthea Jul 23, 2025
a4e6e73
update build command to run tests for a specific library
parthea Jul 23, 2025
598660e
remove return_value
parthea Jul 23, 2025
4f5ec1f
Add TODO comment to reduce docker build duration
parthea Jul 23, 2025
2fbefc0
update exception message
parthea Jul 23, 2025
80007ba
lint
parthea Jul 23, 2025
9d129c8
add type hints
parthea Jul 23, 2025
3f9b48c
refactor common code
parthea Jul 23, 2025
b9b11b0
remove capture output
parthea Jul 23, 2025
917cda9
refactor
parthea Jul 23, 2025
6935737
Merge branch 'main' into add-build-command
parthea Jul 23, 2025
e3580ca
create alias for 3.13.5
parthea Jul 23, 2025
bb6e8d1
fix build
parthea Jul 23, 2025
33207f9
fix build
parthea Jul 23, 2025
a041f2d
fix build
parthea Jul 24, 2025
17fe1c3
fix build
parthea Jul 24, 2025
eb80f09
for testing purposes
parthea Jul 24, 2025
3a1a40f
fix build
parthea Jul 24, 2025
e9914b0
Merge branch 'main' into add-build-command
parthea Jul 24, 2025
f3235e2
restore import
parthea Jul 24, 2025
a2cc75b
restore import
parthea Jul 24, 2025
fce74ed
add type hint
parthea Jul 24, 2025
e36ba3f
use repo dir
parthea Jul 24, 2025
1ea260e
add tests for get_library_id
parthea Jul 24, 2025
8bbe2ad
add tests for _run_individual_session
parthea Jul 24, 2025
9e6c7de
add tests for _run_nox_sessions
parthea Jul 24, 2025
1ec6294
run isort/black
parthea Jul 24, 2025
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
20 changes: 15 additions & 5 deletions .generator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,30 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*

# Set up environment variables for tool versions to make updates easier.
ENV PYTHON_VERSION=3.11.5
ENV BAZELISK_VERSION=v1.26.0

# Create a symbolic link for `python3` to point to our specific version.
ENV PATH /usr/local/bin/python3.11:$PATH

RUN for PYTHON_VERSION in 3.9.23 3.10.18 3.11.13 3.12.11 3.13.5; do \
# Install Python from source
RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \
tar -xvf Python-${PYTHON_VERSION}.tgz && \
cd Python-${PYTHON_VERSION} && \
./configure --enable-optimizations && \
make altinstall && \
cd / && \
rm -rf Python-${PYTHON_VERSION}*
rm -rf Python-${PYTHON_VERSION}* && \
# Install pip using the instructions below
# https://pip.pypa.io/en/stable/installation/#ensurepip
python${PYTHON_VERSION} -m ensurepip --upgrade \
; done

# Test Pip
RUN python3.9 -m pip
RUN python3.10 -m pip
RUN python3.11 -m pip
RUN python3.12 -m pip
RUN python3.13 -m pip


# TODO(https://github.com/googleapis/librarian/issues/904): Install protoc for gencode.

Expand Down
37 changes: 35 additions & 2 deletions .generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import argparse
import json
import logging
import os
import subprocess
import sys
import subprocess
from typing import List

logger = logging.getLogger()

Expand Down Expand Up @@ -113,8 +114,40 @@ def handle_generate():
logger.info("'generate' command executed.")


def _run_nox_sessions(sessions:List[str]):
"""Calls nox with the specified sessions.

Args:
path (List[str]): The list of nox sessions to run.
"""
# Read a generate-request.json file
try:
request_data = _read_json_file(f"{LIBRARIAN_DIR}/{GENERATE_REQUEST_FILE}")
library_id = request_data.get("id")
for nox_session in sessions:
command = ["nox", "-s", nox_session, "-f", f"{SOURCE_DIR}/packages/{library_id}"]
result = subprocess.run(command, capture_output=True, text=True, check=True)
logger.info(result)
except Exception as e:
raise ValueError("Generation failed.") from e

def handle_build():
# TODO(https://github.com/googleapis/librarian/issues/450): Implement build command and update docstring.
"""The main coordinator for validating client library generation."""
sessions = [
"unit-3.9",
"unit-3.10",
"unit-3.11",
"unit-3.12",
"unit-3.13",
"docs",
"system",
"lint",
"lint_setup_py",
"mypy",
"check_lower_bounds",
]
_run_nox_sessions(sessions)

logger.info("'build' command executed.")


Expand Down
5 changes: 4 additions & 1 deletion .generator/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ def test_handle_generate_fail(caplog):
handle_generate()


def test_handle_build_success(caplog, mock_generate_request_file):
def test_handle_build_success(caplog, mocker):
"""
Tests the successful execution path of handle_build.
"""
caplog.set_level(logging.INFO)

mocker.patch(
"cli._run_nox_sessions", return_value="mock-result"
)
handle_build()

assert "'build' command executed." in caplog.text
Expand Down
1 change: 1 addition & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

timeout: 7200s # 2 hours
steps:
# This step builds the Docker image.
- name: 'gcr.io/cloud-builders/docker'
Expand Down
Loading