Skip to content

Commit

Permalink
Remove auto-importing of modules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgodwin committed Sep 10, 2015
1 parent 041ea3f commit fc52e3c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 29 deletions.
6 changes: 2 additions & 4 deletions channels/management/commands/runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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

Expand All @@ -24,10 +23,9 @@ def run(self, *args, **options):
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:
Expand Down
2 changes: 0 additions & 2 deletions channels/management/commands/runworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
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):

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"
Expand Down
2 changes: 0 additions & 2 deletions channels/management/commands/runwsserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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):
Expand All @@ -14,7 +13,6 @@ def add_arguments(self, parser):
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"
Expand Down
21 changes: 0 additions & 21 deletions channels/utils.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit fc52e3c

Please sign in to comment.