Skip to content

Commit c525b44

Browse files
GAPIC Header Consistency: Vision (#3050)
1 parent 2c608f9 commit c525b44

15 files changed

+97
-46
lines changed

vision/google/cloud/vision/_gax.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"""GAX Client for interacting with the Google Cloud Vision API."""
1616

1717
from google.cloud.gapic.vision.v1 import image_annotator_client
18-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
18+
from google.cloud.proto.vision.v1 import image_annotator_pb2
1919

20+
from google.cloud.vision import __version__
2021
from google.cloud.vision.annotations import Annotations
2122

2223

@@ -28,7 +29,9 @@ class _GAPICVisionAPI(object):
2829
"""
2930
def __init__(self, client=None):
3031
self._client = client
31-
self._annotator_client = image_annotator_client.ImageAnnotatorClient()
32+
self._annotator_client = image_annotator_client.ImageAnnotatorClient(
33+
credentials=client._credentials, lib_name='gccl',
34+
lib_version=__version__)
3235

3336
def annotate(self, images):
3437
"""Annotate images through GAX.
@@ -64,7 +67,7 @@ def _to_gapic_feature(feature):
6467
:param feature: Local ``Feature`` class to be converted to gRPC ``Feature``
6568
instance.
6669
67-
:rtype: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.Feature`
70+
:rtype: :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.Feature`
6871
:returns: gRPC ``Feature`` converted from
6972
:class:`~google.cloud.vision.feature.Feature`.
7073
"""
@@ -79,7 +82,7 @@ def _to_gapic_image(image):
7982
:type image: :class:`~google.cloud.vision.image.Image`
8083
:param image: Local ``Image`` class to be converted to gRPC ``Image``.
8184
82-
:rtype: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.Image`
85+
:rtype: :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.Image`
8386
:returns: gRPC ``Image`` converted from
8487
:class:`~google.cloud.vision.image.Image`.
8588
"""

vision/google/cloud/vision/annotations.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def from_api_repr(cls, response):
9999
def from_pb(cls, response):
100100
"""Factory: construct an instance of ``Annotations`` from protobuf.
101101
102-
:type response: :class:`~google.cloud.grpc.vision.v1.\
102+
:type response: :class:`~google.cloud.proto.vision.v1.\
103103
image_annotator_pb2.AnnotateImageResponse`
104104
:param response: ``AnnotateImageResponse`` from protobuf call.
105105
@@ -113,7 +113,7 @@ def from_pb(cls, response):
113113
def _process_image_annotations(image):
114114
"""Helper for processing annotation types from protobuf.
115115
116-
:type image: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.\
116+
:type image: :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.\
117117
AnnotateImageResponse`
118118
:param image: ``AnnotateImageResponse`` from protobuf.
119119
@@ -137,7 +137,7 @@ def _make_entity_from_pb(annotations):
137137
"""Create an entity from a protobuf response.
138138
139139
:type annotations:
140-
:class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.EntityAnnotation`
140+
:class:`~google.cloud.proto.vision.v1.image_annotator_pb2.EntityAnnotation`
141141
:param annotations: protobuf instance of ``EntityAnnotation``.
142142
143143
:rtype: list
@@ -150,7 +150,7 @@ def _make_faces_from_pb(faces):
150150
"""Create face objects from a protobuf response.
151151
152152
:type faces:
153-
:class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.FaceAnnotation`
153+
:class:`~google.cloud.proto.vision.v1.image_annotator_pb2.FaceAnnotation`
154154
:param faces: Protobuf instance of ``FaceAnnotation``.
155155
156156
:rtype: list
@@ -162,7 +162,7 @@ def _make_faces_from_pb(faces):
162162
def _make_image_properties_from_pb(image_properties):
163163
"""Create ``ImageProperties`` object from a protobuf response.
164164
165-
:type image_properties: :class:`~google.cloud.grpc.vision.v1.\
165+
:type image_properties: :class:`~google.cloud.proto.vision.v1.\
166166
image_annotator_pb2.ImagePropertiesAnnotation`
167167
:param image_properties: Protobuf instance of
168168
``ImagePropertiesAnnotation``.
@@ -176,7 +176,7 @@ def _make_image_properties_from_pb(image_properties):
176176
def _make_safe_search_from_pb(safe_search):
177177
"""Create ``SafeSearchAnnotation`` object from a protobuf response.
178178
179-
:type safe_search: :class:`~google.cloud.grpc.vision.v1.\
179+
:type safe_search: :class:`~google.cloud.proto.vision.v1.\
180180
image_annotator_pb2.SafeSearchAnnotation`
181181
:param safe_search: Protobuf instance of ``SafeSearchAnnotation``.
182182

vision/google/cloud/vision/color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def from_api_repr(cls, image_properties):
4545
def from_pb(cls, image_properties):
4646
"""Factory: construct ``ImagePropertiesAnnotation`` from a response.
4747
48-
:type image_properties: :class:`~google.cloud.grpc.vision.v1.\
48+
:type image_properties: :class:`~google.cloud.proto.vision.v1.\
4949
image_annotator_pb2.ImageProperties`
5050
:param image_properties: Protobuf response from Vision API with image
5151
properties data.
@@ -196,7 +196,7 @@ def from_api_repr(cls, color_information):
196196
def from_pb(cls, color_information):
197197
"""Factory: construct ``ColorInformation`` for a color.
198198
199-
:type color_information: :class:`~google.cloud.grpc.vision.v1.\
199+
:type color_information: :class:`~google.cloud.proto.vision.v1.\
200200
image_annotator_pb2.ColorInfo`
201201
:param color_information: Color data with extra meta information.
202202

vision/google/cloud/vision/entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def from_api_repr(cls, response):
7474
def from_pb(cls, response):
7575
"""Factory: construct entity from Vision gRPC response.
7676
77-
:type response: :class:`~google.cloud.grpc.vision.v1.\
77+
:type response: :class:`~google.cloud.proto.vision.v1.\
7878
image_annotator_pb2.AnnotateImageResponse`
7979
:param response: gRPC response from Vision API with entity data.
8080

vision/google/cloud/vision/face.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def from_api_repr(cls, angle):
5050
def from_pb(cls, angle):
5151
"""Factory: convert protobuf Angle object to local Angle object.
5252
53-
:type angle: :class:`~google.cloud.grpc.vision.v1.\
53+
:type angle: :class:`~google.cloud.proto.vision.v1.\
5454
image_annotator_pb2.FaceAnnotation`
5555
:param angle: Protobuf ``FaceAnnotation`` response with angle data.
5656
@@ -126,7 +126,7 @@ def from_api_repr(cls, emotions):
126126
def from_pb(cls, emotions):
127127
"""Factory: construct ``Emotions`` from Vision API response.
128128
129-
:type emotions: :class:`~google.cloud.grpc.vision.v1.\
129+
:type emotions: :class:`~google.cloud.proto.vision.v1.\
130130
image_annotator_pb2.FaceAnnotation`
131131
:param emotions: Response dictionary representing a face with emotions.
132132
@@ -225,7 +225,7 @@ def from_api_repr(cls, face):
225225
def from_pb(cls, face):
226226
"""Factory: construct an instance of a Face from an protobuf response
227227
228-
:type face: :class:`~google.cloud.grpc.vision.v1.\
228+
:type face: :class:`~google.cloud.proto.vision.v1.\
229229
image_annotator_pb2.AnnotateImageResponse`
230230
:param face: ``AnnotateImageResponse`` from gRPC call.
231231
@@ -397,7 +397,7 @@ def from_api_repr(cls, face):
397397
def from_pb(cls, face):
398398
"""Factory: construct image properties from image.
399399
400-
:type face: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.\
400+
:type face: :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.\
401401
FaceAnnotation`
402402
:param face: Protobuf instace of `Face`.
403403
@@ -508,7 +508,7 @@ def from_api_repr(cls, landmark):
508508
def from_pb(cls, landmark):
509509
"""Factory: construct an instance of a Landmark from a response.
510510
511-
:type landmark: :class:`~google.cloud.grpc.vision.v1.\
511+
:type landmark: :class:`~google.cloud.proto.vision.v1.\
512512
image_annotator_pb.FaceAnnotation.Landmark`
513513
:param landmark: Landmark representation from Vision API.
514514

vision/google/cloud/vision/geometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def from_api_repr(cls, vertices):
4343
def from_pb(cls, vertices):
4444
"""Factory: construct BoundsBase instance from a protobuf response.
4545
46-
:type vertices: :class:`~google.cloud.grpc.vision.v1.\
46+
:type vertices: :class:`~google.cloud.proto.vision.v1.\
4747
geometry_pb2.BoundingPoly`
4848
:param vertices: List of vertices.
4949

vision/google/cloud/vision/likelihood.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from enum import Enum
1919

20-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
20+
from google.cloud.proto.vision.v1 import image_annotator_pb2
2121

2222

2323
def _get_pb_likelihood(likelihood):

vision/google/cloud/vision/safe_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def from_api_repr(cls, response):
6666
def from_pb(cls, image):
6767
"""Factory: construct SafeSearchAnnotation from Vision API response.
6868
69-
:type image: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.\
70-
SafeSearchAnnotation`
69+
:type image: :class:`~google.cloud.proto.vision.v1.\
70+
image_annotator_pb2.SafeSearchAnnotation`
7171
:param image: Protobuf response from Vision API with safe search data.
7272
7373
:rtype: :class:`~google.cloud.vision.safe_search.SafeSearchAnnotation`

vision/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
REQUIREMENTS = [
5353
'enum34',
5454
'google-cloud-core >= 0.23.0, < 0.24dev',
55-
'gapic-google-cloud-vision-v1 >= 0.14.0, < 0.15dev',
55+
'gapic-google-cloud-vision-v1 >= 0.15.0, < 0.16dev',
5656
]
5757

5858
setup(
5959
name='google-cloud-vision',
60-
version='0.22.0',
60+
version='0.23.0',
6161
description='Python Client for Google Cloud Vision',
6262
long_description=README,
6363
namespace_packages=[

vision/unit_tests/test__gax.py

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
import mock
1818

1919

20+
def _make_credentials():
21+
import google.auth.credentials
22+
return mock.Mock(spec=google.auth.credentials.Credentials)
23+
24+
2025
class TestGAXClient(unittest.TestCase):
2126
def _get_target_class(self):
2227
from google.cloud.vision._gax import _GAPICVisionAPI
@@ -32,12 +37,55 @@ def test_ctor(self):
3237
api = self._make_one(client)
3338
self.assertIs(api._client, client)
3439

40+
def test_gapic_credentials(self):
41+
from google.cloud.gapic.vision.v1.image_annotator_client import (
42+
ImageAnnotatorClient)
43+
from google.cloud.vision import Client
44+
45+
# Mock the GAPIC ImageAnnotatorClient, whose arguments we
46+
# want to check.
47+
with mock.patch.object(ImageAnnotatorClient, '__init__') as iac:
48+
iac.return_value = None
49+
50+
# Create the GAX client.
51+
credentials = _make_credentials()
52+
client = Client(credentials=credentials, project='foo')
53+
self._make_one(client=client)
54+
55+
# Assert that the GAPIC constructor was called once, and
56+
# that the credentials were sent.
57+
iac.assert_called_once()
58+
_, _, kwargs = iac.mock_calls[0]
59+
self.assertIs(kwargs['credentials'], credentials)
60+
61+
def test_kwarg_lib_name(self):
62+
from google.cloud.gapic.vision.v1.image_annotator_client import (
63+
ImageAnnotatorClient)
64+
from google.cloud.vision import __version__
65+
from google.cloud.vision import Client
66+
67+
# Mock the GAPIC ImageAnnotatorClient, whose arguments we
68+
# want to check.
69+
with mock.patch.object(ImageAnnotatorClient, '__init__') as iac:
70+
iac.return_value = None
71+
72+
# Create the GAX client.
73+
client = Client(credentials=_make_credentials(), project='foo')
74+
self._make_one(client=client)
75+
76+
# Assert that the GAPIC constructor was called once, and
77+
# that lib_name and lib_version were sent.
78+
iac.assert_called_once()
79+
_, _, kwargs = iac.mock_calls[0]
80+
self.assertEqual(kwargs['lib_name'], 'gccl')
81+
self.assertEqual(kwargs['lib_version'], __version__)
82+
3583
def test_annotation(self):
3684
from google.cloud.vision.feature import Feature
3785
from google.cloud.vision.feature import FeatureTypes
3886
from google.cloud.vision.image import Image
3987

40-
client = mock.Mock(spec_set=[])
88+
client = mock.Mock(spec_set=['_credentials'])
4189
feature = Feature(FeatureTypes.LABEL_DETECTION, 5)
4290
image_content = b'abc 1 2 3'
4391
image = Image(client, content=image_content)
@@ -64,7 +112,7 @@ def test_annotate_no_results(self):
64112
from google.cloud.vision.feature import FeatureTypes
65113
from google.cloud.vision.image import Image
66114

67-
client = mock.Mock(spec_set=[])
115+
client = mock.Mock(spec_set=['_credentials'])
68116
feature = Feature(FeatureTypes.LABEL_DETECTION, 5)
69117
image_content = b'abc 1 2 3'
70118
image = Image(client, content=image_content)
@@ -87,13 +135,13 @@ def test_annotate_no_results(self):
87135
gax_api._annotator_client.batch_annotate_images.assert_called()
88136

89137
def test_annotate_multiple_results(self):
90-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
138+
from google.cloud.proto.vision.v1 import image_annotator_pb2
91139
from google.cloud.vision.annotations import Annotations
92140
from google.cloud.vision.feature import Feature
93141
from google.cloud.vision.feature import FeatureTypes
94142
from google.cloud.vision.image import Image
95143

96-
client = mock.Mock(spec_set=[])
144+
client = mock.Mock(spec_set=['_credentials'])
97145
feature = Feature(FeatureTypes.LABEL_DETECTION, 5)
98146
image_content = b'abc 1 2 3'
99147
image = Image(client, content=image_content)
@@ -128,7 +176,7 @@ def _call_fut(self, feature):
128176
def test__to_gapic_feature(self):
129177
from google.cloud.vision.feature import Feature
130178
from google.cloud.vision.feature import FeatureTypes
131-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
179+
from google.cloud.proto.vision.v1 import image_annotator_pb2
132180

133181
feature = Feature(FeatureTypes.LABEL_DETECTION, 5)
134182
feature_pb = self._call_fut(feature)
@@ -144,7 +192,7 @@ def _call_fut(self, image):
144192

145193
def test__to_gapic_image_content(self):
146194
from google.cloud.vision.image import Image
147-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
195+
from google.cloud.proto.vision.v1 import image_annotator_pb2
148196

149197
image_content = b'abc 1 2 3'
150198
client = object()
@@ -155,7 +203,7 @@ def test__to_gapic_image_content(self):
155203

156204
def test__to_gapic_image_uri(self):
157205
from google.cloud.vision.image import Image
158-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
206+
from google.cloud.proto.vision.v1 import image_annotator_pb2
159207

160208
image_uri = 'gs://1234/34.jpg'
161209
client = object()

vision/unit_tests/test_annotations.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717

1818
def _make_pb_entity():
19-
from google.cloud.grpc.vision.v1 import geometry_pb2
20-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
19+
from google.cloud.proto.vision.v1 import geometry_pb2
20+
from google.cloud.proto.vision.v1 import image_annotator_pb2
2121
from google.type import latlng_pb2
2222

2323
description = 'testing 1 2 3'
@@ -78,7 +78,7 @@ def test_unsupported_http_annotation(self):
7878
def test_from_pb(self):
7979
from google.cloud.vision.likelihood import Likelihood
8080
from google.cloud.vision.safe_search import SafeSearchAnnotation
81-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
81+
from google.cloud.proto.vision.v1 import image_annotator_pb2
8282

8383
image_response = image_annotator_pb2.AnnotateImageResponse()
8484
annotations = self._make_one().from_pb(image_response)
@@ -131,7 +131,7 @@ def _call_fut(self, annotations):
131131
return _make_faces_from_pb(annotations)
132132

133133
def test_it(self):
134-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
134+
from google.cloud.proto.vision.v1 import image_annotator_pb2
135135
from google.cloud.vision.face import Face
136136

137137
faces_pb = [image_annotator_pb2.FaceAnnotation()]
@@ -147,7 +147,7 @@ def _call_fut(self, annotations):
147147
return _make_image_properties_from_pb(annotations)
148148

149149
def test_it(self):
150-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
150+
from google.cloud.proto.vision.v1 import image_annotator_pb2
151151
from google.protobuf.wrappers_pb2 import FloatValue
152152
from google.type.color_pb2 import Color
153153

@@ -178,7 +178,7 @@ def _call_fut(self, image):
178178
return _process_image_annotations(image)
179179

180180
def test_it(self):
181-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
181+
from google.cloud.proto.vision.v1 import image_annotator_pb2
182182

183183
description = 'testing 1 2 3'
184184
locale = 'US'

vision/unit_tests/test_color.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _get_target_class():
9595
return ImagePropertiesAnnotation
9696

9797
def test_image_properties_annotation_from_pb(self):
98-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
98+
from google.cloud.proto.vision.v1 import image_annotator_pb2
9999
from google.protobuf.wrappers_pb2 import FloatValue
100100
from google.type.color_pb2 import Color
101101

@@ -121,7 +121,7 @@ def test_image_properties_annotation_from_pb(self):
121121
self.assertEqual(image_properties.colors[0].color.alpha, 1.0)
122122

123123
def test_empty_image_properties_annotation_from_pb(self):
124-
from google.cloud.grpc.vision.v1 import image_annotator_pb2
124+
from google.cloud.proto.vision.v1 import image_annotator_pb2
125125

126126
image_properties_pb = image_annotator_pb2.ImageProperties()
127127

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy