Skip to content

Commit

Permalink
[chore] Remove package metadata (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Sneeringer authored May 23, 2019
1 parent f457dc9 commit 8fe9b53
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 79 deletions.
32 changes: 0 additions & 32 deletions gapic/schema/naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
46 changes: 0 additions & 46 deletions tests/unit/schema/test_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import pytest

from google.api import client_pb2
from google.protobuf import descriptor_pb2

from gapic.schema import naming
Expand Down Expand Up @@ -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(
Expand All @@ -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')
Expand Down

0 comments on commit 8fe9b53

Please sign in to comment.