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
71 changes: 71 additions & 0 deletions .generator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM marketplace.gcr.io/google/ubuntu2404 AS builder

# TODO(https://github.com/googleapis/librarian/issues/901): Install the necssary dependencies and build tools.
RUN apt-get update && \
apt-get install -y --no-install-recommends \
# Essential for compiling C code
build-essential \
# For downloading secure files
wget \
ca-certificates \
# --- Critical libraries for a complete Python build ---
libssl-dev \
zlib1g-dev \
libbz2-dev \
libffi-dev \
libsqlite3-dev \
libreadline-dev \
# ------------------------------------------------------
&& apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set up environment variables for tool versions to make updates easier.
# TODO(): Downgrade to Python `3.11` if `3.13.5` is incompatible with googleapis.
ENV PYTHON_VERSION=3.13.5

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

# Install Python from source
RUN 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}*

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

# TODO(https://github.com/googleapis/librarian/issues/903): Install Bazelisk for building a client library.

# TODO(https://github.com/googleapis/librarian/issues/902): Create a dedicate non-root user and
# switch to the non-root user to run subsequent commands.

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

# TODO(https://github.com/googleapis/librarian/issues/907): Install Python dependencies from requirements.in.
# TODO(https://github.com/googleapis/librarian/issues/905): Install Synthtool by cloning its repo.
# TODO(https://github.com/googleapis/librarian/issues/906): Clone googleapis and run bazelisk build.

# Copy the CLI script into the container and set ownership.
# No other files or dependencies are needed for this simple script.
COPY cli.py .

# Set the entrypoint for the container to run the script.
ENTRYPOINT ["python3.13", "./cli.py"]
50 changes: 50 additions & 0 deletions .generator/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import sys

def handle_configure(dry_run=False):
# TODO(https://github.com/googleapis/librarian/issues/466): Implement configure command.
print("'configure' command executed.")

def handle_generate(dry_run=False):
# TODO(https://github.com/googleapis/librarian/issues/448): Implement generate command.
print("'generate' command executed.")

def handle_build(dry_run=False):
# TODO(https://github.com/googleapis/librarian/issues/450): Implement build command.
print("'build' command executed.")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="A simple CLI tool.")
subparsers = parser.add_subparsers(dest="command", required=True, help="Available commands")

# Define commands
for command_name, help_text in [
("configure", "Onboard a new library or an api path to Librarian workflow."),
("generate", "generate a python client for an API."),
("build", "Run unit tests via nox for the generated library.")
]:
handler_map = {"configure": handle_configure, "generate": handle_generate, "build": handle_build}
parser_cmd = subparsers.add_parser(command_name, help=help_text)
parser_cmd.set_defaults(func=handler_map[command_name])

if len(sys.argv) == 1:
parser.print_help(sys.stderr)
sys.exit(1)

args = parser.parse_args()
args.func(args)
28 changes: 28 additions & 0 deletions .generator/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from cli import handle_generate, handle_build, handle_configure


def test_handle_configure_dry_run():
Copy link
Contributor

Choose a reason for hiding this comment

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

Will you also have tests with dry_run=False?

I could imagine that when dry_run=False, you could accumulate the commands that would be yielded by dry_run=True and pass them to a function execute_run that will execute them. In that case, the tests for dry_run=False need merely verify that the invocations all call execute_run with the expected parameters, and then we only need a single additional test for execute_run that it executes a given test command.

# This is a simple test to ensure that the dry run command succeeds.
handle_configure(dry_run=True)

def test_handle_generate_dry_run():
# This is a simple test to ensure that the dry run command succeeds.
handle_generate(dry_run=True)

def test_handle_build_dry_run():
# This is a simple test to ensure that the dry run command succeeds.
handle_build(dry_run=True)
30 changes: 30 additions & 0 deletions .github/workflows/generator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
pull_request:
branches:
- main
name: generator

permissions:
contents: read

jobs:
test_generator_cli:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
# Use a fetch-depth of 2
# See https://github.com/googleapis/google-cloud-python/issues/12013
# and https://github.com/actions/checkout#checkout-head.
with:
fetch-depth: 2
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install pytest
run: |
python -m pip install pytest
- name: Run generator_cli tests
run: |
pytest .generator/test_cli.py
Loading