Skip to content

Commit 0f9f80b

Browse files
ohmayrparthea
andauthored
feat: add support for python 3.12 (#1816)
Co-authored-by: omair <[email protected]> Co-authored-by: Anthonios Partheniou <[email protected]>
1 parent 4b18f02 commit 0f9f80b

File tree

20 files changed

+96
-117
lines changed

20 files changed

+96
-117
lines changed

packages/gapic-generator/.github/sync-repo-settings.yaml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ branchProtectionRules:
77
requiredStatusCheckContexts:
88
- 'cla/google'
99
- 'docs'
10-
- 'mypy'
11-
- 'showcase (showcase)'
12-
- 'showcase (showcase_alternative_templates)'
10+
- 'mypy (3.8)'
11+
- 'mypy (3.9)'
12+
- 'mypy (3.10)'
13+
- 'mypy (3.11)'
14+
- 'mypy (3.12)'
15+
- 'showcase (3.7, showcase)'
16+
- 'showcase (3.12, showcase)'
17+
- 'showcase (3.7, showcase_alternative_templates)'
18+
- 'showcase (3.12, showcase_alternative_templates)'
1319
# TODO(dovs): reenable these when the mtls tests have been debugged and fixed
1420
# See #1218 for details
1521
# - 'showcase-mtls (showcase_mtls)'
@@ -21,21 +27,25 @@ branchProtectionRules:
2127
- 'showcase-unit (3.9)'
2228
- 'showcase-unit (3.10)'
2329
- 'showcase-unit (3.11)'
30+
- 'showcase-unit (3.12)'
2431
- 'showcase-unit (3.7, _alternative_templates)'
2532
- 'showcase-unit (3.8, _alternative_templates)'
2633
- 'showcase-unit (3.9, _alternative_templates)'
2734
- 'showcase-unit (3.10, _alternative_templates)'
2835
- 'showcase-unit (3.11, _alternative_templates)'
36+
- 'showcase-unit (3.12, _alternative_templates)'
2937
- 'showcase-unit (3.7, _alternative_templates_mixins)'
3038
- 'showcase-unit (3.8, _alternative_templates_mixins)'
3139
- 'showcase-unit (3.9, _alternative_templates_mixins)'
3240
- 'showcase-unit (3.10, _alternative_templates_mixins)'
3341
- 'showcase-unit (3.11, _alternative_templates_mixins)'
42+
- 'showcase-unit (3.12, _alternative_templates_mixins)'
3443
- 'showcase-unit (3.7, _mixins)'
3544
- 'showcase-unit (3.8, _mixins)'
3645
- 'showcase-unit (3.9, _mixins)'
3746
- 'showcase-unit (3.10, _mixins)'
3847
- 'showcase-unit (3.11, _mixins)'
48+
- 'showcase-unit (3.12, _mixins)'
3949
- 'showcase-unit-add-iam-methods'
4050
- 'integration'
4151
- 'goldens-lint'
@@ -46,16 +56,19 @@ branchProtectionRules:
4656
- 'unit (3.9)'
4757
- 'unit (3.10)'
4858
- 'unit (3.11)'
59+
- 'unit (3.12)'
4960
- 'fragment (3.7)'
5061
- 'fragment (3.8)'
5162
- 'fragment (3.9)'
5263
- 'fragment (3.10)'
5364
- 'fragment (3.11)'
65+
- 'fragment (3.12)'
5466
- 'fragment (3.7, _alternative_templates)'
5567
- 'fragment (3.8, _alternative_templates)'
5668
- 'fragment (3.9, _alternative_templates)'
5769
- 'fragment (3.10, _alternative_templates)'
5870
- 'fragment (3.11, _alternative_templates)'
71+
- 'fragment (3.12, _alternative_templates)'
5972
- 'OwlBot Post Processor'
6073
requiredApprovingReviewCount: 1
6174
requiresCodeOwnerReviews: true

packages/gapic-generator/.github/workflows/tests.yaml

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,51 @@ env:
1919

2020
jobs:
2121
docs:
22-
# Don't upgrade python version; there's a bug in 3.10 sphinx
2322
runs-on: ubuntu-latest
2423
steps:
2524
- uses: actions/checkout@v4
2625
- name: Set up Python
2726
uses: actions/setup-python@v4
27+
# Use python 3.10 for docs to match the version for the sphinx plugin
28+
# https://github.com/googleapis/synthtool/pull/1891
2829
with:
29-
python-version: "3.9"
30+
python-version: "3.10"
3031
cache: 'pip'
3132
- name: Install nox.
3233
run: python -m pip install nox
3334
- name: Build the documentation.
3435
run: nox -s docs
3536
mypy:
37+
strategy:
38+
matrix:
39+
# Run mypy on all of the supported python versions listed in setup.py
40+
# https://github.com/python/mypy/blob/master/setup.py
41+
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
3642
runs-on: ubuntu-latest
3743
steps:
3844
- uses: actions/checkout@v4
39-
- name: Set up Python "3.11"
45+
- name: Set up Python "${{ matrix.python }}"
4046
uses: actions/setup-python@v4
4147
with:
42-
python-version: "3.11"
48+
python-version: "${{ matrix.python }}"
4349
cache: 'pip'
4450
- name: Install nox.
4551
run: python -m pip install nox
4652
- name: Check type annotations.
47-
run: nox -s mypy
53+
run: nox -s mypy-${{ matrix.python }}
4854
showcase:
4955
strategy:
56+
# Run showcase tests on the lowest and highest supported runtimes
5057
matrix:
58+
python: ["3.7", "3.12"]
5159
target: [showcase, showcase_alternative_templates]
5260
runs-on: ubuntu-latest
5361
steps:
5462
- uses: actions/checkout@v4
55-
- name: Set up Python "3.11"
63+
- name: Set up Python "${{ matrix.python }}"
5664
uses: actions/setup-python@v4
5765
with:
58-
python-version: "3.11"
66+
python-version: "${{ matrix.python }}"
5967
cache: 'pip'
6068
- name: Install system dependencies.
6169
run: |
@@ -81,7 +89,7 @@ jobs:
8189
unzip protoc-${PROTOC_VERSION}.zip
8290
sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
8391
- name: Run showcase tests.
84-
run: nox -s ${{ matrix.target }}
92+
run: nox -s ${{ matrix.target }}-${{ matrix.python }}
8593
showcase-mtls:
8694
if: ${{ false }} # TODO(dovs): reenable when #1218 is fixed
8795
strategy:
@@ -95,10 +103,10 @@ jobs:
95103
run: |
96104
sudo mkdir -p /tmp/workspace/tests/cert/
97105
sudo chown -R ${USER} /tmp/workspace/
98-
- name: Set up Python "3.11"
106+
- name: Set up Python "3.12"
99107
uses: actions/setup-python@v4
100108
with:
101-
python-version: "3.11"
109+
python-version: "3.12"
102110
cache: 'pip'
103111
- name: Copy mtls files
104112
run: cp tests/cert/mtls.* /tmp/workspace/tests/cert/
@@ -131,7 +139,7 @@ jobs:
131139
showcase-unit:
132140
strategy:
133141
matrix:
134-
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
142+
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
135143
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins]
136144
runs-on: ubuntu-latest
137145
steps:
@@ -161,10 +169,10 @@ jobs:
161169
runs-on: ubuntu-latest
162170
steps:
163171
- uses: actions/checkout@v4
164-
- name: Set up Python "3.11"
172+
- name: Set up Python "3.12"
165173
uses: actions/setup-python@v4
166174
with:
167-
python-version: "3.11"
175+
python-version: "3.12"
168176
cache: 'pip'
169177
- name: Install system dependencies.
170178
run: |
@@ -189,10 +197,10 @@ jobs:
189197
variant: ['', _alternative_templates]
190198
steps:
191199
- uses: actions/checkout@v4
192-
- name: Set up Python "3.11"
200+
- name: Set up Python "3.12"
193201
uses: actions/setup-python@v4
194202
with:
195-
python-version: "3.11"
203+
python-version: "3.12"
196204
cache: 'pip'
197205
- name: Install system dependencies.
198206
run: |
@@ -214,10 +222,10 @@ jobs:
214222
runs-on: ubuntu-latest
215223
steps:
216224
- uses: actions/checkout@v4
217-
- name: Set up Python "3.11"
225+
- name: Set up Python "3.12"
218226
uses: actions/setup-python@v4
219227
with:
220-
python-version: "3.11"
228+
python-version: "3.12"
221229
cache: 'pip'
222230
- name: Install system dependencies.
223231
run: |
@@ -230,7 +238,7 @@ jobs:
230238
unit:
231239
strategy:
232240
matrix:
233-
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
241+
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
234242
runs-on: ubuntu-latest
235243
steps:
236244
- uses: actions/checkout@v4
@@ -251,7 +259,7 @@ jobs:
251259
fragment:
252260
strategy:
253261
matrix:
254-
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
262+
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
255263
variant: ['', _alternative_templates]
256264
runs-on: ubuntu-latest
257265
steps:
@@ -303,28 +311,30 @@ jobs:
303311
runs-on: ubuntu-latest
304312
steps:
305313
- uses: actions/checkout@v4
306-
- name: Set up Python 3.11
314+
- name: Set up Python 3.12
307315
uses: actions/setup-python@v4
308316
with:
309-
python-version: "3.11"
317+
python-version: "3.12"
310318
cache: 'pip'
311319
- name: Install nox.
312320
run: |
313321
python -m pip install nox
314322
- name: Run blacken and lint on the generated output.
315323
run: |
316-
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
317-
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
318-
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
319-
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
320-
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-3.11 blacken lint_setup_py lint
324+
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-3.12 blacken lint
325+
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-3.12 blacken lint
326+
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-3.12 blacken lint
327+
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-3.12 blacken lint
328+
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-3.12 blacken lint
321329
style-check:
322330
runs-on: ubuntu-latest
323331
steps:
324332
- uses: actions/checkout@v4
325333
- name: Set up Python "3.11"
326334
uses: actions/setup-python@v4
327335
with:
336+
# Do not upgrade this check to python 3.12 until
337+
# https://github.com/hhatto/autopep8/issues/712 is fixed
328338
python-version: "3.11"
329339
cache: 'pip'
330340
- name: Install autopep8

packages/gapic-generator/gapic/ads-templates/noxfile.py.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ALL_PYTHON = [
1313
"3.9",
1414
"3.10",
1515
"3.11",
16+
"3.12",
1617
]
1718

1819
@nox.session(python=ALL_PYTHON)

packages/gapic-generator/gapic/ads-templates/setup.py.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ setuptools.setup(
4747
'Programming Language :: Python :: 3.9',
4848
'Programming Language :: Python :: 3.10',
4949
'Programming Language :: Python :: 3.11',
50+
'Programming Language :: Python :: 3.12',
5051
'Topic :: Internet',
5152
'Topic :: Software Development :: Libraries :: Python Modules',
5253
],

packages/gapic-generator/gapic/schema/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def convert_to_versioned_package(self) -> Tuple[str, ...]:
178178
# underscore between the module and the version. For example,
179179
# change google.cloud.documentai.v1 to google.cloud.documentai_v1.
180180
# Check if the package name contains a version.
181-
version_regex = "^v\d[^/]*$"
181+
version_regex = r"^v\d[^/]*$"
182182
regex_match = re.match(version_regex, self.package[-1])
183183
if regex_match and len(self.package) > 1:
184184
versioned_module = f"{self.package[-2]}_{regex_match[0]}"

packages/gapic-generator/gapic/templates/noxfile.py.j2

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ ALL_PYTHON = [
1717
"3.9",
1818
"3.10",
1919
"3.11",
20+
"3.12"
2021
]
2122

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

2425
LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
25-
PACKAGE_NAME = subprocess.check_output([sys.executable, "setup.py", "--name"], encoding="utf-8")
26+
PACKAGE_NAME = '{{ api.naming.warehouse_package_name }}'
2627

2728
BLACK_VERSION = "black==22.3.0"
2829
BLACK_PATHS = ["docs", "google", "tests", "samples", "noxfile.py", "setup.py"]
29-
DEFAULT_PYTHON_VERSION = "3.11"
30+
DEFAULT_PYTHON_VERSION = "3.12"
3031

3132
nox.sessions = [
3233
"unit",
@@ -37,7 +38,6 @@ nox.sessions = [
3738
"docs",
3839
"blacken",
3940
"lint",
40-
"lint_setup_py",
4141
]
4242

4343
@nox.session(python=ALL_PYTHON)
@@ -82,7 +82,7 @@ def mypy(session):
8282
session.install('.')
8383
session.run(
8484
'mypy',
85-
'--explicit-package-bases',
85+
'-p',
8686
{% if api.naming.module_namespace %}
8787
'{{ api.naming.module_namespace[0] }}',
8888
{% else %}
@@ -169,11 +169,4 @@ def blacken(session):
169169
*BLACK_PATHS,
170170
)
171171

172-
173-
@nox.session(python=DEFAULT_PYTHON_VERSION)
174-
def lint_setup_py(session):
175-
"""Verify that setup.py is valid (including RST check)."""
176-
session.install("docutils", "pygments")
177-
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
178-
179172
{% endblock %}

packages/gapic-generator/gapic/templates/setup.py.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ packages = [
5555
if package.startswith("{{ api.naming.namespace_packages|first }}")
5656
]
5757

58-
namespaces = [{% for namespace_packages in api.naming.namespace_packages %}"{{ namespace_packages }}"{% if not loop.last %}, {% endif %}{% endfor %}]
59-
6058
setuptools.setup(
6159
name=name,
6260
version=version,
@@ -77,6 +75,7 @@ setuptools.setup(
7775
"Programming Language :: Python :: 3.9",
7876
"Programming Language :: Python :: 3.10",
7977
"Programming Language :: Python :: 3.11",
78+
"Programming Language :: Python :: 3.12",
8079
"Operating System :: OS Independent",
8180
"Topic :: Internet",
8281
],

0 commit comments

Comments
 (0)