mirror of
https://github.com/django/daphne.git
synced 2025-04-21 17:22:03 +03:00
Remove auto-importing of modules
This commit is contained in:
parent
041ea3fa5c
commit
fc52e3c5a2
|
@ -4,7 +4,6 @@ from django.core.management.commands.runserver import Command as RunserverComman
|
|||
from django.core.management import CommandError
|
||||
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
||||
from channels.worker import Worker
|
||||
from channels.utils import auto_import_consumers
|
||||
from channels.adapters import UrlConsumer
|
||||
from channels.interfaces.wsgi import WSGIInterface
|
||||
|
||||
|
@ -24,10 +23,9 @@ class Command(RunserverCommand):
|
|||
def inner_run(self, *args, **options):
|
||||
# Check a handler is registered for http reqs
|
||||
self.channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
|
||||
auto_import_consumers()
|
||||
if not self.channel_backend.registry.consumer_for_channel("django.wsgi.request"):
|
||||
if not self.channel_backend.registry.consumer_for_channel("http.request"):
|
||||
# Register the default one
|
||||
self.channel_backend.registry.add_consumer(UrlConsumer(), ["django.wsgi.request"])
|
||||
self.channel_backend.registry.add_consumer(UrlConsumer(), ["http.request"])
|
||||
# Note that this is the right one on the console
|
||||
self.stdout.write("Worker thread running, channels enabled")
|
||||
if self.channel_backend.local_only:
|
||||
|
|
|
@ -3,7 +3,6 @@ from wsgiref.simple_server import BaseHTTPRequestHandler
|
|||
from django.core.management import BaseCommand, CommandError
|
||||
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
||||
from channels.worker import Worker
|
||||
from channels.utils import auto_import_consumers
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -11,7 +10,6 @@ class Command(BaseCommand):
|
|||
def handle(self, *args, **options):
|
||||
# Get the backend to use
|
||||
channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
|
||||
auto_import_consumers()
|
||||
if channel_backend.local_only:
|
||||
raise CommandError(
|
||||
"You have a process-local channel backend configured, and so cannot run separate workers.\n"
|
||||
|
|
|
@ -2,7 +2,6 @@ import time
|
|||
from django.core.management import BaseCommand, CommandError
|
||||
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
||||
from channels.interfaces.websocket_twisted import WebsocketTwistedInterface
|
||||
from channels.utils import auto_import_consumers
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -14,7 +13,6 @@ class Command(BaseCommand):
|
|||
def handle(self, *args, **options):
|
||||
# Get the backend to use
|
||||
channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
|
||||
auto_import_consumers()
|
||||
if channel_backend.local_only:
|
||||
raise CommandError(
|
||||
"You have a process-local channel backend configured, and so cannot run separate interface servers.\n"
|
||||
|
|
|
@ -1,25 +1,4 @@
|
|||
import types
|
||||
from django.apps import apps
|
||||
|
||||
from six import PY3
|
||||
|
||||
def auto_import_consumers():
|
||||
"""
|
||||
Auto-import consumers modules in apps
|
||||
"""
|
||||
for app_config in apps.get_app_configs():
|
||||
for submodule in ["consumers", "views"]:
|
||||
module_name = "%s.%s" % (app_config.name, submodule)
|
||||
try:
|
||||
__import__(module_name)
|
||||
except ImportError as e:
|
||||
err = str(e).lower()
|
||||
if PY3:
|
||||
if "no module named '%s'" % (module_name,) not in err:
|
||||
raise
|
||||
else:
|
||||
if "no module named %s" % (submodule,) not in err:
|
||||
raise
|
||||
|
||||
|
||||
def name_that_thing(thing):
|
||||
|
|
Loading…
Reference in New Issue
Block a user