• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

joke2k / django-environ / 4656950294

pending completion
4656950294

push

github

GitHub
Merge pull request #443 from joke2k/develop

260 of 297 branches covered (87.54%)

43 of 43 new or added lines in 4 files covered. (100.0%)

482 of 526 relevant lines covered (91.63%)

16.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.55
/environ/compat.py
1
# This file is part of the django-environ.
2
#
3
# Copyright (c) 2021-2022, Serghei Iakovlev <egrep@protonmail.ch>
4
# Copyright (c) 2013-2021, Daniele Faraglia <daniele.faraglia@gmail.com>
5
#
6
# For the full copyright and license information, please view
7
# the LICENSE.txt file that was distributed with this source code.
8

9
"""This module handles import compatibility issues."""
18✔
10

11
from pkgutil import find_loader
18✔
12

13

14
if find_loader('simplejson'):
18!
15
    import simplejson as json
×
16
else:
17
    import json
18✔
18

19
if find_loader('django'):
18!
20
    from django import VERSION as DJANGO_VERSION
18✔
21
    from django.core.exceptions import ImproperlyConfigured
18✔
22
else:
23
    DJANGO_VERSION = None
×
24

25
    class ImproperlyConfigured(Exception):
×
26
        """Django is somehow improperly configured"""
27

28

29
def choose_rediscache_driver():
18✔
30
    """Backward compatibility for RedisCache driver."""
31
    # use built-in support if Django 4+
32
    if DJANGO_VERSION is not None and DJANGO_VERSION >= (4, 0):
18✔
33
        return 'django.core.cache.backends.redis.RedisCache'
18✔
34

35
    # back compatibility with redis_cache package
36
    if find_loader('redis_cache'):
18✔
37
        return 'redis_cache.RedisCache'
18✔
38
    return 'django_redis.cache.RedisCache'
18✔
39

40

41
def choose_postgres_driver():
18✔
42
    """Backward compatibility for postgresql driver."""
43
    old_django = DJANGO_VERSION is not None and DJANGO_VERSION < (2, 0)
18✔
44
    if old_django:
18!
45
        return 'django.db.backends.postgresql_psycopg2'
×
46
    return 'django.db.backends.postgresql'
18✔
47

48

49
def choose_pymemcache_driver():
18✔
50
    """Backward compatibility for pymemcache."""
51
    old_django = DJANGO_VERSION is not None and DJANGO_VERSION < (3, 2)
18✔
52
    if old_django or not find_loader('pymemcache'):
18✔
53
        # The original backend choice for the 'pymemcache' scheme is
54
        # unfortunately 'pylibmc'.
55
        return 'django.core.cache.backends.memcached.PyLibMCCache'
18✔
56
    return 'django.core.cache.backends.memcached.PyMemcacheCache'
18✔
57

58

59
REDIS_DRIVER = choose_rediscache_driver()
18✔
60
"""The name of the RedisCache driver."""
6✔
61

62
DJANGO_POSTGRES = choose_postgres_driver()
18✔
63
"""The name of the PostgreSQL driver."""
6✔
64

65
PYMEMCACHE_DRIVER = choose_pymemcache_driver()
18✔
66
"""The name of the Pymemcache driver."""
18✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc