Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbaad28

Browse files
authored
prevent stray imports of older 'apiclient' alias from raising an ImportError
Prevent stray imports of older 'apiclient' alias from raising an ImportError if oauth2client is not installed, unless sample_tools.init is actually called. Closes googleapis#524
1 parent c7533a0 commit bbaad28

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

googleapiclient/sample_tools.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828
from googleapiclient import discovery
2929
from googleapiclient.http import build_http
3030

31-
try:
32-
from oauth2client import client
33-
from oauth2client import file
34-
from oauth2client import tools
35-
except ImportError:
36-
raise ImportError('googleapiclient.sample_tools requires oauth2client. Please install oauth2client and try again.')
37-
38-
3931
def init(argv, name, version, doc, filename, scope=None, parents=[], discovery_filename=None):
4032
"""A common initialization routine for samples.
4133
@@ -60,6 +52,13 @@ def init(argv, name, version, doc, filename, scope=None, parents=[], discovery_f
6052
A tuple of (service, flags), where service is the service object and flags
6153
is the parsed command-line flags.
6254
"""
55+
try:
56+
from oauth2client import client
57+
from oauth2client import file
58+
from oauth2client import tools
59+
except ImportError:
60+
raise ImportError('googleapiclient.sample_tools requires oauth2client. Please install oauth2client and try again.')
61+
6362
if scope is None:
6463
scope = 'https://www.googleapis.com/auth/' + name
6564

samples/maps_engine/maps_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
import sys
4848
import time
4949

50-
from apiclient import sample_tools
51-
from apiclient.http import MediaFileUpload
50+
from googleapiclient import sample_tools
51+
from googleapiclient.http import MediaFileUpload
5252

5353
logging.basicConfig(level=logging.INFO)
5454

samples/prediction/prediction.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@
3939
'[email protected] (Marc Cohen)')
4040

4141
import argparse
42-
import os
4342
import pprint
4443
import sys
4544
import time
4645

47-
from apiclient import discovery
4846
from apiclient import sample_tools
4947
from oauth2client import client
5048

0 commit comments

Comments
 (0)