Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Only require simplejson if a compatible json library isn't found

  • Loading branch information...
commit 174d438dd0b867c728081bdb049b6868bc088c60 1 parent d225d7c
@gdb gdb authored
Showing with 39 additions and 19 deletions.
  1. +15 −1 setup.py
  2. +3 −18 stripe/__init__.py
  3. +21 −0 stripe/importer.py
View
16 setup.py
@@ -4,11 +4,25 @@
# Don't import stripe module here, since deps may not be installed
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'stripe'))
+import importer
import version
path, script = os.path.split(sys.argv[0])
os.chdir(os.path.abspath(path))
+# Get simplejson if we don't already have json
+install_requires = 'requests'
+try:
+ importer.import_json()
+except ImportError:
+ install_requires.append('simplejson')
+
+try:
+ import json
+ _json_loaded = hasattr(json, 'loads')
+except ImportError:
+ pass
+
setup(name='stripe',
version=version.VERSION,
description='Stripe python bindings',
@@ -17,5 +31,5 @@
url='https://stripe.com/',
packages=['stripe'],
package_data={'stripe' : ['data/ca-certificates.crt', '../VERSION']},
- install_requires=['simplejson', 'requests']
+ install_requires=install_requires
)
View
21 stripe/__init__.py
@@ -20,24 +20,6 @@
except ImportError:
import StringIO
-# Python 2.5 and below do not ship with json
-_json_loaded = None
-try:
- import json
- _json_loaded = hasattr(json, 'loads')
-except ImportError:
- pass
-
-
-if not _json_loaded:
- try:
- import simplejson as json
- except ImportError:
- if _json_loaded is None:
- raise ImportError("Stripe requires a JSON library, which you do not appear to have. Please install the simplejson library. HINT: Try installing the python simplejson library via 'easy_install simplejson', or contact support@stripe.com with questions.")
- else:
- raise ImportError("Stripe requires a JSON library with the same interface as the Python 2.6 'json' library. You appear to have a 'json' library with a different interface. Please install the simplejson library. HINT: Try installing the python simplejson library via 'easy_install simplejson', or contact support@stripe.com with questions.")
-
# - Requests is the preferred HTTP library
# - Google App Engine has urlfetch
# - Use Pycurl if it's there (at least it verifies SSL certs)
@@ -76,6 +58,9 @@
raise ImportError("Stripe requires one of pycurl, Google App Engine's urlfetch, or urllib2. If you are on a platform where none of these libraries are available, please let us know at support@stripe.com.")
from version import VERSION
+import importer
+json = importer.import_json()
+
logger = logging.getLogger('stripe')
## Configuration variables
View
21 stripe/importer.py
@@ -0,0 +1,21 @@
+# Imports needed in setup.py and __init__.py
+
+def import_json():
+ # Python 2.5 and below do not ship with json
+ _json_loaded = None
+ try:
+ import json
+ if hasattr(json, 'loads'):
+ return json
+ _json_loaded = False
+ except ImportError:
+ pass
+
+ try:
+ import simplejson
+ return simplejson
+ except ImportError:
+ if _json_loaded is None:
+ raise ImportError("Stripe requires a JSON library, which you do not appear to have. Please install the simplejson library. HINT: Try installing the python simplejson library via 'pip install simplejson' or 'easy_install simplejson', or contact support@stripe.com with questions.")
+ else:
+ raise ImportError("Stripe requires a JSON library with the same interface as the Python 2.6 'json' library. You appear to have a 'json' library with a different interface. Please install the simplejson library. HINT: Try installing the python simplejson library via 'pip install simplejson' or 'easy_install simplejson', or contact support@stripe.com with questions.")
Please sign in to comment.
Something went wrong with that request. Please try again.