Skip to content

Commit cfb3f10

Browse files
author
Ilya Volodarsky
committed
adding helpful message for when analytics module is not initialized
1 parent 3e052ee commit cfb3f10

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

analytics/__init__.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11

2-
VERSION = '0.3.2'
2+
VERSION = '0.3.3'
33

44
import sys
55

66
try:
77
import requests
88
except ImportError:
9-
print >>sys.stderr, 'analytics-node requires that you have a Python "requests" library installed. Try running "pip install requests"'
9+
print >>sys.stderr, 'analytics-python requires that you have a Python "requests" library installed. Try running "pip install requests"'
10+
11+
import sys
12+
this_module = sys.modules[__name__]
1013

1114
from stats import Statistics
1215
stats = Statistics()
1316

1417
from client import Client
1518

19+
methods = ['identify', 'track', 'flush', 'on_success', 'on_failure']
20+
21+
22+
def uninitialized(*args, **kwargs):
23+
print >>sys.stderr, 'Please call analytics.init(secret) before calling analytics methods.'
24+
25+
for method in methods:
26+
setattr(this_module, method, uninitialized)
27+
1628

1729
def init(secret, **kwargs):
1830
"""Create a default instance of a analytics-python client
@@ -35,8 +47,7 @@ def init(secret, **kwargs):
3547
3648
"""
3749

38-
import sys
39-
this_module = sys.modules[__name__]
50+
# if we have already initialized, no-op
4051
if hasattr(this_module, 'default_client'):
4152
return
4253

@@ -51,6 +62,5 @@ def proxy_to_default_client(*args, **kwargs):
5162

5263
setattr(this_module, method, proxy_to_default_client)
5364

54-
methods = ['identify', 'track', 'flush', 'on_success', 'on_failure']
5565
for method in methods:
5666
proxy(method)

0 commit comments

Comments
 (0)