4239: Update Python SDK for google-api-python-client 1.3.
authorBrett Smith <brett@curoverse.com>
Fri, 17 Oct 2014 14:22:01 +0000 (10:22 -0400)
committerBrett Smith <brett@curoverse.com>
Fri, 17 Oct 2014 14:25:09 +0000 (10:25 -0400)
This package renames the module from apiclient to googleapiclient.  It
provides a shim apiclient module for compatibility, but it only
exports the appropriate names, not real submodules.  Using it requires
changing imports like

    import apiclient.errors

to

    from apiclient import errors

This approach works (has been tested) with both versions 1.2 and 1.3.
Closes #4239.

sdk/python/arvados/api.py
sdk/python/arvados/commands/put.py
sdk/python/arvados/errors.py
sdk/python/setup.py
sdk/python/tests/test_api.py
services/nodemanager/arvnodeman/config.py

index cb716f1709fe39b2c22519f6d9ebc304f4c42f4e..c618fc3c6623ef18e8663609340b55bcce219f78 100644 (file)
@@ -6,8 +6,8 @@ import re
 import types
 
 import apiclient
-import apiclient.discovery
-import apiclient.errors
+from apiclient import discovery as apiclient_discovery
+from apiclient import errors as apiclient_errors
 import config
 import errors
 import util
@@ -47,7 +47,7 @@ class CredentialsFromToken(object):
 
 # Monkey patch discovery._cast() so objects and arrays get serialized
 # with json.dumps() instead of str().
-_cast_orig = apiclient.discovery._cast
+_cast_orig = apiclient_discovery._cast
 def _cast_objects_too(value, schema_type):
     global _cast_orig
     if (type(value) != type('') and
@@ -55,16 +55,16 @@ def _cast_objects_too(value, schema_type):
         return json.dumps(value)
     else:
         return _cast_orig(value, schema_type)
-apiclient.discovery._cast = _cast_objects_too
+apiclient_discovery._cast = _cast_objects_too
 
 # Convert apiclient's HttpErrors into our own API error subclass for better
 # error reporting.
-# Reassigning apiclient.errors.HttpError is not sufficient because most of the
+# Reassigning apiclient_errors.HttpError is not sufficient because most of the
 # apiclient submodules import the class into their own namespace.
 def _new_http_error(cls, *args, **kwargs):
-    return super(apiclient.errors.HttpError, cls).__new__(
+    return super(apiclient_errors.HttpError, cls).__new__(
         errors.ApiError, *args, **kwargs)
-apiclient.errors.HttpError.__new__ = staticmethod(_new_http_error)
+apiclient_errors.HttpError.__new__ = staticmethod(_new_http_error)
 
 def http_cache(data_type):
     path = os.environ['HOME'] + '/.cache/arvados/' + data_type
@@ -90,7 +90,7 @@ def api(version=None, cache=True, host=None, token=None, insecure=False, **kwarg
     * insecure: If True, ignore SSL certificate validation errors.
 
     Additional keyword arguments will be passed directly to
-    `apiclient.discovery.build` if a new Resource object is created.
+    `apiclient_discovery.build` if a new Resource object is created.
     If the `discoveryServiceUrl` or `http` keyword arguments are
     missing, this function will set default values for them, based on
     the current Arvados configuration settings.
@@ -153,7 +153,7 @@ def api(version=None, cache=True, host=None, token=None, insecure=False, **kwarg
     credentials = CredentialsFromToken(api_token=token)
     kwargs['http'] = credentials.authorize(kwargs['http'])
 
-    svc = apiclient.discovery.build('arvados', version, **kwargs)
+    svc = apiclient_discovery.build('arvados', version, **kwargs)
     svc.api_token = token
     kwargs['http'].cache = None
     if cache:
index 53d6f565468595c0c6face0ec76cff86f156c1d2..4a926c701c9f45648dc6337fc294391986e03379 100644 (file)
@@ -3,7 +3,6 @@
 # TODO:
 # --md5sum - display md5 of each file as read from disk
 
-import apiclient.errors
 import argparse
 import arvados
 import base64
@@ -18,6 +17,7 @@ import signal
 import socket
 import sys
 import tempfile
+from apiclient import errors as apiclient_errors
 
 import arvados.commands._util as arv_cmd
 
@@ -390,7 +390,7 @@ def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
     try:
         project_uuid = desired_project_uuid(api_client, args.project_uuid,
                                             args.retries)
-    except (apiclient.errors.Error, ValueError) as error:
+    except (apiclient_errors.Error, ValueError) as error:
         print >>stderr, error
         sys.exit(1)
 
@@ -468,7 +468,7 @@ def main(arguments=None, stdout=sys.stdout, stderr=sys.stderr):
             else:
                 output = collection['uuid']
 
-        except apiclient.errors.Error as error:
+        except apiclient_errors.Error as error:
             print >>stderr, (
                 "arv-put: Error creating Collection on project: {}.".format(
                     error))
index 89910aa60f389f7e61ecfc9d4be6d492f09ad25f..4740a2d91962f31f6aeea1638c8d9582a2b35f50 100644 (file)
@@ -1,9 +1,9 @@
 # errors.py - Arvados-specific exceptions.
 
-import apiclient.errors
 import json
+from apiclient import errors as apiclient_errors
 
-class ApiError(apiclient.errors.HttpError):
+class ApiError(apiclient_errors.HttpError):
     def _get_reason(self):
         try:
             return '; '.join(json.loads(self.content)['errors'])
index ee5b15d3e658f00db4b2bb75d4282085d49bdc2f..03637cbf580c78f275f3609827334f6e0182bf86 100644 (file)
@@ -42,7 +42,7 @@ setup(name='arvados-python-client',
         ],
       install_requires=[
         'python-gflags',
-        'google-api-python-client<1.3',
+        'google-api-python-client',
         'httplib2',
         'urllib3',
         'ws4py'
index e9cb838cb37022ecad51ec669c91b643bd7fafef..0d81fdf738caf3d3120725479c8b110d27204c66 100644 (file)
@@ -1,6 +1,5 @@
 #!/usr/bin/env python
 
-import apiclient.errors
 import arvados
 import httplib2
 import json
@@ -8,8 +7,9 @@ import mimetypes
 import os
 import run_test_server
 import unittest
+from apiclient import errors as apiclient_errors
+from apiclient import http as apiclient_http
 
-from apiclient.http import RequestMockBuilder
 from arvados_testutil import fake_httplib2_response
 
 if not mimetypes.inited:
@@ -41,7 +41,7 @@ class ArvadosApiClientTest(unittest.TestCase):
             'arvados.humans.list': (None, json.dumps(
                     {'items_available': 0, 'items': []})),
             }
-        req_builder = RequestMockBuilder(mock_responses)
+        req_builder = apiclient_http.RequestMockBuilder(mock_responses)
         cls.api = arvados.api('v1', cache=False,
                               host=os.environ['ARVADOS_API_HOST'],
                               token='discovery-doc-only-no-token-needed',
@@ -58,14 +58,14 @@ class ArvadosApiClientTest(unittest.TestCase):
         self.assertEqual(answer['items_available'], len(answer['items']))
 
     def test_exceptions_include_errors(self):
-        with self.assertRaises(apiclient.errors.HttpError) as err_ctx:
+        with self.assertRaises(apiclient_errors.HttpError) as err_ctx:
             self.api.humans().get(uuid='xyz-xyz-abcdef').execute()
         err_s = str(err_ctx.exception)
         for msg in ["Bad UUID format", "Bad output format"]:
             self.assertIn(msg, err_s)
 
     def test_exceptions_without_errors_have_basic_info(self):
-        with self.assertRaises(apiclient.errors.HttpError) as err_ctx:
+        with self.assertRaises(apiclient_errors.HttpError) as err_ctx:
             self.api.humans().delete(uuid='xyz-xyz-abcdef').execute()
         self.assertIn("500", str(err_ctx.exception))
 
index 07504e2fe9aa9e0007044881c57c1ad6793426d0..1699584b200e99ab249ae6f15d63e6888325890e 100644 (file)
@@ -7,11 +7,11 @@ import importlib
 import logging
 import ssl
 
-import apiclient.errors as apierror
 import arvados
 import httplib2
 import libcloud.common.types as cloud_types
 import pykka
+from apiclient import errors as apierror
 
 # IOError is the base class for socket.error and friends.
 # It seems like it hits the sweet spot for operations we want to retry: