Skip to content

Commit

Permalink
feat: Add support for Python 3.13 (#2215)
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea authored Oct 23, 2024
1 parent f2053ee commit 4e1f9c6
Show file tree
Hide file tree
Showing 25 changed files with 140 additions and 67 deletions.
17 changes: 13 additions & 4 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ branchProtectionRules:
- 'mypy (3.10)'
- 'mypy (3.11)'
- 'mypy (3.12)'
- 'mypy (3.13)'
- 'showcase (3.7, showcase)'
- 'showcase (3.12, showcase)'
- 'showcase (3.13, showcase)'
- 'showcase (3.7, showcase_alternative_templates)'
- 'showcase (3.12, showcase_alternative_templates)'
- 'showcase (3.7, _w_rest_async)'
- 'showcase (3.12, _w_rest_async)'
- 'showcase (3.13, showcase_alternative_templates)'
- 'showcase (3.7, showcase_w_rest_async)'
- 'showcase (3.13, showcase_w_rest_async)'
# TODO(dovs): reenable these when the mtls tests have been debugged and fixed
# See #1218 for details
# - 'showcase-mtls (showcase_mtls)'
Expand All @@ -30,30 +31,35 @@ branchProtectionRules:
- 'showcase-unit (3.10)'
- 'showcase-unit (3.11)'
- 'showcase-unit (3.12)'
- 'showcase-unit (3.13)'
- 'showcase-unit (3.7, _alternative_templates)'
- 'showcase-unit (3.8, _alternative_templates)'
- 'showcase-unit (3.9, _alternative_templates)'
- 'showcase-unit (3.10, _alternative_templates)'
- 'showcase-unit (3.11, _alternative_templates)'
- 'showcase-unit (3.12, _alternative_templates)'
- 'showcase-unit (3.13, _alternative_templates)'
- 'showcase-unit (3.7, _alternative_templates_mixins)'
- 'showcase-unit (3.8, _alternative_templates_mixins)'
- 'showcase-unit (3.9, _alternative_templates_mixins)'
- 'showcase-unit (3.10, _alternative_templates_mixins)'
- 'showcase-unit (3.11, _alternative_templates_mixins)'
- 'showcase-unit (3.12, _alternative_templates_mixins)'
- 'showcase-unit (3.13, _alternative_templates_mixins)'
- 'showcase-unit (3.7, _mixins)'
- 'showcase-unit (3.8, _mixins)'
- 'showcase-unit (3.9, _mixins)'
- 'showcase-unit (3.10, _mixins)'
- 'showcase-unit (3.11, _mixins)'
- 'showcase-unit (3.12, _mixins)'
- 'showcase-unit (3.13, _mixins)'
- 'showcase-unit (3.7, _w_rest_async)'
- 'showcase-unit (3.8, _w_rest_async)'
- 'showcase-unit (3.9, _w_rest_async)'
- 'showcase-unit (3.10, _w_rest_async)'
- 'showcase-unit (3.11, _w_rest_async)'
- 'showcase-unit (3.12, _w_rest_async)'
- 'showcase-unit (3.13, _w_rest_async)'
- 'showcase-unit-add-iam-methods'
- 'integration'
- 'goldens-lint'
Expand All @@ -67,18 +73,21 @@ branchProtectionRules:
- 'unit (3.10)'
- 'unit (3.11)'
- 'unit (3.12)'
- 'unit (3.13)'
- 'fragment (3.7)'
- 'fragment (3.8)'
- 'fragment (3.9)'
- 'fragment (3.10)'
- 'fragment (3.11)'
- 'fragment (3.12)'
- 'fragment (3.13)'
- 'fragment (3.7, _alternative_templates)'
- 'fragment (3.8, _alternative_templates)'
- 'fragment (3.9, _alternative_templates)'
- 'fragment (3.10, _alternative_templates)'
- 'fragment (3.11, _alternative_templates)'
- 'fragment (3.12, _alternative_templates)'
- 'fragment (3.13, _alternative_templates)'
- 'OwlBot Post Processor'
requiredApprovingReviewCount: 1
requiresCodeOwnerReviews: true
Expand Down
62 changes: 30 additions & 32 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
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"]
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -56,7 +56,7 @@ jobs:
# 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.12"]
python: ["3.7", "3.13"]
target: [showcase, showcase_alternative_templates, showcase_w_rest_async]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -104,10 +104,10 @@ jobs:
run: |
sudo mkdir -p /tmp/workspace/tests/cert/
sudo chown -R ${USER} /tmp/workspace/
- name: Set up Python "3.12"
- name: Set up Python "3.13"
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.13"
cache: 'pip'
- name: Copy mtls files
run: cp tests/cert/mtls.* /tmp/workspace/tests/cert/
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
showcase-unit:
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
# 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]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -171,10 +171,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python "3.12"
- name: Set up Python "3.13"
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.13"
cache: 'pip'
- name: Install system dependencies.
run: |
Expand All @@ -199,10 +199,10 @@ jobs:
variant: ['', _alternative_templates]
steps:
- uses: actions/checkout@v4
- name: Set up Python "3.12"
- name: Set up Python "3.13"
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.13"
cache: 'pip'
- name: Install system dependencies.
run: |
Expand All @@ -224,10 +224,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python "3.12"
- name: Set up Python "3.13"
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.13"
cache: 'pip'
- name: Install system dependencies.
run: |
Expand All @@ -240,7 +240,7 @@ jobs:
unit:
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -261,7 +261,7 @@ jobs:
fragment:
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
variant: ['', _alternative_templates]
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -313,29 +313,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.13"
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.12 blacken lint
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-3.12 blacken lint
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-3.12 blacken lint
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-3.12 blacken lint
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-3.12 blacken lint
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
goldens-unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.13"
cache: 'pip'
- name: Install nox.
run: |
Expand All @@ -345,18 +345,18 @@ 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.12
nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-3.12
nox -f tests/integration/goldens/logging/noxfile.py -s unit-3.12
nox -f tests/integration/goldens/redis/noxfile.py -s unit-3.12
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
goldens-prerelease:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: "3.13"
cache: 'pip'
- name: Install nox.
run: |
Expand All @@ -374,12 +374,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python "3.11"
- name: Set up Python "3.13"
uses: actions/setup-python@v5
with:
# Do not upgrade this check to python 3.12 until
# https://github.com/hhatto/autopep8/issues/712 is fixed
python-version: "3.11"
python-version: "3.13"
cache: 'pip'
- name: Install autopep8
run: |
Expand Down
1 change: 1 addition & 0 deletions gapic/ads-templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ALL_PYTHON = [
"3.10",
"3.11",
"3.12",
"3.13",
]

@nox.session(python=ALL_PYTHON)
Expand Down
1 change: 1 addition & 0 deletions gapic/ads-templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ setuptools.setup(
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: OS Independent",
"Topic :: Internet",
],
Expand Down
2 changes: 1 addition & 1 deletion gapic/samplegen/samplegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ def _fill_sample_metadata(sample: dict, api_schema: api.API):
if not method.void:
snippet_metadata.client_method.result_type = method.client_output_async.ident.sphinx if async_ else method.client_output.ident.sphinx
if method.server_streaming:
snippet_metadata.client_method.result_type = f"Iterable[{snippet_metadata.client_method.result_type }]"
snippet_metadata.client_method.result_type = f"Iterable[{snippet_metadata.client_method.result_type}]"

# Client Method Parameters
parameters = snippet_metadata.client_method.parameters
Expand Down
12 changes: 7 additions & 5 deletions gapic/templates/noxfile.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ ALL_PYTHON = [
"3.9",
"3.10",
"3.11",
"3.12"
"3.12",
"3.13",
]

CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
Expand All @@ -28,7 +29,7 @@ PACKAGE_NAME = '{{ api.naming.warehouse_package_name }}'

BLACK_VERSION = "black==22.3.0"
BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"]
DEFAULT_PYTHON_VERSION = "3.12"
DEFAULT_PYTHON_VERSION = "3.13"

nox.sessions = [
"unit",
Expand All @@ -50,7 +51,7 @@ nox.sessions = [
def unit(session, protobuf_implementation):
"""Run the unit test suite."""

if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12"):
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"):
session.skip("cpp implementation is not supported in python 3.11+")

session.install('coverage', 'pytest', 'pytest-cov', 'pytest-asyncio', 'asyncmock; python_version < "3.8"')
Expand Down Expand Up @@ -84,7 +85,7 @@ def unit(session, protobuf_implementation):
def prerelease_deps(session, protobuf_implementation):
"""Run the unit test suite against pre-release versions of dependencies."""

if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12"):
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"):
session.skip("cpp implementation is not supported in python 3.11+")

# Install test environment dependencies
Expand Down Expand Up @@ -119,7 +120,8 @@ def prerelease_deps(session, protobuf_implementation):
"googleapis-common-protos",
"google-api-core",
"google-auth",
"grpcio",
# Exclude grpcio!=1.67.0rc1 which does not support python 3.13
"grpcio!=1.67.0rc1",
"grpcio-status",
"protobuf",
"proto-plus",
Expand Down
2 changes: 2 additions & 0 deletions gapic/templates/setup.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies = [
# See https://github.com/googleapis/google-cloud-python/issues/12364
"google-auth >= 2.14.1, <3.0.0dev,!=2.24.0,!=2.25.0",
"proto-plus >= 1.22.3, <2.0.0dev",
"proto-plus >= 1.25.0, <2.0.0dev; python_version >= '3.13'",
{# Explicitly exclude protobuf versions mentioned in https://cloud.google.com/support/bulletins#GCP-2022-019 #}
"protobuf>=3.20.2,<6.0.0dev,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
{% for package_tuple, package_info in pypi_packages.items() %}
Expand Down Expand Up @@ -91,6 +92,7 @@ setuptools.setup(
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: OS Independent",
"Topic :: Internet",
],
Expand Down
4 changes: 4 additions & 0 deletions gapic/templates/testing/constraints-3.13.txt.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
{% block constraints %}
{% include "testing/_default_constraints.j2" %}
{% endblock %}
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"3.10",
"3.11",
"3.12",
"3.13",
)

NEWEST_PYTHON = ALL_PYTHON[-1]
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: OS Independent",
"Topic :: Software Development :: Code Generators",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand Down
Loading

0 comments on commit 4e1f9c6

Please sign in to comment.