Skip to content

tests: add testing for Python 3.14 Pre-release #2344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
112 changes: 78 additions & 34 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,40 @@ concurrency:
env:
SHOWCASE_VERSION: 0.35.0
PROTOC_VERSION: 3.20.2
OLDEST_PYTHON: 3.7
LATEST_STABLE_PYTHON: 3.13
PRE_RELEASE_PYTHON: 3.14
ALL_PYTHON: "['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']"

permissions:
contents: read

jobs:
# `all_python_setup` amd `python_config` are a workaround for a known issue where it's not possible to use environment variables outside of `steps`.
# Some jobs set up a text matrix which is outside of `steps` and environment variables can't be used directly.
# This requires a workaround based on the discussion in:
# https://github.com/actions/runner/issues/2372
# The limitation is captured here where certain job configurations don't have access to `env`
# https://docs.github.com/en/enterprise-cloud@latest/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#context-availability
all_python_setup:
runs-on: ubuntu-latest
outputs:
all_python: ${{ env.ALL_PYTHON }}
steps:
- name: Set up all python
id: all_python
run: |
echo 'all_python={{ "${{ env.ALL_PYTHON }}" }}'
python_config:
runs-on: ubuntu-latest
outputs:
oldest_python: ${{ env.OLDEST_PYTHON }}
latest_stable_python: ${{ env.LATEST_STABLE_PYTHON }}
steps:
- name: Print env variables for `python_config`
run: |
echo 'oldest_python={{ "${{ env.OLDEST_PYTHON }}" }}'
echo 'latest_stable_python={{ "${{ env.LATEST_STABLE_PYTHON }}" }}'
docs:
runs-on: ubuntu-latest
steps:
Expand All @@ -34,11 +66,15 @@ jobs:
- name: Build the documentation.
run: nox -s docs
mypy:
needs: all_python_setup
strategy:
matrix:
# Run mypy on all of the supported python versions listed in setup.py
# https://github.com/python/mypy/blob/master/setup.py
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
exclude:
# Remove once https://github.com/googleapis/gapic-generator-python/issues/2303 is fixed
- python: '3.7'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -47,16 +83,18 @@ jobs:
with:
python-version: "${{ matrix.python }}"
cache: 'pip'
allow-prereleases: true
- name: Install nox.
run: python -m pip install nox
- name: Check type annotations.
run: nox -s mypy-${{ matrix.python }}
showcase:
needs: python_config
strategy:
# Run showcase tests on the lowest and highest supported runtimes
matrix:
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `showcase_w_rest_async` target when async rest is GA.
python: ["3.7", "3.13"]
python: ["${{ needs.python_config.outputs.oldest_python }}", "${{ needs.python_config.outputs.latest_stable_python }}"]
target: [showcase, showcase_w_rest_async]
logging_scope: ["", "google"]

Expand Down Expand Up @@ -111,10 +149,10 @@ jobs:
run: |
sudo mkdir -p /tmp/workspace/tests/cert/
sudo chown -R ${USER} /tmp/workspace/
- name: Set up Python "3.13"
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
cache: 'pip'
- name: Copy mtls files
run: cp tests/cert/mtls.* /tmp/workspace/tests/cert/
Expand Down Expand Up @@ -145,9 +183,10 @@ jobs:
nox -s ${{ matrix.target }}
# TODO(yon-mg): add compute unit tests
showcase-unit:
needs: all_python_setup
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `_w_rest_async` variant when async rest is GA.
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, _w_rest_async]
logging_scope: ["", "google"]
Expand All @@ -162,6 +201,7 @@ jobs:
with:
python-version: "${{ matrix.python }}"
cache: 'pip'
allow-prereleases: true
- name: Install system dependencies.
run: |
sudo apt-get update
Expand All @@ -185,10 +225,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python "3.13"
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
cache: 'pip'
- name: Install system dependencies.
run: |
Expand All @@ -213,10 +253,10 @@ jobs:
variant: ['', _alternative_templates]
steps:
- uses: actions/checkout@v4
- name: Set up Python "3.13"
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
cache: 'pip'
- name: Install system dependencies.
run: |
Expand All @@ -235,13 +275,14 @@ jobs:
- name: Typecheck the generated output.
run: nox -s showcase_mypy${{ matrix.variant }}
snippetgen:
needs: all_python_setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python "3.13"
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
cache: 'pip'
- name: Install system dependencies.
run: |
Expand All @@ -252,10 +293,10 @@ jobs:
- name: Check autogenerated snippets.
run: nox -s snippetgen
unit:
needs: all_python_setup
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
# Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
runs-on: ubuntu-22.04
Expand All @@ -264,8 +305,9 @@ jobs:
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
python-version: "${{ matrix.python }}"
cache: 'pip'
allow-prereleases: true
- name: Install pandoc
run: |
sudo apt-get update
Expand All @@ -276,11 +318,11 @@ jobs:
- name: Run unit tests.
run: nox -s unit-${{ matrix.python }}
fragment:
needs: all_python_setup
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
variant: ['', _alternative_templates]

# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
# Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
runs-on: ubuntu-22.04
Expand All @@ -289,8 +331,9 @@ jobs:
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
python-version: "${{ matrix.python }}"
cache: 'pip'
allow-prereleases: true
- name: Install pandoc
run: |
sudo apt-get update
Expand Down Expand Up @@ -333,29 +376,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.13
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: ${{ env.LATEST_STABLE_PYTHON }}
cache: 'pip'
- name: Install nox.
run: |
python -m pip install nox
- name: Run blacken and lint on the generated output.
run: |
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-3.13 blacken lint
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-3.13 blacken lint
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-3.13 blacken lint
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-3.13 blacken lint
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-3.13 blacken lint
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
goldens-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.13
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
cache: 'pip'
- name: Install nox.
run: |
Expand All @@ -365,19 +408,20 @@ jobs:
# in order to run unit tests
# See https://github.com/googleapis/gapic-generator-python/issues/1806
run: |
nox -f tests/integration/goldens/credentials/noxfile.py -s unit-3.13
nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-3.13
nox -f tests/integration/goldens/logging/noxfile.py -s unit-3.13
nox -f tests/integration/goldens/redis/noxfile.py -s unit-3.13
nox -f tests/integration/goldens/credentials/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
nox -f tests/integration/goldens/logging/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
nox -f tests/integration/goldens/redis/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
goldens-prerelease:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.13
- name: Set up Python ${{ env.PRE_RELEASE_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "${{ env.PRE_RELEASE_PYTHON }}"
cache: 'pip'
allow-prereleases: true
- name: Install nox.
run: |
python -m pip install nox
Expand All @@ -394,10 +438,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python "3.13"
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
cache: 'pip'
- name: Install nox.
run: |
Expand Down
18 changes: 12 additions & 6 deletions gapic/templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ ALL_PYTHON = [
"3.11",
"3.12",
"3.13",
"3.14",
]

DEFAULT_PYTHON_VERSION = ALL_PYTHON[-1]
DEFAULT_PYTHON_VERSION = ALL_PYTHON[-2]
PRE_RELEASE_PYTHON = ALL_PYTHON[-1]

CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()

Expand All @@ -51,7 +53,7 @@ UNIT_TEST_DEPENDENCIES: List[str] = []
UNIT_TEST_EXTRAS: List[str] = []
UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {}

SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ALL_PYTHON
SYSTEM_TEST_STANDARD_DEPENDENCIES = [
"mock",
"pytest",
Expand Down Expand Up @@ -223,15 +225,17 @@ def install_unittest_dependencies(session, *constraints):
def unit(session, protobuf_implementation):
# Install all test dependencies, then install this package in-place.

if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"):
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
# Remove this check once support for Protobuf 3.x is dropped.
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
session.skip("cpp implementation is not supported in python 3.11+")

constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
install_unittest_dependencies(session, "-c", constraints_path)

# TODO(https://github.com/googleapis/synthtool/issues/1976):
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
# Remove the 'cpp' implementation once support for Protobuf 3.x is dropped.
# The 'cpp' implementation requires Protobuf<4.
if protobuf_implementation == "cpp":
Expand Down Expand Up @@ -425,7 +429,7 @@ def docfx(session):
)


@nox.session(python=DEFAULT_PYTHON_VERSION)
@nox.session(python=PRE_RELEASE_PYTHON)
@nox.parametrize(
"protobuf_implementation",
["python", "upb", "cpp"],
Expand All @@ -438,7 +442,9 @@ def prerelease_deps(session, protobuf_implementation):
`pip install --pre <package>`.
"""

if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"):
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2388):
# Remove this check once support for Protobuf 3.x is dropped.
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13", "3.14"):
session.skip("cpp implementation is not supported in python 3.11+")

# Install all dependencies
Expand Down
3 changes: 2 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
"3.11",
"3.12",
"3.13",
"3.14",
)

NEWEST_PYTHON = ALL_PYTHON[-1]
NEWEST_PYTHON = ALL_PYTHON[-2]


@nox.session(python=ALL_PYTHON)
Expand Down
Loading
Loading