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

joke2k / django-environ / 11748032612

08 Nov 2024 07:04PM UTC coverage: 92.654% (+0.4%) from 92.215%
11748032612

Pull #545

github

sergeyklay
Merge branch 'main' into develop
Pull Request #545: Release v0.12.0

269 of 312 branches covered (86.22%)

28 of 31 new or added lines in 2 files covered. (90.32%)

2 existing lines in 1 file now uncovered.

555 of 599 relevant lines covered (92.65%)

16.47 hits per line

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

93.75
/environ/compat.py
1
# This file is part of the django-environ.
2
#
3
# Copyright (c) 2021-2024, Serghei Iakovlev <oss@serghei.pl>
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."""
3✔
10

11
from importlib.util import find_spec
18✔
12

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

18
if find_spec('django'):
18✔
UNCOV
19
    from django import VERSION as DJANGO_VERSION
6✔
UNCOV
20
    from django.core.exceptions import ImproperlyConfigured
6✔
21
else:
22
    DJANGO_VERSION = None
12✔
23

24
    class ImproperlyConfigured(Exception):
12✔
25
        """Django is somehow improperly configured"""
26

27

28
def choose_rediscache_driver():
18✔
29
    """Backward compatibility for RedisCache driver."""
30

31
    # django-redis library takes precedence
32
    if find_spec('django_redis'):
18✔
33
        return 'django_redis.cache.RedisCache'
18✔
34

35
    # use built-in support if Django 4+
36
    if DJANGO_VERSION is not None and DJANGO_VERSION >= (4, 0):
18✔
37
        return 'django.core.cache.backends.redis.RedisCache'
18✔
38

39
    # back compatibility with redis_cache package
40
    return 'redis_cache.RedisCache'
18✔
41

42

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

50

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

60

61
REDIS_DRIVER = choose_rediscache_driver()
18✔
62
"""The name of the RedisCache driver."""
15✔
63

64
DJANGO_POSTGRES = choose_postgres_driver()
18✔
65
"""The name of the PostgreSQL driver."""
15✔
66

67
PYMEMCACHE_DRIVER = choose_pymemcache_driver()
18✔
68
"""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

© 2025 Coveralls, Inc