From fc52e3c5a23aaacb078a5f357e125285fa22c597 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 9 Sep 2015 20:58:32 -0500 Subject: [PATCH] Remove auto-importing of modules --- channels/management/commands/runserver.py | 6 ++---- channels/management/commands/runworker.py | 2 -- channels/management/commands/runwsserver.py | 2 -- channels/utils.py | 21 --------------------- 4 files changed, 2 insertions(+), 29 deletions(-) diff --git a/channels/management/commands/runserver.py b/channels/management/commands/runserver.py index ddc1731..34154b9 100644 --- a/channels/management/commands/runserver.py +++ b/channels/management/commands/runserver.py @@ -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: diff --git a/channels/management/commands/runworker.py b/channels/management/commands/runworker.py index 8d8b2ae..dd0bb9c 100644 --- a/channels/management/commands/runworker.py +++ b/channels/management/commands/runworker.py @@ -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" diff --git a/channels/management/commands/runwsserver.py b/channels/management/commands/runwsserver.py index 9434be0..7b4d296 100644 --- a/channels/management/commands/runwsserver.py +++ b/channels/management/commands/runwsserver.py @@ -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" diff --git a/channels/utils.py b/channels/utils.py index 4a7fb65..2cddb58 100644 --- a/channels/utils.py +++ b/channels/utils.py @@ -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):