From 518b560ccd5af04a19dda138c67c4fa59cda3e13 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Wed, 1 Mar 2017 10:27:36 -0800 Subject: [PATCH 1/2] Add helpful error messages when importing optional dependencies --- google/auth/transport/grpc.py | 7 ++++++- google/auth/transport/requests.py | 8 ++++++-- google/auth/transport/urllib3.py | 7 ++++++- google/oauth2/oauthlib.py | 7 ++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/google/auth/transport/grpc.py b/google/auth/transport/grpc.py index 81d565865..02535244d 100644 --- a/google/auth/transport/grpc.py +++ b/google/auth/transport/grpc.py @@ -16,7 +16,12 @@ from __future__ import absolute_import -import grpc +try: + import grpc +except ImportError: # pragma: NO COVER + raise ImportError( + 'gRPC is not installed, please install grpcio to use the gRPC ' + 'transport.') import six diff --git a/google/auth/transport/requests.py b/google/auth/transport/requests.py index e21109024..7f8abaebd 100644 --- a/google/auth/transport/requests.py +++ b/google/auth/transport/requests.py @@ -18,8 +18,12 @@ import logging - -import requests +try: + import requests +except ImportError: # pragma: NO COVER + raise ImportError( + 'The requests library is not installed, please install requests to ' + 'use the requests transport.') import requests.exceptions from google.auth import exceptions diff --git a/google/auth/transport/urllib3.py b/google/auth/transport/urllib3.py index 9d417b5b6..8057cfff8 100644 --- a/google/auth/transport/urllib3.py +++ b/google/auth/transport/urllib3.py @@ -30,7 +30,12 @@ except ImportError: # pragma: NO COVER certifi = None -import urllib3 +try: + import urllib3 +except ImportError: # pragma: NO COVER + raise ImportError( + 'The urllib3 library is not installed, please install urllib3 to ' + 'use the urllib3 transport.') import urllib3.exceptions from google.auth import exceptions diff --git a/google/oauth2/oauthlib.py b/google/oauth2/oauthlib.py index 8f5c10575..957d8c654 100644 --- a/google/oauth2/oauthlib.py +++ b/google/oauth2/oauthlib.py @@ -27,7 +27,12 @@ import json -import requests_oauthlib +try: + import requests_oauthlib +except ImportError: # pragma: NO COVER + raise ImportError( + 'The requests-oauthlib library is not installed, please install ' + 'requests-oauthlib to use google.oauth2.oauthlib.') import google.oauth2.credentials From b31a5b850462c2c7775e917c60287f8abbe6c927 Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Wed, 1 Mar 2017 12:23:54 -0800 Subject: [PATCH 2/2] Mention package names explicitly --- google/auth/transport/grpc.py | 4 ++-- google/auth/transport/requests.py | 4 ++-- google/auth/transport/urllib3.py | 4 ++-- google/oauth2/oauthlib.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/google/auth/transport/grpc.py b/google/auth/transport/grpc.py index 02535244d..8554ffa36 100644 --- a/google/auth/transport/grpc.py +++ b/google/auth/transport/grpc.py @@ -20,8 +20,8 @@ import grpc except ImportError: # pragma: NO COVER raise ImportError( - 'gRPC is not installed, please install grpcio to use the gRPC ' - 'transport.') + 'gRPC is not installed, please install the grpcio package to use the ' + 'gRPC transport.') import six diff --git a/google/auth/transport/requests.py b/google/auth/transport/requests.py index 7f8abaebd..0c66fdd41 100644 --- a/google/auth/transport/requests.py +++ b/google/auth/transport/requests.py @@ -22,8 +22,8 @@ import requests except ImportError: # pragma: NO COVER raise ImportError( - 'The requests library is not installed, please install requests to ' - 'use the requests transport.') + 'The requests library is not installed, please install the requests ' + 'package to use the requests transport.') import requests.exceptions from google.auth import exceptions diff --git a/google/auth/transport/urllib3.py b/google/auth/transport/urllib3.py index 8057cfff8..a08f4275c 100644 --- a/google/auth/transport/urllib3.py +++ b/google/auth/transport/urllib3.py @@ -34,8 +34,8 @@ import urllib3 except ImportError: # pragma: NO COVER raise ImportError( - 'The urllib3 library is not installed, please install urllib3 to ' - 'use the urllib3 transport.') + 'The urllib3 library is not installed, please install the urllib3 ' + 'package to use the urllib3 transport.') import urllib3.exceptions from google.auth import exceptions diff --git a/google/oauth2/oauthlib.py b/google/oauth2/oauthlib.py index 957d8c654..e1c608972 100644 --- a/google/oauth2/oauthlib.py +++ b/google/oauth2/oauthlib.py @@ -31,8 +31,8 @@ import requests_oauthlib except ImportError: # pragma: NO COVER raise ImportError( - 'The requests-oauthlib library is not installed, please install ' - 'requests-oauthlib to use google.oauth2.oauthlib.') + 'The requests-oauthlib library is not installed, please install the ' + 'requests-oauthlib package to use google.oauth2.oauthlib.') import google.oauth2.credentials