mirror of
https://github.com/django/daphne.git
synced 2025-07-30 16:59:46 +03:00
Add explicit checks for asgi library versions
Refs daphne/#105
This commit is contained in:
parent
c1f801a20e
commit
ceeacdbfc3
|
@ -2,6 +2,7 @@ from django.apps import AppConfig
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
|
||||||
from .binding.base import BindingMetaclass
|
from .binding.base import BindingMetaclass
|
||||||
|
from .package_checks import check_all
|
||||||
|
|
||||||
|
|
||||||
class ChannelsConfig(AppConfig):
|
class ChannelsConfig(AppConfig):
|
||||||
|
@ -10,13 +11,8 @@ class ChannelsConfig(AppConfig):
|
||||||
verbose_name = "Channels"
|
verbose_name = "Channels"
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
# Check you're not running 1.10 or above
|
# Check versions
|
||||||
try:
|
check_all()
|
||||||
from django import channels # NOQA isort:skip
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise ImproperlyConfigured("You have Django 1.10 or above; use the builtin django.channels!")
|
|
||||||
# Do django monkeypatches
|
# Do django monkeypatches
|
||||||
from .hacks import monkeypatch_django
|
from .hacks import monkeypatch_django
|
||||||
monkeypatch_django()
|
monkeypatch_django()
|
||||||
|
|
30
channels/package_checks.py
Normal file
30
channels/package_checks.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import importlib
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
|
|
||||||
|
required_versions = {
|
||||||
|
"asgi_redis": "1.2.0",
|
||||||
|
"asgi_ipc": "1.3.0",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def check_all():
|
||||||
|
"""
|
||||||
|
Checks versions of all the possible packages you have installed so that
|
||||||
|
we can easily warn people about incompatible versions.
|
||||||
|
|
||||||
|
This is needed as there are some packages (e.g. asgi_redis) that we cannot
|
||||||
|
declare dependencies on as they are not _required_. People usually remember
|
||||||
|
to upgrade their Channels package so this is where we check.
|
||||||
|
"""
|
||||||
|
for package, version in required_versions.items():
|
||||||
|
try:
|
||||||
|
module = importlib.import_module(package)
|
||||||
|
except ImportError:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
if StrictVersion(version) > StrictVersion(module.__version__):
|
||||||
|
raise RuntimeError("Your version of %s is too old - it must be at least %s" % (
|
||||||
|
package,
|
||||||
|
version,
|
||||||
|
))
|
Loading…
Reference in New Issue
Block a user