Skip to content

Commit b6e857d

Browse files
authored
chore: add prerelease_deps nox sessions (#17267)
This PR implements nox sessions for `core_deps_from_source` and `prerelease_deps`. Fixes #16013🦕
1 parent d6aaf61 commit b6e857d

1 file changed

Lines changed: 85 additions & 9 deletions

File tree

packages/google-auth/noxfile.py

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import os
1616
import pathlib
17+
import re
1718
import shutil
1819

1920
import nox
@@ -33,6 +34,12 @@
3334
]
3435

3536
DEFAULT_PYTHON_VERSION = "3.14"
37+
38+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2450):
39+
# Switch this to Python 3.15 alpha1
40+
# https://peps.python.org/pep-0790/
41+
PREVIEW_PYTHON_VERSION = "3.14"
42+
3643
UNIT_TEST_PYTHON_VERSIONS = [
3744
"3.10",
3845
"3.11",
@@ -42,6 +49,15 @@
4249
]
4350
ALL_PYTHON = UNIT_TEST_PYTHON_VERSIONS.copy()
4451

52+
UNIT_TEST_STANDARD_DEPENDENCIES = [
53+
"mock",
54+
"asyncmock",
55+
"pytest",
56+
"pytest-cov",
57+
"pytest-asyncio",
58+
]
59+
UNIT_TEST_EXTERNAL_DEPENDENCIES: list[str] = []
60+
4561
# Error if a python version is missing
4662
nox.options.error_on_missing_interpreters = True
4763

@@ -220,23 +236,83 @@ def docfx(session):
220236
session.skip("This package does not have documentation in cloud.google.com")
221237

222238

223-
@nox.session(python=DEFAULT_PYTHON_VERSION)
224-
def prerelease_deps(session):
225-
"""Run all tests with pre-release versions of dependencies installed
239+
@nox.session(python=PREVIEW_PYTHON_VERSION)
240+
@nox.parametrize(
241+
"protobuf_implementation",
242+
["python", "upb"],
243+
)
244+
def prerelease_deps(session, protobuf_implementation):
245+
"""
246+
Run all tests with pre-release versions of dependencies installed
226247
rather than the standard non pre-release versions.
227248
Pre-release versions can be installed using
228249
`pip install --pre <package>`.
229250
"""
230-
# TODO(https://github.com/googleapis/google-cloud-python/issues/16013):
231-
# Add prerelease tests
232-
session.skip("Prerelease tests are not yet supported")
251+
252+
# Install all dependencies
253+
session.install("-e", ".[testing,rsa]")
254+
session.install("oauth2client")
255+
256+
# Install dependencies for the unit test environment
257+
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
258+
session.install(*unit_deps_all)
259+
260+
# Because we test minimum dependency versions on the minimum Python
261+
# version, the first version we test with in the unit tests sessions has a
262+
# constraints file containing all dependencies and extras.
263+
with open(
264+
CURRENT_DIRECTORY / "testing" / f"constraints-{ALL_PYTHON[0]}.txt",
265+
encoding="utf-8",
266+
) as constraints_file:
267+
constraints_text = constraints_file.read()
268+
269+
# Ignore leading whitespace and comment lines.
270+
constraints_deps = [
271+
match.group(1)
272+
for match in re.finditer(
273+
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
274+
)
275+
]
276+
277+
# Install dependencies specified in `testing/constraints-X.txt`.
278+
session.install(*constraints_deps)
279+
280+
# Note: If a dependency is added to the `prerel_deps` list,
281+
# the `core_dependencies_from_source` list in the `core_deps_from_source`
282+
# nox session should also be updated.
283+
prerel_deps = [
284+
# Note: We use --no-deps below to prevent prerelease updates.
285+
# However, aiohttp 3.10+ introduced aiohappyeyeballs as a strict requirement.
286+
# We must manually inject it here so the aiohttp pre-release doesn't crash on import.
287+
"aiohappyeyeballs",
288+
"aiohttp",
289+
"cryptography",
290+
"grpcio",
291+
"pyasn1-modules",
292+
"pyjwt",
293+
"pyopenssl",
294+
"requests",
295+
"rsa",
296+
"urllib3",
297+
]
298+
299+
for dep in prerel_deps:
300+
session.install("--pre", "--no-deps", "--ignore-installed", dep)
301+
print(f"Installed {dep}")
302+
303+
session.run(
304+
"py.test",
305+
"tests",
306+
"tests_async",
307+
env={
308+
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
309+
},
310+
)
233311

234312

235313
@nox.session(python=DEFAULT_PYTHON_VERSION)
236314
def core_deps_from_source(session):
237315
"""Run all tests with core dependencies installed from source
238316
rather than pulling the dependencies from PyPI.
239317
"""
240-
# TODO(https://github.com/googleapis/google-cloud-python/issues/16013):
241-
# Add prerelease tests
242-
session.skip("Prerelease tests are not yet supported")
318+
session.skip("Skipping: Not applicable for google-auth.")

0 commit comments

Comments
 (0)