Some import sorting stuff

This commit is contained in:
Andrew Godwin 2016-04-05 17:38:05 -07:00
parent 11218089bd
commit 732167282b
3 changed files with 37 additions and 20 deletions

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.utils import six from django.utils import six
from channels import DEFAULT_CHANNEL_LAYER, channel_layers from channels import DEFAULT_CHANNEL_LAYER, channel_layers

View File

@ -1,7 +1,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.core.management import BaseCommand, CommandError from django.core.management import BaseCommand, CommandError
from channels import channel_layers, DEFAULT_CHANNEL_LAYER
from channels import DEFAULT_CHANNEL_LAYER, channel_layers
from channels.log import setup_logger from channels.log import setup_logger
from channels.worker import Worker from channels.worker import Worker

View File

@ -11,6 +11,8 @@ import re
import os.path import os.path
import sys import sys
from isort import SortImports
# Transforms: Turn one content string into another # Transforms: Turn one content string into another
@ -48,6 +50,15 @@ class Insert(object):
return value[:match.start()] + self.to_insert + value[match.start():] return value[:match.start()] + self.to_insert + value[match.start():]
class Isort(object):
"""
Runs isort on the file
"""
def __call__(self, value):
return SortImports(file_contents=value).output
# Operations: Copy or patch files # Operations: Copy or patch files
class FileMap(object): class FileMap(object):
@ -108,7 +119,11 @@ global_transforms = [
Replacement(r"from .handler import", r"from django.core.handlers.asgi import"), Replacement(r"from .handler import", r"from django.core.handlers.asgi import"),
Replacement(r"from django.channels.tests import", r"from django.test.channels import"), Replacement(r"from django.channels.tests import", r"from django.test.channels import"),
Replacement(r"from django.channels.handler import", r"from django.core.handlers.asgi import"), Replacement(r"from django.channels.handler import", r"from django.core.handlers.asgi import"),
Replacement(r"channels.tests.test_routing", r"channels_tests.test_routing") Replacement(r"channels.tests.test_routing", r"channels_tests.test_routing"),
]
python_transforms = global_transforms + [
Isort(),
] ]
docs_transforms = global_transforms + [ docs_transforms = global_transforms + [
@ -129,64 +144,64 @@ class Patchinator(object):
operations = [ operations = [
FileMap( FileMap(
"channels/asgi.py", "django/channels/asgi.py", global_transforms, "channels/asgi.py", "django/channels/asgi.py", python_transforms,
), ),
FileMap( FileMap(
"channels/auth.py", "django/channels/auth.py", global_transforms, "channels/auth.py", "django/channels/auth.py", python_transforms,
), ),
FileMap( FileMap(
"channels/channel.py", "django/channels/channel.py", global_transforms, "channels/channel.py", "django/channels/channel.py", python_transforms,
), ),
FileMap( FileMap(
"channels/database_layer.py", "django/channels/database_layer.py", global_transforms, "channels/database_layer.py", "django/channels/database_layer.py", python_transforms,
), ),
FileMap( FileMap(
"channels/exceptions.py", "django/channels/exceptions.py", global_transforms, "channels/exceptions.py", "django/channels/exceptions.py", python_transforms,
), ),
FileMap( FileMap(
"channels/handler.py", "django/core/handlers/asgi.py", global_transforms, "channels/handler.py", "django/core/handlers/asgi.py", python_transforms,
), ),
FileMap( FileMap(
"channels/routing.py", "django/channels/routing.py", global_transforms, "channels/routing.py", "django/channels/routing.py", python_transforms,
), ),
FileMap( FileMap(
"channels/message.py", "django/channels/message.py", global_transforms, "channels/message.py", "django/channels/message.py", python_transforms,
), ),
FileMap( FileMap(
"channels/sessions.py", "django/channels/sessions.py", global_transforms, "channels/sessions.py", "django/channels/sessions.py", python_transforms,
), ),
FileMap( FileMap(
"channels/staticfiles.py", "django/contrib/staticfiles/consumers.py", global_transforms, "channels/staticfiles.py", "django/contrib/staticfiles/consumers.py", python_transforms,
), ),
FileMap( FileMap(
"channels/utils.py", "django/channels/utils.py", global_transforms, "channels/utils.py", "django/channels/utils.py", python_transforms,
), ),
FileMap( FileMap(
"channels/worker.py", "django/channels/worker.py", global_transforms, "channels/worker.py", "django/channels/worker.py", python_transforms,
), ),
FileMap( FileMap(
"channels/management/commands/runworker.py", "channels/management/commands/runworker.py",
"django/core/management/commands/runworker.py", "django/core/management/commands/runworker.py",
global_transforms, python_transforms,
), ),
# Tests # Tests
FileMap( FileMap(
"channels/tests/base.py", "django/test/channels.py", global_transforms, "channels/tests/base.py", "django/test/channels.py", python_transforms,
), ),
NewFile( NewFile(
"tests/channels_tests/__init__.py", "tests/channels_tests/__init__.py",
), ),
FileMap( FileMap(
"channels/tests/test_database_layer.py", "tests/channels_tests/test_database_layer.py", global_transforms, "channels/tests/test_database_layer.py", "tests/channels_tests/test_database_layer.py", python_transforms,
), ),
FileMap( FileMap(
"channels/tests/test_handler.py", "tests/channels_tests/test_handler.py", global_transforms, "channels/tests/test_handler.py", "tests/channels_tests/test_handler.py", python_transforms,
), ),
FileMap( FileMap(
"channels/tests/test_routing.py", "tests/channels_tests/test_routing.py", global_transforms, "channels/tests/test_routing.py", "tests/channels_tests/test_routing.py", python_transforms,
), ),
FileMap( FileMap(
"channels/tests/test_request.py", "tests/channels_tests/test_request.py", global_transforms, "channels/tests/test_request.py", "tests/channels_tests/test_request.py", python_transforms,
), ),
# Docs # Docs
FileMap( FileMap(