|
22 | 22 |
|
23 | 23 | VERSION = platform.python_version()
|
24 | 24 |
|
| 25 | +_IMPORTS = False |
| 26 | +_GOOGLE_API_CLIENT_INSTALLED = False |
| 27 | +_GOOGLE_API_CLIENT_VALID_VERSION = False |
| 28 | +_HTTPLIB2_INSTALLED = False |
| 29 | +_SETUPTOOLS_INSTALLED = False |
| 30 | + |
25 | 31 | def missing_bq():
|
26 | 32 | try:
|
27 | 33 | subprocess.call('bq')
|
28 | 34 | return False
|
29 | 35 | except OSError:
|
30 | 36 | return True
|
31 | 37 |
|
| 38 | +def _test_imports(): |
| 39 | + if not compat.PY3: |
| 40 | + |
| 41 | + global _GOOGLE_API_CLIENT_INSTALLED, _GOOGLE_API_CLIENT_VALID_VERSION, \ |
| 42 | + _HTTPLIB2_INSTALLED, _SETUPTOOLS_INSTALLED |
| 43 | + |
| 44 | + try: |
| 45 | + import pkg_resources |
| 46 | + _SETUPTOOLS_INSTALLED = True |
| 47 | + except ImportError: |
| 48 | + _SETUPTOOLS_INSTALLED = False |
| 49 | + |
| 50 | + if _SETUPTOOLS_INSTALLED: |
| 51 | + try: |
| 52 | + from apiclient.discovery import build |
| 53 | + from apiclient.errors import HttpError |
| 54 | + |
| 55 | + from oauth2client.client import OAuth2WebServerFlow |
| 56 | + from oauth2client.client import AccessTokenRefreshError |
| 57 | + |
| 58 | + from oauth2client.file import Storage |
| 59 | + from oauth2client.tools import run_flow |
| 60 | + _GOOGLE_API_CLIENT_INSTALLED=True |
| 61 | + _GOOGLE_API_CLIENT_VERSION = pkg_resources.get_distribution('google-api-python-client').version |
| 62 | + |
| 63 | + if LooseVersion(_GOOGLE_API_CLIENT_VERSION) >= '1.2.0': |
| 64 | + _GOOGLE_API_CLIENT_VALID_VERSION = True |
| 65 | + |
| 66 | + except ImportError: |
| 67 | + _GOOGLE_API_CLIENT_INSTALLED = False |
| 68 | + |
| 69 | + |
| 70 | + try: |
| 71 | + import httplib2 |
| 72 | + _HTTPLIB2_INSTALLED = True |
| 73 | + except ImportError: |
| 74 | + _HTTPLIB2_INSTALLED = False |
| 75 | + |
| 76 | + |
| 77 | + if compat.PY3: |
| 78 | + raise NotImplementedError("Google's libraries do not support Python 3 yet") |
| 79 | + |
| 80 | + if not _SETUPTOOLS_INSTALLED: |
| 81 | + raise ImportError('Could not import pkg_resources (setuptools).') |
| 82 | + |
| 83 | + if not _GOOGLE_API_CLIENT_INSTALLED: |
| 84 | + raise ImportError('Could not import Google API Client.') |
| 85 | + |
| 86 | + if not _GOOGLE_API_CLIENT_VALID_VERSION: |
| 87 | + raise ImportError("pandas requires google-api-python-client >= 1.2.0 for Google " |
| 88 | + "BigQuery support, current version " + _GOOGLE_API_CLIENT_VERSION) |
| 89 | + |
| 90 | + if not _HTTPLIB2_INSTALLED: |
| 91 | + raise ImportError("pandas requires httplib2 for Google BigQuery support") |
| 92 | + |
32 | 93 | def test_requirements():
|
33 | 94 | try:
|
34 |
| - gbq._test_imports() |
| 95 | + _test_imports() |
35 | 96 | except (ImportError, NotImplementedError) as import_exception:
|
36 | 97 | raise nose.SkipTest(import_exception)
|
37 | 98 |
|
|
0 commit comments