diff --git a/gapic/schema/naming.py b/gapic/schema/naming.py index f8d924edd..af09805a5 100644 --- a/gapic/schema/naming.py +++ b/gapic/schema/naming.py @@ -17,7 +17,6 @@ import re from typing import Iterable, Sequence, Tuple -from google.api import client_pb2 from google.protobuf import descriptor_pb2 from gapic import utils @@ -116,37 +115,6 @@ def build(cls, raise ValueError('All protos must have the same proto package ' 'up to and including the version.') - # Iterate over the metadata annotations and collect the package - # information from there. - # - # This creates a naming class non-empty metadata annotation and - # uses Python's set logic to de-duplicate. There should only be one. - explicit_pkgs = set() - for fd in file_descriptors: - pkg = fd.options.Extensions[client_pb2.client_package] - naming = cls( - name=pkg.title or pkg.product_title, - namespace=tuple(pkg.namespace), - version=pkg.version, - ) - if naming: - explicit_pkgs.add(naming) - - # Sanity check: Ensure that any google.api.metadata provisions were - # consistent. - if len(explicit_pkgs) > 1: - raise ValueError( - 'If the google.api.client_package annotation is provided in ' - 'more than one file, it must be consistent.', - ) - - # Merge the package naming information and the metadata naming - # information, with the latter being preferred. - # Return a Naming object which effectively merges them. - if len(explicit_pkgs): - return dataclasses.replace(package_info, - **dataclasses.asdict(explicit_pkgs.pop()), - ) return package_info def __bool__(self): diff --git a/setup.py b/setup.py index 727bafb8d..2e9897284 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ include_package_data=True, install_requires=( 'click >= 6.7', - 'googleapis-common-protos >= 1.6.0b8', + 'googleapis-common-protos >= 1.6.0', 'jinja2 >= 2.10', 'protobuf >= 3.7.1', 'pypandoc >= 1.4', diff --git a/tests/unit/schema/test_naming.py b/tests/unit/schema/test_naming.py index f3ad0e09e..763358d12 100644 --- a/tests/unit/schema/test_naming.py +++ b/tests/unit/schema/test_naming.py @@ -14,7 +14,6 @@ import pytest -from google.api import client_pb2 from google.protobuf import descriptor_pb2 from gapic.schema import naming @@ -110,25 +109,6 @@ def test_build_no_annotations_no_version(): assert n.version == '' -def test_build_with_annotations(): - proto = descriptor_pb2.FileDescriptorProto( - name='spanner.proto', - package='google.spanner.v1', - ) - proto.options.Extensions[client_pb2.client_package].MergeFrom( - client_pb2.Package( - namespace=['Google', 'Cloud'], - title='Spanner', - version='v1', - ), - ) - n = naming.Naming.build(proto) - assert n.name == 'Spanner' - assert n.namespace == ('Google', 'Cloud') - assert n.version == 'v1' - assert n.product_name == 'Spanner' - - def test_build_no_namespace(): protos = ( descriptor_pb2.FileDescriptorProto( @@ -143,32 +123,6 @@ def test_build_no_namespace(): assert n.product_name == 'Foo' -def test_inconsistent_metadata_error(): - # Set up the first proto. - proto1 = descriptor_pb2.FileDescriptorProto( - name='spanner.proto', - package='google.spanner.v1', - ) - proto1.options.Extensions[client_pb2.client_package].MergeFrom( - client_pb2.Package(namespace=['Google', 'Cloud']), - ) - - # Set up the second proto. - # Note that - proto2 = descriptor_pb2.FileDescriptorProto( - name='spanner2.proto', - package='google.spanner.v1', - ) - proto2.options.Extensions[client_pb2.client_package].MergeFrom( - client_pb2.Package(title='Spanner', namespace=['Google', 'Cloud']), - ) - - # This should error. Even though the data in the metadata is consistent, - # it is expected to exactly match, and it does not. - with pytest.raises(ValueError): - naming.Naming.build(proto1, proto2) - - def test_inconsistent_package_error(): proto1 = descriptor_pb2.FileDescriptorProto(package='google.spanner.v1') proto2 = descriptor_pb2.FileDescriptorProto(package='spanner.v1')