python.yml•3.04 kB
# 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.
#
# SPDX-License-Identifier: Apache-2.0
name: Python Checks
on:
  pull_request:
    paths:
      - "py/**"
      - "genkit-tools/**"
      - ".github/workflows/python.yml"
jobs:
  python-checks:
    runs-on: ubuntu-latest
    env:
      PATH: ${{ github.workspace }}/go/bin:${{ github.workspace }}/.cargo/bin:${{ github.workspace }}/.local/share/pnpm:${{ github.workspace }}/.local/bin:/usr/local/bin:/usr/bin:/bin
    strategy:
      matrix:
        python-version:
          - "3.10"
          - "3.11"
          - "3.12"
          - "3.13"
          #- "pypy-3.10" # TODO: Fix build failures.
          #- "pypy-3.11" # TODO: Fix build failures.
          #- "3.14" # TODO: This still fails.
      fail-fast: false
    steps:
      - uses: actions/checkout@v4
      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y build-essential libffi-dev cmake curl ripgrep
      - name: Set up Go
        uses: actions/setup-go@main
        with:
          go-version: stable
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
      - name: Install pnpm
        uses: pnpm/action-setup@v3
        with:
          version: 10.2.0
      - name: Install uv and setup Python version
        uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true
          python-version: ${{ matrix.python-version }}
      - name: Install Python dependencies
        run: |
          cd py
          uv pip install -e .[dev,test,docs]
          uv pip install --group dev
      - name: Install NPM packages
        run: |
          npm install -g license-checker
      - name: Install Go tools
        run: |
          go install github.com/google/go-licenses@latest
      - name: Generate schema typing
        run: ./py/bin/generate_schema_typing --ci
      - name: Format check
        run: uv run --directory py ruff format --check .
      - name: Lint with ruff
        run: uv run --directory py ruff check --select I .
      - name: Check licenses
        run: ./bin/check_license
      - name: Run Python tests
        run: uv run --python ${{ matrix.python-version }} --active --isolated --directory py pytest -xvs --log-level=DEBUG .
      - name: Build distributions
        run: ./py/bin/build_dists