Skip to content

Commit

Permalink
Move is_installed from setup.py to jsonpickle.util so it can be used …
Browse files Browse the repository at this point in the history
…to check for backends' existence.
  • Loading branch information
johnpaulett committed May 13, 2010
1 parent 6de3e5a commit afbd769
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 16 additions & 0 deletions jsonpickle/util.py
Expand Up @@ -210,3 +210,19 @@ def is_picklable(name, value):
if name in tags.RESERVED:
return False
return not is_function(value)

def is_installed(module):
"""Tests to see if ``module`` is available on the sys.path
>>> is_installed('sys')
True
>>> is_installed('hopefullythisisnotarealmodule')
False
"""
try:
__import__(module)
return True
except ImportError, e:
return False

8 changes: 1 addition & 7 deletions setup.py
Expand Up @@ -47,17 +47,11 @@ def main():
def _check_dependencies():
# check to see if any of the supported backends is installed
backends = _jsonpickle.SUPPORTED_BACKENDS
if not any([_is_installed(module) for module in backends]):
if not any([_jsonpickle.util.is_installed(module) for module in backends]):
print >> sys.stderr, ('No supported JSON backend found. '
'Must install one of %s' % (', '.join(backends)))
sys.exit(1)

def _is_installed(module):
try:
__import__(module)
return True
except ImportError, e:
return False

if __name__ == '__main__':
sys.exit(main())

0 comments on commit afbd769

Please sign in to comment.