Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed Jun 11, 2024
1 parent ba45234 commit 4218608
Showing 1 changed file with 59 additions and 58 deletions.
117 changes: 59 additions & 58 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,70 +49,75 @@ def lint_setup_py(session):

def unit(session, repository, package, prerelease, protobuf_implementation):
"""Run the unit test suite."""
# Install all test dependencies, then install this package in-place.
session.install("asyncmock", "pytest-asyncio")

# Pin mock due to https://github.com/googleapis/python-pubsub/issues/840
session.install("mock==5.0.0", "pytest", "pytest-cov")

downstream_dir = repository
if package:
downstream_parent_dir = f"{CURRENT_DIRECTORY}/{repository}/packages/{package}"
else:
downstream_parent_dir = f"{CURRENT_DIRECTORY}/{repository}"
downstream_dir = f"{repository}/packages/{package}"
with session.chdir(downstream_dir):
# Install all test dependencies, then install this package in-place.
session.install("asyncmock", "pytest-asyncio")

install_command = ["-e", downstream_parent_dir]
# Pin mock due to https://github.com/googleapis/python-pubsub/issues/840
session.install("mock==5.0.0", "pytest", "pytest-cov")

if prerelease:
install_prerelease_dependencies(
session,
f"{downstream_parent_dir}/testing/constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
)
# Use the `--no-deps` options to install googleapis-api-common-protos without dependencies
# since we are using pre-release versions of dependencies
install_command.extend(["--no-deps"])
else:
# Install the pinned dependencies in constraints file
install_command.extend(
["-c", f"{downstream_parent_dir}/testing/constraints-{session.python}.txt"]
)
if package:
downstream_parent_dir = f"{CURRENT_DIRECTORY}/{repository}/packages/{package}"
else:
downstream_parent_dir = f"{CURRENT_DIRECTORY}/{repository}"

# These *must* be the last 3 install commands to get the packages from source.
session.install(*install_command)
install_command = ["-e", downstream_parent_dir]

# 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")
if prerelease:
install_prerelease_dependencies(
session,
f"{downstream_parent_dir}/testing/constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
)
# Use the `--no-deps` options to allow pre-release versions of dependencies to be installed
install_command.extend(["--no-deps"])
else:
# Install the pinned dependencies in constraints file
install_command.extend(
["-c", f"{downstream_parent_dir}/testing/constraints-{session.python}.txt"]
)

session.install(".", "--no-deps")
# These *must* be the last 3 install commands to get the packages from source.
session.install(*install_command)

# Print out package versions of dependencies
session.run(
"python", "-c", "import google.protobuf; print(google.protobuf.__version__)"
)
session.run("python", "-c", "import grpc; print(grpc.__version__)")
session.run("python", "-c", "import google.auth; print(google.auth.__version__)")
# 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(
"python", "-c", "import google.api_core; print(google.api_core.__version__)"
)
session.install(".", "--no-deps", "--ignore-installed")

# Run py.test against the unit tests.
session.run(
"py.test",
"--quiet",
"--cov=google/cloud",
"--cov=tests/unit",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=0",
os.path.join("tests", "unit"),
*session.posargs,
env={
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
},
)
with session.chdir(downstream_dir):
# Print out package versions of dependencies
session.run(
"python", "-c", "import google.protobuf; print(google.protobuf.__version__)"
)
session.run("python", "-c", "import grpc; print(grpc.__version__)")
session.run("python", "-c", "import google.auth; print(google.auth.__version__)")

session.run(
"python", "-c", "import google.api_core; print(google.api_core.__version__)"
)

# Run py.test against the unit tests.
session.run(
"py.test",
"--quiet",
"--cov=google/cloud",
"--cov=tests/unit",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=0",
os.path.join("tests", "unit"),
*session.posargs,
env={
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
},
)


def install_prerelease_dependencies(session, constraints_path):
Expand Down Expand Up @@ -198,10 +203,6 @@ def test(session, library, prerelease, protobuf_implementation):
external=True,
)

session.cd(repository)
if package:
session.cd(f"packages/{package}")

unit(session=session, repository=repository, package=package, prerelease=prerelease, protobuf_implementation=protobuf_implementation)


Expand Down

0 comments on commit 4218608

Please sign in to comment.