Skip to content

Commit

Permalink
Add helpful error messages when importing optional dependencies (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott committed Mar 6, 2017
1 parent 8170194 commit b9101e3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
7 changes: 6 additions & 1 deletion google/auth/transport/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 the grpcio package to use the '
'gRPC transport.')
import six


Expand Down
8 changes: 6 additions & 2 deletions google/auth/transport/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 the requests '
'package to use the requests transport.')
import requests.exceptions

from google.auth import exceptions
Expand Down
7 changes: 6 additions & 1 deletion google/auth/transport/urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 the urllib3 '
'package to use the urllib3 transport.')
import urllib3.exceptions

from google.auth import exceptions
Expand Down
7 changes: 6 additions & 1 deletion google/oauth2/oauthlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 the '
'requests-oauthlib package to use google.oauth2.oauthlib.')

import google.oauth2.credentials

Expand Down

0 comments on commit b9101e3

Please sign in to comment.