Skip to content

Commit 98fc6fe

Browse files
committed
add core_deps_from_source nox session
1 parent 97ff1b8 commit 98fc6fe

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

packages/google-api-core/noxfile.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232

3333
DEFAULT_PYTHON_VERSION = "3.14"
3434
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
35+
UNIT_TEST_STANDARD_DEPENDENCIES = [
36+
"mock",
37+
"asyncmock",
38+
"pytest",
39+
"pytest-cov",
40+
"pytest-asyncio",
41+
]
3542

3643
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
3744
nox.options.sessions = [
@@ -377,3 +384,69 @@ def docfx(session):
377384
os.path.join("docs", ""),
378385
os.path.join("docs", "_build", "html", ""),
379386
)
387+
388+
@nox.session(python=DEFAULT_PYTHON_VERSION)
389+
@nox.parametrize(
390+
"protobuf_implementation",
391+
["python", "upb"],
392+
)
393+
def core_deps_from_source(session, protobuf_implementation):
394+
"""Run all tests with core dependencies installed from source
395+
rather than pulling the dependencies from PyPI.
396+
"""
397+
398+
# Install all dependencies
399+
session.install("-e", ".")
400+
401+
# Install dependencies for the unit test environment
402+
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES
403+
session.install(*unit_deps_all)
404+
405+
# Because we test minimum dependency versions on the minimum Python
406+
# version, the first version we test with in the unit tests sessions has a
407+
# constraints file containing all dependencies and extras.
408+
with open(
409+
CURRENT_DIRECTORY
410+
/ "testing"
411+
/ f"constraints-{PYTHON_VERSIONS[0]}.txt",
412+
encoding="utf-8",
413+
) as constraints_file:
414+
constraints_text = constraints_file.read()
415+
416+
# Ignore leading whitespace and comment lines.
417+
constraints_deps = [
418+
match.group(1)
419+
for match in re.finditer(
420+
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
421+
)
422+
]
423+
424+
# Install dependencies specified in `testing/constraints-X.txt`.
425+
session.install(*constraints_deps)
426+
427+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2358): `grpcio` and
428+
# `grpcio-status` should be added to the list below so that they are installed from source,
429+
# rather than PyPI.
430+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2357): `protobuf` should be
431+
# added to the list below so that it is installed from source, rather than PyPI
432+
# Note: If a dependency is added to the `core_dependencies_from_source` list,
433+
# the `prerel_deps` list in the `prerelease_deps` nox session should also be updated.
434+
core_dependencies_from_source = [
435+
f"{CURRENT_DIRECTORY}/../googleapis-common-protos",
436+
f"{CURRENT_DIRECTORY}/../google-api-core",
437+
"google-auth @ git+https://github.com/googleapis/google-auth-library-python.git",
438+
f"{CURRENT_DIRECTORY}/../grpc-google-iam-v1",
439+
"proto-plus @ git+https://github.com/googleapis/proto-plus-python.git",
440+
]
441+
442+
for dep in core_dependencies_from_source:
443+
session.install(dep, "--no-deps", "--ignore-installed")
444+
print(f"Installed {dep}")
445+
446+
session.run(
447+
"py.test",
448+
"tests/unit",
449+
env={
450+
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
451+
},
452+
)

0 commit comments

Comments
 (0)