mirror of
https://github.com/django/daphne.git
synced 2025-07-13 09:22:17 +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 django.core.management import CommandError
|
||||||
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
||||||
from channels.worker import Worker
|
from channels.worker import Worker
|
||||||
from channels.utils import auto_import_consumers
|
|
||||||
from channels.adapters import UrlConsumer
|
from channels.adapters import UrlConsumer
|
||||||
from channels.interfaces.wsgi import WSGIInterface
|
from channels.interfaces.wsgi import WSGIInterface
|
||||||
|
|
||||||
|
@ -24,10 +23,9 @@ class Command(RunserverCommand):
|
||||||
def inner_run(self, *args, **options):
|
def inner_run(self, *args, **options):
|
||||||
# Check a handler is registered for http reqs
|
# Check a handler is registered for http reqs
|
||||||
self.channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
|
self.channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
|
||||||
auto_import_consumers()
|
if not self.channel_backend.registry.consumer_for_channel("http.request"):
|
||||||
if not self.channel_backend.registry.consumer_for_channel("django.wsgi.request"):
|
|
||||||
# Register the default one
|
# 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
|
# Note that this is the right one on the console
|
||||||
self.stdout.write("Worker thread running, channels enabled")
|
self.stdout.write("Worker thread running, channels enabled")
|
||||||
if self.channel_backend.local_only:
|
if self.channel_backend.local_only:
|
||||||
|
|
|
@ -3,7 +3,6 @@ from wsgiref.simple_server import BaseHTTPRequestHandler
|
||||||
from django.core.management import BaseCommand, CommandError
|
from django.core.management import BaseCommand, CommandError
|
||||||
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
||||||
from channels.worker import Worker
|
from channels.worker import Worker
|
||||||
from channels.utils import auto_import_consumers
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -11,7 +10,6 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
# Get the backend to use
|
# Get the backend to use
|
||||||
channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
|
channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
|
||||||
auto_import_consumers()
|
|
||||||
if channel_backend.local_only:
|
if channel_backend.local_only:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"You have a process-local channel backend configured, and so cannot run separate workers.\n"
|
"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 django.core.management import BaseCommand, CommandError
|
||||||
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
from channels import channel_backends, DEFAULT_CHANNEL_BACKEND
|
||||||
from channels.interfaces.websocket_twisted import WebsocketTwistedInterface
|
from channels.interfaces.websocket_twisted import WebsocketTwistedInterface
|
||||||
from channels.utils import auto_import_consumers
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -14,7 +13,6 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
# Get the backend to use
|
# Get the backend to use
|
||||||
channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
|
channel_backend = channel_backends[DEFAULT_CHANNEL_BACKEND]
|
||||||
auto_import_consumers()
|
|
||||||
if channel_backend.local_only:
|
if channel_backend.local_only:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"You have a process-local channel backend configured, and so cannot run separate interface servers.\n"
|
"You have a process-local channel backend configured, and so cannot run separate interface servers.\n"
|
||||||
|
|
|
@ -1,25 +1,4 @@
|
||||||
import types
|
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):
|
def name_that_thing(thing):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user