diff --git a/vision/google/cloud/vision/_gax.py b/vision/google/cloud/vision/_gax.py index 55f3dfd4adf2..d738288b5aca 100644 --- a/vision/google/cloud/vision/_gax.py +++ b/vision/google/cloud/vision/_gax.py @@ -15,8 +15,9 @@ """GAX Client for interacting with the Google Cloud Vision API.""" from google.cloud.gapic.vision.v1 import image_annotator_client -from google.cloud.grpc.vision.v1 import image_annotator_pb2 +from google.cloud.proto.vision.v1 import image_annotator_pb2 +from google.cloud.vision import __version__ from google.cloud.vision.annotations import Annotations @@ -28,7 +29,9 @@ class _GAPICVisionAPI(object): """ def __init__(self, client=None): self._client = client - self._annotator_client = image_annotator_client.ImageAnnotatorClient() + self._annotator_client = image_annotator_client.ImageAnnotatorClient( + credentials=client._credentials, lib_name='gccl', + lib_version=__version__) def annotate(self, images): """Annotate images through GAX. @@ -64,7 +67,7 @@ def _to_gapic_feature(feature): :param feature: Local ``Feature`` class to be converted to gRPC ``Feature`` instance. - :rtype: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.Feature` + :rtype: :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.Feature` :returns: gRPC ``Feature`` converted from :class:`~google.cloud.vision.feature.Feature`. """ @@ -79,7 +82,7 @@ def _to_gapic_image(image): :type image: :class:`~google.cloud.vision.image.Image` :param image: Local ``Image`` class to be converted to gRPC ``Image``. - :rtype: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.Image` + :rtype: :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.Image` :returns: gRPC ``Image`` converted from :class:`~google.cloud.vision.image.Image`. """ diff --git a/vision/google/cloud/vision/annotations.py b/vision/google/cloud/vision/annotations.py index 2348d2361731..053bb26d6f68 100644 --- a/vision/google/cloud/vision/annotations.py +++ b/vision/google/cloud/vision/annotations.py @@ -99,7 +99,7 @@ def from_api_repr(cls, response): def from_pb(cls, response): """Factory: construct an instance of ``Annotations`` from protobuf. - :type response: :class:`~google.cloud.grpc.vision.v1.\ + :type response: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb2.AnnotateImageResponse` :param response: ``AnnotateImageResponse`` from protobuf call. @@ -113,7 +113,7 @@ def from_pb(cls, response): def _process_image_annotations(image): """Helper for processing annotation types from protobuf. - :type image: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.\ + :type image: :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.\ AnnotateImageResponse` :param image: ``AnnotateImageResponse`` from protobuf. @@ -137,7 +137,7 @@ def _make_entity_from_pb(annotations): """Create an entity from a protobuf response. :type annotations: - :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.EntityAnnotation` + :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.EntityAnnotation` :param annotations: protobuf instance of ``EntityAnnotation``. :rtype: list @@ -150,7 +150,7 @@ def _make_faces_from_pb(faces): """Create face objects from a protobuf response. :type faces: - :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.FaceAnnotation` + :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.FaceAnnotation` :param faces: Protobuf instance of ``FaceAnnotation``. :rtype: list @@ -162,7 +162,7 @@ def _make_faces_from_pb(faces): def _make_image_properties_from_pb(image_properties): """Create ``ImageProperties`` object from a protobuf response. - :type image_properties: :class:`~google.cloud.grpc.vision.v1.\ + :type image_properties: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb2.ImagePropertiesAnnotation` :param image_properties: Protobuf instance of ``ImagePropertiesAnnotation``. @@ -176,7 +176,7 @@ def _make_image_properties_from_pb(image_properties): def _make_safe_search_from_pb(safe_search): """Create ``SafeSearchAnnotation`` object from a protobuf response. - :type safe_search: :class:`~google.cloud.grpc.vision.v1.\ + :type safe_search: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb2.SafeSearchAnnotation` :param safe_search: Protobuf instance of ``SafeSearchAnnotation``. diff --git a/vision/google/cloud/vision/color.py b/vision/google/cloud/vision/color.py index 634842567525..205b8f3b1ba6 100644 --- a/vision/google/cloud/vision/color.py +++ b/vision/google/cloud/vision/color.py @@ -45,7 +45,7 @@ def from_api_repr(cls, image_properties): def from_pb(cls, image_properties): """Factory: construct ``ImagePropertiesAnnotation`` from a response. - :type image_properties: :class:`~google.cloud.grpc.vision.v1.\ + :type image_properties: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb2.ImageProperties` :param image_properties: Protobuf response from Vision API with image properties data. @@ -196,7 +196,7 @@ def from_api_repr(cls, color_information): def from_pb(cls, color_information): """Factory: construct ``ColorInformation`` for a color. - :type color_information: :class:`~google.cloud.grpc.vision.v1.\ + :type color_information: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb2.ColorInfo` :param color_information: Color data with extra meta information. diff --git a/vision/google/cloud/vision/entity.py b/vision/google/cloud/vision/entity.py index 774c220732d6..5d1e402b362a 100644 --- a/vision/google/cloud/vision/entity.py +++ b/vision/google/cloud/vision/entity.py @@ -74,7 +74,7 @@ def from_api_repr(cls, response): def from_pb(cls, response): """Factory: construct entity from Vision gRPC response. - :type response: :class:`~google.cloud.grpc.vision.v1.\ + :type response: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb2.AnnotateImageResponse` :param response: gRPC response from Vision API with entity data. diff --git a/vision/google/cloud/vision/face.py b/vision/google/cloud/vision/face.py index 354ff08d59ce..cdb744c97cb5 100644 --- a/vision/google/cloud/vision/face.py +++ b/vision/google/cloud/vision/face.py @@ -50,7 +50,7 @@ def from_api_repr(cls, angle): def from_pb(cls, angle): """Factory: convert protobuf Angle object to local Angle object. - :type angle: :class:`~google.cloud.grpc.vision.v1.\ + :type angle: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb2.FaceAnnotation` :param angle: Protobuf ``FaceAnnotation`` response with angle data. @@ -126,7 +126,7 @@ def from_api_repr(cls, emotions): def from_pb(cls, emotions): """Factory: construct ``Emotions`` from Vision API response. - :type emotions: :class:`~google.cloud.grpc.vision.v1.\ + :type emotions: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb2.FaceAnnotation` :param emotions: Response dictionary representing a face with emotions. @@ -225,7 +225,7 @@ def from_api_repr(cls, face): def from_pb(cls, face): """Factory: construct an instance of a Face from an protobuf response - :type face: :class:`~google.cloud.grpc.vision.v1.\ + :type face: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb2.AnnotateImageResponse` :param face: ``AnnotateImageResponse`` from gRPC call. @@ -397,7 +397,7 @@ def from_api_repr(cls, face): def from_pb(cls, face): """Factory: construct image properties from image. - :type face: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.\ + :type face: :class:`~google.cloud.proto.vision.v1.image_annotator_pb2.\ FaceAnnotation` :param face: Protobuf instace of `Face`. @@ -508,7 +508,7 @@ def from_api_repr(cls, landmark): def from_pb(cls, landmark): """Factory: construct an instance of a Landmark from a response. - :type landmark: :class:`~google.cloud.grpc.vision.v1.\ + :type landmark: :class:`~google.cloud.proto.vision.v1.\ image_annotator_pb.FaceAnnotation.Landmark` :param landmark: Landmark representation from Vision API. diff --git a/vision/google/cloud/vision/geometry.py b/vision/google/cloud/vision/geometry.py index 39b429a32ed8..b9cc2a2dd6e2 100644 --- a/vision/google/cloud/vision/geometry.py +++ b/vision/google/cloud/vision/geometry.py @@ -43,7 +43,7 @@ def from_api_repr(cls, vertices): def from_pb(cls, vertices): """Factory: construct BoundsBase instance from a protobuf response. - :type vertices: :class:`~google.cloud.grpc.vision.v1.\ + :type vertices: :class:`~google.cloud.proto.vision.v1.\ geometry_pb2.BoundingPoly` :param vertices: List of vertices. diff --git a/vision/google/cloud/vision/likelihood.py b/vision/google/cloud/vision/likelihood.py index fd249e41dff1..a83b2991f2bb 100644 --- a/vision/google/cloud/vision/likelihood.py +++ b/vision/google/cloud/vision/likelihood.py @@ -17,7 +17,7 @@ from enum import Enum -from google.cloud.grpc.vision.v1 import image_annotator_pb2 +from google.cloud.proto.vision.v1 import image_annotator_pb2 def _get_pb_likelihood(likelihood): diff --git a/vision/google/cloud/vision/safe_search.py b/vision/google/cloud/vision/safe_search.py index 9b531837db8c..d439d9ed6015 100644 --- a/vision/google/cloud/vision/safe_search.py +++ b/vision/google/cloud/vision/safe_search.py @@ -66,8 +66,8 @@ def from_api_repr(cls, response): def from_pb(cls, image): """Factory: construct SafeSearchAnnotation from Vision API response. - :type image: :class:`~google.cloud.grpc.vision.v1.image_annotator_pb2.\ - SafeSearchAnnotation` + :type image: :class:`~google.cloud.proto.vision.v1.\ + image_annotator_pb2.SafeSearchAnnotation` :param image: Protobuf response from Vision API with safe search data. :rtype: :class:`~google.cloud.vision.safe_search.SafeSearchAnnotation` diff --git a/vision/setup.py b/vision/setup.py index 7764d29668d2..cbd5dd4bad1c 100644 --- a/vision/setup.py +++ b/vision/setup.py @@ -52,12 +52,12 @@ REQUIREMENTS = [ 'enum34', 'google-cloud-core >= 0.23.0, < 0.24dev', - 'gapic-google-cloud-vision-v1 >= 0.14.0, < 0.15dev', + 'gapic-google-cloud-vision-v1 >= 0.15.0, < 0.16dev', ] setup( name='google-cloud-vision', - version='0.22.0', + version='0.23.0', description='Python Client for Google Cloud Vision', long_description=README, namespace_packages=[ diff --git a/vision/unit_tests/test__gax.py b/vision/unit_tests/test__gax.py index 31383936d0df..1a97778bfc1b 100644 --- a/vision/unit_tests/test__gax.py +++ b/vision/unit_tests/test__gax.py @@ -17,6 +17,11 @@ import mock +def _make_credentials(): + import google.auth.credentials + return mock.Mock(spec=google.auth.credentials.Credentials) + + class TestGAXClient(unittest.TestCase): def _get_target_class(self): from google.cloud.vision._gax import _GAPICVisionAPI @@ -32,12 +37,55 @@ def test_ctor(self): api = self._make_one(client) self.assertIs(api._client, client) + def test_gapic_credentials(self): + from google.cloud.gapic.vision.v1.image_annotator_client import ( + ImageAnnotatorClient) + from google.cloud.vision import Client + + # Mock the GAPIC ImageAnnotatorClient, whose arguments we + # want to check. + with mock.patch.object(ImageAnnotatorClient, '__init__') as iac: + iac.return_value = None + + # Create the GAX client. + credentials = _make_credentials() + client = Client(credentials=credentials, project='foo') + self._make_one(client=client) + + # Assert that the GAPIC constructor was called once, and + # that the credentials were sent. + iac.assert_called_once() + _, _, kwargs = iac.mock_calls[0] + self.assertIs(kwargs['credentials'], credentials) + + def test_kwarg_lib_name(self): + from google.cloud.gapic.vision.v1.image_annotator_client import ( + ImageAnnotatorClient) + from google.cloud.vision import __version__ + from google.cloud.vision import Client + + # Mock the GAPIC ImageAnnotatorClient, whose arguments we + # want to check. + with mock.patch.object(ImageAnnotatorClient, '__init__') as iac: + iac.return_value = None + + # Create the GAX client. + client = Client(credentials=_make_credentials(), project='foo') + self._make_one(client=client) + + # Assert that the GAPIC constructor was called once, and + # that lib_name and lib_version were sent. + iac.assert_called_once() + _, _, kwargs = iac.mock_calls[0] + self.assertEqual(kwargs['lib_name'], 'gccl') + self.assertEqual(kwargs['lib_version'], __version__) + def test_annotation(self): from google.cloud.vision.feature import Feature from google.cloud.vision.feature import FeatureTypes from google.cloud.vision.image import Image - client = mock.Mock(spec_set=[]) + client = mock.Mock(spec_set=['_credentials']) feature = Feature(FeatureTypes.LABEL_DETECTION, 5) image_content = b'abc 1 2 3' image = Image(client, content=image_content) @@ -64,7 +112,7 @@ def test_annotate_no_results(self): from google.cloud.vision.feature import FeatureTypes from google.cloud.vision.image import Image - client = mock.Mock(spec_set=[]) + client = mock.Mock(spec_set=['_credentials']) feature = Feature(FeatureTypes.LABEL_DETECTION, 5) image_content = b'abc 1 2 3' image = Image(client, content=image_content) @@ -87,13 +135,13 @@ def test_annotate_no_results(self): gax_api._annotator_client.batch_annotate_images.assert_called() def test_annotate_multiple_results(self): - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 from google.cloud.vision.annotations import Annotations from google.cloud.vision.feature import Feature from google.cloud.vision.feature import FeatureTypes from google.cloud.vision.image import Image - client = mock.Mock(spec_set=[]) + client = mock.Mock(spec_set=['_credentials']) feature = Feature(FeatureTypes.LABEL_DETECTION, 5) image_content = b'abc 1 2 3' image = Image(client, content=image_content) @@ -128,7 +176,7 @@ def _call_fut(self, feature): def test__to_gapic_feature(self): from google.cloud.vision.feature import Feature from google.cloud.vision.feature import FeatureTypes - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 feature = Feature(FeatureTypes.LABEL_DETECTION, 5) feature_pb = self._call_fut(feature) @@ -144,7 +192,7 @@ def _call_fut(self, image): def test__to_gapic_image_content(self): from google.cloud.vision.image import Image - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 image_content = b'abc 1 2 3' client = object() @@ -155,7 +203,7 @@ def test__to_gapic_image_content(self): def test__to_gapic_image_uri(self): from google.cloud.vision.image import Image - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 image_uri = 'gs://1234/34.jpg' client = object() diff --git a/vision/unit_tests/test_annotations.py b/vision/unit_tests/test_annotations.py index 41408a17b88c..56be200bfd33 100644 --- a/vision/unit_tests/test_annotations.py +++ b/vision/unit_tests/test_annotations.py @@ -16,8 +16,8 @@ def _make_pb_entity(): - from google.cloud.grpc.vision.v1 import geometry_pb2 - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import geometry_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 from google.type import latlng_pb2 description = 'testing 1 2 3' @@ -78,7 +78,7 @@ def test_unsupported_http_annotation(self): def test_from_pb(self): from google.cloud.vision.likelihood import Likelihood from google.cloud.vision.safe_search import SafeSearchAnnotation - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 image_response = image_annotator_pb2.AnnotateImageResponse() annotations = self._make_one().from_pb(image_response) @@ -131,7 +131,7 @@ def _call_fut(self, annotations): return _make_faces_from_pb(annotations) def test_it(self): - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 from google.cloud.vision.face import Face faces_pb = [image_annotator_pb2.FaceAnnotation()] @@ -147,7 +147,7 @@ def _call_fut(self, annotations): return _make_image_properties_from_pb(annotations) def test_it(self): - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 from google.protobuf.wrappers_pb2 import FloatValue from google.type.color_pb2 import Color @@ -178,7 +178,7 @@ def _call_fut(self, image): return _process_image_annotations(image) def test_it(self): - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 description = 'testing 1 2 3' locale = 'US' diff --git a/vision/unit_tests/test_color.py b/vision/unit_tests/test_color.py index 9a9055dac7d2..6421fd5d3423 100644 --- a/vision/unit_tests/test_color.py +++ b/vision/unit_tests/test_color.py @@ -95,7 +95,7 @@ def _get_target_class(): return ImagePropertiesAnnotation def test_image_properties_annotation_from_pb(self): - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 from google.protobuf.wrappers_pb2 import FloatValue from google.type.color_pb2 import Color @@ -121,7 +121,7 @@ def test_image_properties_annotation_from_pb(self): self.assertEqual(image_properties.colors[0].color.alpha, 1.0) def test_empty_image_properties_annotation_from_pb(self): - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 image_properties_pb = image_annotator_pb2.ImageProperties() diff --git a/vision/unit_tests/test_entity.py b/vision/unit_tests/test_entity.py index 00d7cd5b4d33..b812bb0b0682 100644 --- a/vision/unit_tests/test_entity.py +++ b/vision/unit_tests/test_entity.py @@ -34,7 +34,7 @@ def test_logo_annotation(self): self.assertEqual(162, logo.bounds.vertices[0].y_coordinate) def test_logo_pb_annotation(self): - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 description = 'testing 1 2 3' locale = 'US' diff --git a/vision/unit_tests/test_face.py b/vision/unit_tests/test_face.py index 801479bccc44..55814e0cad15 100644 --- a/vision/unit_tests/test_face.py +++ b/vision/unit_tests/test_face.py @@ -22,7 +22,7 @@ def _get_target_class(): return Face def _make_face_pb(self, *args, **kwargs): - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 return image_annotator_pb2.FaceAnnotation(*args, **kwargs) @@ -34,8 +34,8 @@ def setUp(self): self.FACE_ANNOTATIONS['faceAnnotations'][0]) def test_face_from_pb(self): - from google.cloud.grpc.vision.v1 import image_annotator_pb2 - from google.cloud.grpc.vision.v1 import geometry_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import geometry_pb2 position_pb = geometry_pb2.Position(x=1.0, y=2.0, z=3.0) landmark_pb = image_annotator_pb2.FaceAnnotation.Landmark( diff --git a/vision/unit_tests/test_safe_search.py b/vision/unit_tests/test_safe_search.py index 5bc06ac47c52..b2ee7593e87b 100644 --- a/vision/unit_tests/test_safe_search.py +++ b/vision/unit_tests/test_safe_search.py @@ -38,9 +38,9 @@ def test_safe_search_annotation(self): def test_pb_safe_search_annotation(self): from google.cloud.vision.likelihood import Likelihood - from google.cloud.grpc.vision.v1.image_annotator_pb2 import ( + from google.cloud.proto.vision.v1.image_annotator_pb2 import ( Likelihood as LikelihoodPB) - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 possible = LikelihoodPB.Value('POSSIBLE') possible_name = Likelihood.POSSIBLE @@ -57,7 +57,7 @@ def test_pb_safe_search_annotation(self): def test_empty_pb_safe_search_annotation(self): from google.cloud.vision.likelihood import Likelihood - from google.cloud.grpc.vision.v1 import image_annotator_pb2 + from google.cloud.proto.vision.v1 import image_annotator_pb2 unknown = Likelihood.UNKNOWN safe_search_annotation = image_annotator_pb2.SafeSearchAnnotation()