Skip to content

Commit 7f7d50e

Browse files
authored
tests: add testing for Python 3.14 Pre-release (#2344)
1 parent 46b321a commit 7f7d50e

File tree

19 files changed

+280
-84
lines changed

19 files changed

+280
-84
lines changed

.github/workflows/tests.yaml

Lines changed: 78 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,40 @@ concurrency:
1616
env:
1717
SHOWCASE_VERSION: 0.35.0
1818
PROTOC_VERSION: 3.20.2
19+
OLDEST_PYTHON: 3.7
20+
LATEST_STABLE_PYTHON: 3.13
21+
PRE_RELEASE_PYTHON: 3.14
22+
ALL_PYTHON: "['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']"
23+
24+
permissions:
25+
contents: read
1926

2027
jobs:
28+
# `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`.
29+
# Some jobs set up a text matrix which is outside of `steps` and environment variables can't be used directly.
30+
# This requires a workaround based on the discussion in:
31+
# https://github.com/actions/runner/issues/2372
32+
# The limitation is captured here where certain job configurations don't have access to `env`
33+
# https://docs.github.com/en/enterprise-cloud@latest/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#context-availability
34+
all_python_setup:
35+
runs-on: ubuntu-latest
36+
outputs:
37+
all_python: ${{ env.ALL_PYTHON }}
38+
steps:
39+
- name: Set up all python
40+
id: all_python
41+
run: |
42+
echo 'all_python={{ "${{ env.ALL_PYTHON }}" }}'
43+
python_config:
44+
runs-on: ubuntu-latest
45+
outputs:
46+
oldest_python: ${{ env.OLDEST_PYTHON }}
47+
latest_stable_python: ${{ env.LATEST_STABLE_PYTHON }}
48+
steps:
49+
- name: Print env variables for `python_config`
50+
run: |
51+
echo 'oldest_python={{ "${{ env.OLDEST_PYTHON }}" }}'
52+
echo 'latest_stable_python={{ "${{ env.LATEST_STABLE_PYTHON }}" }}'
2153
docs:
2254
runs-on: ubuntu-latest
2355
steps:
@@ -49,11 +81,15 @@ jobs:
4981
- name: Build the documentation.
5082
run: nox -s docfx
5183
mypy:
84+
needs: all_python_setup
5285
strategy:
5386
matrix:
5487
# Run mypy on all of the supported python versions listed in setup.py
5588
# https://github.com/python/mypy/blob/master/setup.py
56-
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
89+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
90+
exclude:
91+
# Remove once https://github.com/googleapis/gapic-generator-python/issues/2303 is fixed
92+
- python: '3.7'
5793
runs-on: ubuntu-latest
5894
steps:
5995
- uses: actions/checkout@v5
@@ -62,16 +98,18 @@ jobs:
6298
with:
6399
python-version: "${{ matrix.python }}"
64100
cache: 'pip'
101+
allow-prereleases: true
65102
- name: Install nox.
66103
run: python -m pip install nox
67104
- name: Check type annotations.
68105
run: nox -s mypy-${{ matrix.python }}
69106
showcase:
107+
needs: python_config
70108
strategy:
71109
# Run showcase tests on the lowest and highest supported runtimes
72110
matrix:
73111
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `showcase_w_rest_async` target when async rest is GA.
74-
python: ["3.7", "3.13"]
112+
python: ["${{ needs.python_config.outputs.oldest_python }}", "${{ needs.python_config.outputs.latest_stable_python }}"]
75113
target: [showcase, showcase_w_rest_async]
76114
logging_scope: ["", "google"]
77115

@@ -126,10 +164,10 @@ jobs:
126164
run: |
127165
sudo mkdir -p /tmp/workspace/tests/cert/
128166
sudo chown -R ${USER} /tmp/workspace/
129-
- name: Set up Python "3.13"
167+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
130168
uses: actions/setup-python@v6
131169
with:
132-
python-version: "3.13"
170+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
133171
cache: 'pip'
134172
- name: Copy mtls files
135173
run: cp tests/cert/mtls.* /tmp/workspace/tests/cert/
@@ -160,9 +198,10 @@ jobs:
160198
nox -s ${{ matrix.target }}
161199
# TODO(yon-mg): add compute unit tests
162200
showcase-unit:
201+
needs: all_python_setup
163202
strategy:
164203
matrix:
165-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
204+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
166205
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `_w_rest_async` variant when async rest is GA.
167206
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, _w_rest_async]
168207
logging_scope: ["", "google"]
@@ -177,6 +216,7 @@ jobs:
177216
with:
178217
python-version: "${{ matrix.python }}"
179218
cache: 'pip'
219+
allow-prereleases: true
180220
- name: Install system dependencies.
181221
run: |
182222
sudo apt-get update
@@ -200,10 +240,10 @@ jobs:
200240
runs-on: ubuntu-latest
201241
steps:
202242
- uses: actions/checkout@v5
203-
- name: Set up Python "3.13"
243+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
204244
uses: actions/setup-python@v6
205245
with:
206-
python-version: "3.13"
246+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
207247
cache: 'pip'
208248
- name: Install system dependencies.
209249
run: |
@@ -228,10 +268,10 @@ jobs:
228268
variant: ['', _alternative_templates]
229269
steps:
230270
- uses: actions/checkout@v5
231-
- name: Set up Python "3.13"
271+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
232272
uses: actions/setup-python@v6
233273
with:
234-
python-version: "3.13"
274+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
235275
cache: 'pip'
236276
- name: Install system dependencies.
237277
run: |
@@ -250,13 +290,14 @@ jobs:
250290
- name: Typecheck the generated output.
251291
run: nox -s showcase_mypy${{ matrix.variant }}
252292
snippetgen:
293+
needs: all_python_setup
253294
runs-on: ubuntu-latest
254295
steps:
255296
- uses: actions/checkout@v5
256-
- name: Set up Python "3.13"
297+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
257298
uses: actions/setup-python@v6
258299
with:
259-
python-version: "3.13"
300+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
260301
cache: 'pip'
261302
- name: Install system dependencies.
262303
run: |
@@ -267,10 +308,10 @@ jobs:
267308
- name: Check autogenerated snippets.
268309
run: nox -s snippetgen
269310
unit:
311+
needs: all_python_setup
270312
strategy:
271313
matrix:
272-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
273-
314+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
274315
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
275316
# Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
276317
runs-on: ubuntu-22.04
@@ -279,8 +320,9 @@ jobs:
279320
- name: Set up Python ${{ matrix.python }}
280321
uses: actions/setup-python@v6
281322
with:
282-
python-version: ${{ matrix.python }}
323+
python-version: "${{ matrix.python }}"
283324
cache: 'pip'
325+
allow-prereleases: true
284326
- name: Install pandoc
285327
run: |
286328
sudo apt-get update
@@ -291,11 +333,11 @@ jobs:
291333
- name: Run unit tests.
292334
run: nox -s unit-${{ matrix.python }}
293335
fragment:
336+
needs: all_python_setup
294337
strategy:
295338
matrix:
296-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
339+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
297340
variant: ['', _alternative_templates]
298-
299341
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
300342
# Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
301343
runs-on: ubuntu-22.04
@@ -304,8 +346,9 @@ jobs:
304346
- name: Set up Python ${{ matrix.python }}
305347
uses: actions/setup-python@v6
306348
with:
307-
python-version: ${{ matrix.python }}
349+
python-version: "${{ matrix.python }}"
308350
cache: 'pip'
351+
allow-prereleases: true
309352
- name: Install pandoc
310353
run: |
311354
sudo apt-get update
@@ -348,29 +391,29 @@ jobs:
348391
runs-on: ubuntu-latest
349392
steps:
350393
- uses: actions/checkout@v5
351-
- name: Set up Python 3.13
394+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
352395
uses: actions/setup-python@v6
353396
with:
354-
python-version: "3.13"
397+
python-version: ${{ env.LATEST_STABLE_PYTHON }}
355398
cache: 'pip'
356399
- name: Install nox.
357400
run: |
358401
python -m pip install nox
359402
- name: Run blacken and lint on the generated output.
360403
run: |
361-
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-3.13 blacken lint
362-
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-3.13 blacken lint
363-
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-3.13 blacken lint
364-
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-3.13 blacken lint
365-
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-3.13 blacken lint
404+
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
405+
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
406+
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
407+
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
408+
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
366409
goldens-unit:
367410
runs-on: ubuntu-latest
368411
steps:
369412
- uses: actions/checkout@v5
370-
- name: Set up Python 3.13
413+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
371414
uses: actions/setup-python@v6
372415
with:
373-
python-version: "3.13"
416+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
374417
cache: 'pip'
375418
- name: Install nox.
376419
run: |
@@ -380,19 +423,20 @@ jobs:
380423
# in order to run unit tests
381424
# See https://github.com/googleapis/gapic-generator-python/issues/1806
382425
run: |
383-
nox -f tests/integration/goldens/credentials/noxfile.py -s unit-3.13
384-
nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-3.13
385-
nox -f tests/integration/goldens/logging/noxfile.py -s unit-3.13
386-
nox -f tests/integration/goldens/redis/noxfile.py -s unit-3.13
426+
nox -f tests/integration/goldens/credentials/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
427+
nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
428+
nox -f tests/integration/goldens/logging/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
429+
nox -f tests/integration/goldens/redis/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
387430
goldens-prerelease:
388431
runs-on: ubuntu-latest
389432
steps:
390433
- uses: actions/checkout@v5
391-
- name: Set up Python 3.13
434+
- name: Set up Python ${{ env.PRE_RELEASE_PYTHON }}
392435
uses: actions/setup-python@v6
393436
with:
394-
python-version: "3.13"
437+
python-version: "${{ env.PRE_RELEASE_PYTHON }}"
395438
cache: 'pip'
439+
allow-prereleases: true
396440
- name: Install nox.
397441
run: |
398442
python -m pip install nox
@@ -409,10 +453,10 @@ jobs:
409453
runs-on: ubuntu-latest
410454
steps:
411455
- uses: actions/checkout@v5
412-
- name: Set up Python "3.13"
456+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
413457
uses: actions/setup-python@v6
414458
with:
415-
python-version: "3.13"
459+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
416460
cache: 'pip'
417461
- name: Install nox.
418462
run: |

gapic/schema/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,11 +935,13 @@ def enforce_valid_library_settings(
935935

936936
# Check to see if selective gapic generation methods are valid.
937937
selective_gapic_errors = {}
938+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2446):
939+
# Workaround issue in Python 3.14 related to code coverage by adding `# pragma: no branch`
938940
for (
939941
method_name
940942
) in (
941943
library_settings.python_settings.common.selective_gapic_generation.methods
942-
):
944+
): # pragma: no branch
943945
if method_name not in self.all_methods:
944946
selective_gapic_errors[method_name] = "Method does not exist."
945947
elif not method_name.startswith(library_settings.version):

gapic/templates/noxfile.py.j2

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ ALL_PYTHON = [
2929
"3.11",
3030
"3.12",
3131
"3.13",
32+
"3.14",
3233
]
3334

34-
DEFAULT_PYTHON_VERSION = ALL_PYTHON[-1]
35+
DEFAULT_PYTHON_VERSION = ALL_PYTHON[-2]
36+
PRE_RELEASE_PYTHON = ALL_PYTHON[-1]
3537

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

@@ -51,7 +53,7 @@ UNIT_TEST_DEPENDENCIES: List[str] = []
5153
UNIT_TEST_EXTRAS: List[str] = []
5254
UNIT_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {}
5355

54-
SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
56+
SYSTEM_TEST_PYTHON_VERSIONS: List[str] = ALL_PYTHON
5557
SYSTEM_TEST_STANDARD_DEPENDENCIES = [
5658
"mock",
5759
"pytest",
@@ -224,15 +226,17 @@ def install_unittest_dependencies(session, *constraints):
224226
def unit(session, protobuf_implementation):
225227
# Install all test dependencies, then install this package in-place.
226228

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

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

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

427431

428-
@nox.session(python=DEFAULT_PYTHON_VERSION)
432+
@nox.session(python=PRE_RELEASE_PYTHON)
429433
@nox.parametrize(
430434
"protobuf_implementation",
431435
["python", "upb", "cpp"],
@@ -438,7 +442,9 @@ def prerelease_deps(session, protobuf_implementation):
438442
`pip install --pre <package>`.
439443
"""
440444

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

444450
# Install all dependencies
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% from '_pypi_packages.j2' import pypi_packages %}
2+
# We use the constraints file for the latest Python version
3+
# (currently this file) to check that the latest
4+
# major versions of dependencies are supported in setup.py.
5+
# List all library dependencies and extras in this file.
6+
# Require the latest major version be installed for each dependency.
7+
# e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0",
8+
# Then this file should have google-cloud-foo>=1
9+
google-api-core>=2
10+
google-auth>=2
11+
proto-plus>=1
12+
protobuf>=6
13+
{% for package_tuple, package_info in pypi_packages.items() %}
14+
{# Quick check to make sure `package_info.package_name` is not the package being generated so we don't circularly include this package in its own constraints file. #}
15+
{% if api.naming.warehouse_package_name != package_info.package_name %}
16+
{% if api.requires_package(package_tuple) %}
17+
{{ package_info.package_name }}>={{ (package_info.upper_bound.split(".")[0] | int) - 1 }}
18+
{% endif %}
19+
{% endif %}
20+
{% endfor %}

noxfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444
"3.11",
4545
"3.12",
4646
"3.13",
47+
"3.14",
4748
)
4849

49-
NEWEST_PYTHON = ALL_PYTHON[-1]
50+
NEWEST_PYTHON = ALL_PYTHON[-2]
5051

5152

5253
@nox.session(python=ALL_PYTHON)

0 commit comments

Comments
 (0)