This repository was archived by the owner on Aug 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathnoxfile.py.j2
More file actions
275 lines (228 loc) · 7.57 KB
/
Copy pathnoxfile.py.j2
File metadata and controls
275 lines (228 loc) · 7.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
{% extends "_base.py.j2" %}
{% block content %}
import os
import pathlib
import re
import shutil
import subprocess
import sys
import nox # type: ignore
ALL_PYTHON = [
"3.7",
"3.8",
"3.9",
"3.10",
"3.11",
"3.12"
]
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
LOWER_BOUND_CONSTRAINTS_FILE = CURRENT_DIRECTORY / "constraints.txt"
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"
nox.sessions = [
"unit",
"cover",
"mypy",
"check_lower_bounds"
# exclude update_lower_bounds from default
"docs",
"blacken",
"lint",
"prerelease_deps",
]
@nox.session(python=ALL_PYTHON)
@nox.parametrize(
"protobuf_implementation",
[ "python", "upb", "cpp" ],
)
def unit(session, protobuf_implementation):
"""Run the unit test suite."""
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12"):
session.skip("cpp implementation is not supported in python 3.11+")
session.install('coverage', 'pytest', 'pytest-cov', 'pytest-asyncio', 'asyncmock; python_version < "3.8"')
session.install('-e', '.', "-c", f"testing/constraints-{session.python}.txt")
# Remove the 'cpp' implementation once support for Protobuf 3.x is dropped.
# The 'cpp' implementation requires Protobuf<4.
if protobuf_implementation == "cpp":
session.install("protobuf<4")
session.run(
'py.test',
'--quiet',
'--cov={{ api.naming.module_namespace|join("/") }}/{{ api.naming.versioned_module_name }}/',
'--cov=tests/',
'--cov-config=.coveragerc',
'--cov-report=term',
'--cov-report=html',
os.path.join('tests', 'unit', ''.join(session.posargs)),
env={
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
},
)
@nox.session(python=ALL_PYTHON[-1])
@nox.parametrize(
"protobuf_implementation",
[ "python", "upb", "cpp" ],
)
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"):
session.skip("cpp implementation is not supported in python 3.11+")
# Install test environment dependencies
session.install('coverage', 'pytest', 'pytest-cov', 'pytest-asyncio', 'asyncmock; python_version < "3.8"')
# Install the package without dependencies
session.install('-e', '.', '--no-deps')
# We test the minimum dependency versions using the minimum Python
# version so the lowest python runtime that we test has a corresponding constraints
# file, located at `testing/constraints-<version>-.txt`, which contains all of the
# dependencies and extras.
with open(
CURRENT_DIRECTORY
/ "testing"
/ f"constraints-{ALL_PYTHON[0]}.txt",
encoding="utf-8",
) as constraints_file:
constraints_text = constraints_file.read()
# Ignore leading whitespace and comment lines.
constraints_deps = [
match.group(1)
for match in re.finditer(
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
)
]
session.install(*constraints_deps)
prerel_deps = [
"googleapis-common-protos",
"google-api-core",
"google-auth",
"grpcio",
"grpcio-status",
"protobuf",
"proto-plus",
]
for dep in prerel_deps:
session.install("--pre", "--no-deps", "--upgrade", dep)
# Remaining dependencies
other_deps = [
"requests",
]
session.install(*other_deps)
# Print out prerelease package versions
session.run("python", "-c", "import google.api_core; print(google.api_core.__version__)")
session.run("python", "-c", "import google.auth; print(google.auth.__version__)")
session.run("python", "-c", "import grpc; print(grpc.__version__)")
session.run(
"python", "-c", "import google.protobuf; print(google.protobuf.__version__)"
)
session.run(
"python", "-c", "import proto; print(proto.__version__)"
)
session.run(
'py.test',
'--quiet',
'--cov={{ api.naming.module_namespace|join("/") }}/{{ api.naming.versioned_module_name }}/',
'--cov=tests/',
'--cov-config=.coveragerc',
'--cov-report=term',
'--cov-report=html',
os.path.join('tests', 'unit', ''.join(session.posargs)),
env={
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
},
)
@nox.session(python=DEFAULT_PYTHON_VERSION)
def cover(session):
"""Run the final coverage report.
This outputs the coverage report aggregating coverage from the unit
test runs (not system test runs), and then erases coverage data.
"""
session.install("coverage", "pytest-cov")
session.run("coverage", "report", "--show-missing", "--fail-under=100")
session.run("coverage", "erase")
@nox.session(python=ALL_PYTHON)
def mypy(session):
"""Run the type checker."""
session.install(
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2066):
# Ignore release of mypy 1.11.0 which may have a regression
'mypy!=1.11.0',
'types-requests',
'types-protobuf'
)
session.install('.')
session.run(
'mypy',
'-p',
{% if api.naming.module_namespace %}
'{{ api.naming.module_namespace[0] }}',
{% else %}
'{{ api.naming.versioned_module_name }}',
{% endif %}
)
@nox.session
def update_lower_bounds(session):
"""Update lower bounds in constraints.txt to match setup.py"""
session.install('google-cloud-testutils')
session.install('.')
session.run(
'lower-bound-checker',
'update',
'--package-name',
PACKAGE_NAME,
'--constraints-file',
str(LOWER_BOUND_CONSTRAINTS_FILE),
)
@nox.session
def check_lower_bounds(session):
"""Check lower bounds in setup.py are reflected in constraints file"""
session.install('google-cloud-testutils')
session.install('.')
session.run(
'lower-bound-checker',
'check',
'--package-name',
PACKAGE_NAME,
'--constraints-file',
str(LOWER_BOUND_CONSTRAINTS_FILE),
)
@nox.session(python=DEFAULT_PYTHON_VERSION)
def docs(session):
"""Build the docs for this library."""
session.install("-e", ".")
session.install("sphinx==7.0.1", "alabaster", "recommonmark")
shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
session.run(
"sphinx-build",
"-W", # warnings as errors
"-T", # show full traceback on exception
"-N", # no colors
"-b",
"html",
"-d",
os.path.join("docs", "_build", "doctrees", ""),
os.path.join("docs", ""),
os.path.join("docs", "_build", "html", ""),
)
@nox.session(python=DEFAULT_PYTHON_VERSION)
def lint(session):
"""Run linters.
Returns a failure if the linters find linting errors or sufficiently
serious code quality issues.
"""
session.install("flake8", BLACK_VERSION)
session.run(
"black",
"--check",
*BLACK_PATHS,
)
session.run("flake8", "google", "tests", "samples")
@nox.session(python=DEFAULT_PYTHON_VERSION)
def blacken(session):
"""Run black. Format code to uniform standard."""
session.install(BLACK_VERSION)
session.run(
"black",
*BLACK_PATHS,
)
{% endblock %}