diff options
| author | Garrett-R <garrettreynolds5@gmail.com> | 2016-02-27 23:32:06 -0800 |
|---|---|---|
| committer | Garrett-R <garrettreynolds5@gmail.com> | 2016-02-28 00:02:50 -0800 |
| commit | fa751d543ea2d72526295fdd3e918a765c82555c (patch) | |
| tree | 1b62dfbab761b26d9ce3bfb3f8087f2da215e672 /requests_cache | |
| parent | bb4dd87161959361013854e678ceaa2d9dbd8d53 (diff) | |
| download | requests-cache-fa751d543ea2d72526295fdd3e918a765c82555c.tar.gz | |
More informative message for missing backend dependencies
Currently, if you don't have the Python package `redis` intalled
then you get the same message if you type:
requests_cache.install_cache(backend='redis')
as if you type:
requests_cache.install_cache(backend='nonsense!!!!')
Diffstat (limited to 'requests_cache')
| -rw-r--r-- | requests_cache/backends/__init__.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/requests_cache/backends/__init__.py b/requests_cache/backends/__init__.py index 29da672..433d405 100644 --- a/requests_cache/backends/__init__.py +++ b/requests_cache/backends/__init__.py @@ -14,6 +14,12 @@ registry = { 'memory': BaseCache, } +_backend_dependencies = { + 'sqlite': 'sqlite3', + 'mongo': 'pymongo', + 'redis': 'redis' +} + try: # Heroku doesn't allow the SQLite3 module to be installed from .sqlite import DbCache @@ -40,11 +46,16 @@ def create_backend(backend_name, cache_name, options): try: return registry[backend_name](cache_name, **options) except KeyError: - raise ValueError('Unsupported backend "%s" try one of: %s' % - (backend_name, ', '.join(registry.keys()))) + if backend_name in _backend_dependencies: + raise ImportError('You must install the python package: %s' % + _backend_dependencies[backend_name]) + else: + raise ValueError('Unsupported backend "%s" try one of: %s' % + (backend_name, ', '.join(registry.keys()))) def _get_default_backend_name(): if 'sqlite' in registry: return 'sqlite' - return 'memory'
\ No newline at end of file + return 'memory' + |
