Skip to content

Commit

Permalink
fix: drop support for grpc-gcp (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea authored Jun 13, 2022
1 parent e92045b commit 5da6733
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 116 deletions.
5 changes: 0 additions & 5 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ branchProtectionRules:
- 'unit-3.8'
- 'unit-3.9'
- 'unit-3.10'
- 'unit_grpc_gcp-3.6'
- 'unit_grpc_gcp-3.7'
- 'unit_grpc_gcp-3.8'
- 'unit_grpc_gcp-3.9'
- 'unit_grpc_gcp-3.10'
- 'unit_wo_grpc-3.6'
- 'unit_wo_grpc-3.10'
- 'cover'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
option: ["", "_grpc_gcp", "_wo_grpc"]
option: ["", "_wo_grpc"]
python:
- "3.6"
- "3.7"
Expand Down
17 changes: 2 additions & 15 deletions google/api_core/grpc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
import google.auth.transport.grpc
import google.auth.transport.requests

try:
import grpc_gcp

HAS_GRPC_GCP = True
except ImportError:
HAS_GRPC_GCP = False


# The list of gRPC Callable interfaces that return iterators.
_STREAM_WRAP_CLASSES = (grpc.UnaryStreamMultiCallable, grpc.StreamStreamMultiCallable)
Expand Down Expand Up @@ -282,8 +275,7 @@ def create_channel(
default_scopes (Sequence[str]): Default scopes passed by a Google client
library. Use 'scopes' for user-defined scopes.
default_host (str): The default endpoint. e.g., "pubsub.googleapis.com".
kwargs: Additional key-word args passed to
:func:`grpc_gcp.secure_channel` or :func:`grpc.secure_channel`.
kwargs: Additional key-word args passed to :func:`grpc.secure_channel`.
Returns:
grpc.Channel: The created channel.
Expand All @@ -302,12 +294,7 @@ def create_channel(
default_host=default_host,
)

if HAS_GRPC_GCP:
# If grpc_gcp module is available use grpc_gcp.secure_channel,
# otherwise, use grpc.secure_channel to create grpc channel.
return grpc_gcp.secure_channel(target, composite_credentials, **kwargs)
else:
return grpc.secure_channel(target, composite_credentials, **kwargs)
return grpc.secure_channel(target, composite_credentials, **kwargs)


_MethodCall = collections.namedtuple(
Expand Down
3 changes: 0 additions & 3 deletions google/api_core/grpc_helpers_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
from google.api_core import exceptions, grpc_helpers


# TODO(lidiz) Support gRPC GCP wrapper
HAS_GRPC_GCP = False

# NOTE(lidiz) Alternatively, we can hack "__getattribute__" to perform
# automatic patching for us. But that means the overhead of creating an
# extra Python function spreads to every single send and receive.
Expand Down
19 changes: 3 additions & 16 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
# 'docfx' is excluded since it only needs to run in 'docs-presubmit'
nox.options.sessions = [
"unit",
"unit_grpc_gcp",
"unit_wo_grpc",
"cover",
"pytype",
Expand Down Expand Up @@ -143,18 +142,6 @@ def unit(session):
default(session)


@nox.session(python=["3.6", "3.7", "3.8", "3.9", "3.10"])
def unit_grpc_gcp(session):
"""Run the unit test suite with grpcio-gcp installed."""
constraints_path = str(
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
)
# Install grpcio-gcp
session.install("-e", ".[grpcgcp]", "-c", constraints_path)

default(session)


@nox.session(python=["3.6", "3.10"])
def unit_wo_grpc(session):
"""Run the unit test suite w/o grpcio installed"""
Expand All @@ -173,14 +160,14 @@ def lint_setup_py(session):
@nox.session(python="3.6")
def pytype(session):
"""Run type-checking."""
session.install(".[grpc, grpcgcp]", "pytype >= 2019.3.21")
session.install(".[grpc]", "pytype >= 2019.3.21")
session.run("pytype")


@nox.session(python=DEFAULT_PYTHON_VERSION)
def mypy(session):
"""Run type-checking."""
session.install(".[grpc, grpcgcp]", "mypy")
session.install(".[grpc]", "mypy")
session.install(
"types-setuptools",
"types-requests",
Expand All @@ -207,7 +194,7 @@ def cover(session):
def docs(session):
"""Build the docs for this library."""

session.install("-e", ".[grpc, grpcgcp]")
session.install("-e", ".[grpc]")
session.install("sphinx==4.0.1", "alabaster", "recommonmark")

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
]
extras = {
"grpc": ["grpcio >= 1.33.2, < 2.0dev", "grpcio-status >= 1.33.2, < 2.0dev"],
"grpcgcp": "grpcio-gcp >= 0.2.2, < 1.0dev",
"grpcio-gcp": "grpcio-gcp >= 0.2.2, < 1.0dev",
}


Expand Down
2 changes: 0 additions & 2 deletions testing/constraints-3.6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ google-auth==1.25.0
requests==2.18.0
packaging==14.3
grpcio==1.33.2
grpcio-gcp==0.2.2
grpcio-gcp==0.2.2
grpcio-status==1.33.2
1 change: 0 additions & 1 deletion testing/constraints-3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ google-auth==1.25.0
requests==2.18.0
packaging==14.3
grpcio==1.33.2
grpcio-gcp==0.2.2
grpcio-status==1.33.2
5 changes: 1 addition & 4 deletions tests/asyncio/test_grpc_helpers_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,8 @@ def test_create_channel_with_credentials_file_and_default_scopes(
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@pytest.mark.skipif(
grpc_helpers_async.HAS_GRPC_GCP, reason="grpc_gcp module not available"
)
@mock.patch("grpc.aio.secure_channel")
def test_create_channel_without_grpc_gcp(grpc_secure_channel):
def test_create_channel(grpc_secure_channel):
target = "example.com:443"
scopes = ["test_scope"]

Expand Down
80 changes: 13 additions & 67 deletions tests/unit/test_grpc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,7 @@ def test_create_channel_implicit(grpc_secure_channel, default, composite_creds_c

default.assert_called_once_with(scopes=None, default_scopes=None)

if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("google.auth.transport.grpc.AuthMetadataPlugin", autospec=True)
Expand Down Expand Up @@ -400,10 +397,7 @@ def test_create_channel_implicit_with_default_host(
mock.sentinel.credentials, mock.sentinel.Request, default_host=default_host
)

if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("grpc.composite_channel_credentials")
Expand All @@ -426,10 +420,7 @@ def test_create_channel_implicit_with_ssl_creds(

composite_creds_call.assert_called_once_with(ssl_creds, mock.ANY)
composite_creds = composite_creds_call.return_value
if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("grpc.composite_channel_credentials")
Expand All @@ -451,10 +442,7 @@ def test_create_channel_implicit_with_scopes(

default.assert_called_once_with(scopes=["one", "two"], default_scopes=None)

if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("grpc.composite_channel_credentials")
Expand All @@ -476,10 +464,7 @@ def test_create_channel_implicit_with_default_scopes(

default.assert_called_once_with(scopes=None, default_scopes=["three", "four"])

if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


def test_create_channel_explicit_with_duplicate_credentials():
Expand Down Expand Up @@ -507,10 +492,7 @@ def test_create_channel_explicit(grpc_secure_channel, auth_creds, composite_cred
)

assert channel is grpc_secure_channel.return_value
if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("grpc.composite_channel_credentials")
Expand All @@ -530,10 +512,7 @@ def test_create_channel_explicit_scoped(grpc_secure_channel, composite_creds_cal
credentials.with_scopes.assert_called_once_with(scopes, default_scopes=None)

assert channel is grpc_secure_channel.return_value
if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("grpc.composite_channel_credentials")
Expand All @@ -557,10 +536,7 @@ def test_create_channel_explicit_default_scopes(
)

assert channel is grpc_secure_channel.return_value
if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("grpc.composite_channel_credentials")
Expand All @@ -582,10 +558,7 @@ def test_create_channel_explicit_with_quota_project(
credentials.with_quota_project.assert_called_once_with("project-foo")

assert channel is grpc_secure_channel.return_value
if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("grpc.composite_channel_credentials")
Expand All @@ -610,10 +583,7 @@ def test_create_channel_with_credentials_file(
)

assert channel is grpc_secure_channel.return_value
if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("grpc.composite_channel_credentials")
Expand Down Expand Up @@ -641,10 +611,7 @@ def test_create_channel_with_credentials_file_and_scopes(
)

assert channel is grpc_secure_channel.return_value
if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@mock.patch("grpc.composite_channel_credentials")
Expand Down Expand Up @@ -672,32 +639,11 @@ def test_create_channel_with_credentials_file_and_default_scopes(
)

assert channel is grpc_secure_channel.return_value
if grpc_helpers.HAS_GRPC_GCP:
grpc_secure_channel.assert_called_once_with(target, composite_creds, None)
else:
grpc_secure_channel.assert_called_once_with(target, composite_creds)
grpc_secure_channel.assert_called_once_with(target, composite_creds)


@pytest.mark.skipif(
not grpc_helpers.HAS_GRPC_GCP, reason="grpc_gcp module not available"
)
@mock.patch("grpc_gcp.secure_channel")
def test_create_channel_with_grpc_gcp(grpc_gcp_secure_channel):
target = "example.com:443"
scopes = ["test_scope"]

credentials = mock.create_autospec(google.auth.credentials.Scoped, instance=True)
credentials.requires_scopes = True

grpc_helpers.create_channel(target, credentials=credentials, scopes=scopes)
grpc_gcp_secure_channel.assert_called()

credentials.with_scopes.assert_called_once_with(scopes, default_scopes=None)


@pytest.mark.skipif(grpc_helpers.HAS_GRPC_GCP, reason="grpc_gcp module not available")
@mock.patch("grpc.secure_channel")
def test_create_channel_without_grpc_gcp(grpc_secure_channel):
def test_create_channel(grpc_secure_channel):
target = "example.com:443"
scopes = ["test_scope"]

Expand Down

0 comments on commit 5da6733

Please sign in to comment.