Merge pull request #1371 from yunstanford/integrate-isort

codestyle: Integrate isort
This commit is contained in:
Eli Uriegas 2018-10-23 16:05:36 -07:00 committed by GitHub
commit 905c51bef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 93 additions and 55 deletions

View File

@ -1,6 +1,7 @@
from sanic.app import Sanic from sanic.app import Sanic
from sanic.blueprints import Blueprint from sanic.blueprints import Blueprint
__version__ = "0.8.3" __version__ = "0.8.3"
__all__ = ["Sanic", "Blueprint"] __all__ = ["Sanic", "Blueprint"]

View File

@ -1,8 +1,9 @@
from argparse import ArgumentParser from argparse import ArgumentParser
from importlib import import_module from importlib import import_module
from sanic.log import logger
from sanic.app import Sanic from sanic.app import Sanic
from sanic.log import logger
if __name__ == "__main__": if __name__ == "__main__":
parser = ArgumentParser(prog="sanic") parser = ArgumentParser(prog="sanic")

View File

@ -1,29 +1,30 @@
import os
import logging import logging
import logging.config import logging.config
import os
import re import re
import warnings import warnings
from asyncio import get_event_loop, ensure_future, CancelledError
from collections import deque, defaultdict from asyncio import CancelledError, ensure_future, get_event_loop
from collections import defaultdict, deque
from functools import partial from functools import partial
from inspect import getmodulename, isawaitable, signature, stack from inspect import getmodulename, isawaitable, signature, stack
from ssl import Purpose, create_default_context
from traceback import format_exc from traceback import format_exc
from urllib.parse import urlencode, urlunparse from urllib.parse import urlencode, urlunparse
from ssl import create_default_context, Purpose
from sanic import reloader_helpers
from sanic.config import Config from sanic.config import Config
from sanic.constants import HTTP_METHODS from sanic.constants import HTTP_METHODS
from sanic.exceptions import ServerError, URLBuildError, SanicException from sanic.exceptions import SanicException, ServerError, URLBuildError
from sanic.handlers import ErrorHandler from sanic.handlers import ErrorHandler
from sanic.log import logger, error_logger, LOGGING_CONFIG_DEFAULTS from sanic.log import LOGGING_CONFIG_DEFAULTS, error_logger, logger
from sanic.response import HTTPResponse, StreamingHTTPResponse from sanic.response import HTTPResponse, StreamingHTTPResponse
from sanic.router import Router from sanic.router import Router
from sanic.server import serve, serve_multiple, HttpProtocol, Signal from sanic.server import HttpProtocol, Signal, serve, serve_multiple
from sanic.static import register as static_register from sanic.static import register as static_register
from sanic.testing import SanicTestClient from sanic.testing import SanicTestClient
from sanic.views import CompositionView from sanic.views import CompositionView
from sanic.websocket import WebSocketProtocol, ConnectionClosed from sanic.websocket import ConnectionClosed, WebSocketProtocol
import sanic.reloader_helpers as reloader_helpers
class Sanic: class Sanic:

View File

@ -3,6 +3,7 @@ from collections import defaultdict, namedtuple
from sanic.constants import HTTP_METHODS from sanic.constants import HTTP_METHODS
from sanic.views import CompositionView from sanic.views import CompositionView
FutureRoute = namedtuple( FutureRoute = namedtuple(
"Route", "Route",
[ [

View File

@ -1,6 +1,7 @@
import re import re
import string import string
# ------------------------------------------------------------ # # ------------------------------------------------------------ #
# SimpleCookie # SimpleCookie
# ------------------------------------------------------------ # # ------------------------------------------------------------ #

View File

@ -1,5 +1,6 @@
from sanic.helpers import STATUS_CODES from sanic.helpers import STATUS_CODES
TRACEBACK_STYLE = """ TRACEBACK_STYLE = """
<style> <style>
body { body {

View File

@ -1,20 +1,21 @@
import sys import sys
from traceback import extract_tb, format_exc from traceback import extract_tb, format_exc
from sanic.exceptions import ( from sanic.exceptions import (
ContentRangeError,
HeaderNotFound,
INTERNAL_SERVER_ERROR_HTML, INTERNAL_SERVER_ERROR_HTML,
InvalidRangeType, TRACEBACK_BORDER,
SanicException,
TRACEBACK_LINE_HTML, TRACEBACK_LINE_HTML,
TRACEBACK_STYLE, TRACEBACK_STYLE,
TRACEBACK_WRAPPER_HTML, TRACEBACK_WRAPPER_HTML,
TRACEBACK_WRAPPER_INNER_HTML, TRACEBACK_WRAPPER_INNER_HTML,
TRACEBACK_BORDER, ContentRangeError,
HeaderNotFound,
InvalidRangeType,
SanicException,
) )
from sanic.log import logger from sanic.log import logger
from sanic.response import text, html from sanic.response import html, text
class ErrorHandler: class ErrorHandler:

View File

@ -1,9 +1,10 @@
import os import os
import sys
import signal import signal
import subprocess import subprocess
from time import sleep import sys
from multiprocessing import Process from multiprocessing import Process
from time import sleep
def _iter_module_files(): def _iter_module_files():

View File

@ -1,11 +1,17 @@
import sys
import json import json
import sys
from cgi import parse_header from cgi import parse_header
from collections import namedtuple from collections import namedtuple
from http.cookies import SimpleCookie from http.cookies import SimpleCookie
from httptools import parse_url
from urllib.parse import parse_qs, urlunparse from urllib.parse import parse_qs, urlunparse
from httptools import parse_url
from sanic.exceptions import InvalidUsage
from sanic.log import error_logger, logger
try: try:
from ujson import loads as json_loads from ujson import loads as json_loads
except ImportError: except ImportError:
@ -18,8 +24,6 @@ except ImportError:
else: else:
json_loads = json.loads json_loads = json.loads
from sanic.exceptions import InvalidUsage
from sanic.log import error_logger, logger
DEFAULT_HTTP_CONTENT_TYPE = "application/octet-stream" DEFAULT_HTTP_CONTENT_TYPE = "application/octet-stream"

View File

@ -2,17 +2,18 @@ from mimetypes import guess_type
from os import path from os import path
from urllib.parse import quote_plus from urllib.parse import quote_plus
from aiofiles import open as open_async
from multidict import CIMultiDict
from sanic.cookies import CookieJar
from sanic.helpers import STATUS_CODES, has_message_body, remove_entity_headers
try: try:
from ujson import dumps as json_dumps from ujson import dumps as json_dumps
except BaseException: except BaseException:
from json import dumps as json_dumps from json import dumps as json_dumps
from aiofiles import open as open_async
from multidict import CIMultiDict
from sanic.helpers import STATUS_CODES, has_message_body, remove_entity_headers
from sanic.cookies import CookieJar
class BaseHTTPResponse: class BaseHTTPResponse:
def _encode_body(self, data): def _encode_body(self, data):

View File

@ -1,13 +1,15 @@
import re import re
import uuid import uuid
from collections import defaultdict, namedtuple from collections import defaultdict, namedtuple
from collections.abc import Iterable from collections.abc import Iterable
from functools import lru_cache from functools import lru_cache
from urllib.parse import unquote from urllib.parse import unquote
from sanic.exceptions import NotFound, MethodNotSupported from sanic.exceptions import MethodNotSupported, NotFound
from sanic.views import CompositionView from sanic.views import CompositionView
Route = namedtuple( Route = namedtuple(
"Route", ["handler", "methods", "pattern", "parameters", "name", "uri"] "Route", ["handler", "methods", "pattern", "parameters", "name", "uri"]
) )

View File

@ -1,17 +1,31 @@
import asyncio import asyncio
import os import os
import traceback import traceback
from functools import partial from functools import partial
from inspect import isawaitable from inspect import isawaitable
from multiprocessing import Process from multiprocessing import Process
from signal import SIGTERM, SIGINT, SIG_IGN, signal as signal_func, Signals from signal import SIG_IGN, SIGINT, SIGTERM, Signals
from socket import socket, SOL_SOCKET, SO_REUSEADDR from signal import signal as signal_func
from socket import SO_REUSEADDR, SOL_SOCKET, socket
from time import time from time import time
from httptools import HttpRequestParser from httptools import HttpRequestParser
from httptools.parser.errors import HttpParserError from httptools.parser.errors import HttpParserError
from multidict import CIMultiDict from multidict import CIMultiDict
from sanic.exceptions import (
InvalidUsage,
PayloadTooLarge,
RequestTimeout,
ServerError,
ServiceUnavailable,
)
from sanic.log import access_logger, logger
from sanic.request import Request
from sanic.response import HTTPResponse
try: try:
import uvloop import uvloop
@ -19,16 +33,6 @@ try:
except ImportError: except ImportError:
pass pass
from sanic.log import logger, access_logger
from sanic.response import HTTPResponse
from sanic.request import Request
from sanic.exceptions import (
RequestTimeout,
PayloadTooLarge,
InvalidUsage,
ServerError,
ServiceUnavailable,
)
current_time = None current_time = None

View File

@ -1,7 +1,7 @@
from mimetypes import guess_type from mimetypes import guess_type
from os import path from os import path
from re import sub from re import sub
from time import strftime, gmtime from time import gmtime, strftime
from urllib.parse import unquote from urllib.parse import unquote
from aiofiles.os import stat from aiofiles.os import stat
@ -13,7 +13,7 @@ from sanic.exceptions import (
InvalidUsage, InvalidUsage,
) )
from sanic.handlers import ContentRangeHandler from sanic.handlers import ContentRangeHandler
from sanic.response import file, file_stream, HTTPResponse from sanic.response import HTTPResponse, file, file_stream
def register( def register(

View File

@ -1,6 +1,7 @@
from json import JSONDecodeError from json import JSONDecodeError
from sanic.log import logger
from sanic.exceptions import MethodNotSupported from sanic.exceptions import MethodNotSupported
from sanic.log import logger
from sanic.response import text from sanic.response import text

View File

@ -1,5 +1,5 @@
from sanic.exceptions import InvalidUsage
from sanic.constants import HTTP_METHODS from sanic.constants import HTTP_METHODS
from sanic.exceptions import InvalidUsage
class HTTPMethodView: class HTTPMethodView:

View File

@ -1,8 +1,9 @@
from httptools import HttpParserUpgrade
from websockets import ConnectionClosed # noqa
from websockets import InvalidHandshake, WebSocketCommonProtocol, handshake
from sanic.exceptions import InvalidUsage from sanic.exceptions import InvalidUsage
from sanic.server import HttpProtocol from sanic.server import HttpProtocol
from httptools import HttpParserUpgrade
from websockets import handshake, WebSocketCommonProtocol, InvalidHandshake
from websockets import ConnectionClosed # noqa
class WebSocketProtocol(HttpProtocol): class WebSocketProtocol(HttpProtocol):

View File

@ -1,10 +1,16 @@
import os
import sys
import signal
import asyncio import asyncio
import logging import logging
import os
import signal
import sys
import traceback import traceback
import gunicorn.workers.base as base
from sanic.server import HttpProtocol, Signal, serve, trigger_events
from sanic.websocket import WebSocketProtocol
try: try:
import ssl import ssl
except ImportError: except ImportError:
@ -16,10 +22,6 @@ try:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
except ImportError: except ImportError:
pass pass
import gunicorn.workers.base as base
from sanic.server import trigger_events, serve, HttpProtocol, Signal
from sanic.websocket import WebSocketProtocol
class GunicornWorker(base.Worker): class GunicornWorker(base.Worker):

View File

@ -2,3 +2,16 @@
# https://github.com/ambv/black#slices # https://github.com/ambv/black#slices
# https://github.com/ambv/black#line-breaks--binary-operators # https://github.com/ambv/black#line-breaks--binary-operators
ignore = E203, W503 ignore = E203, W503
[isort]
atomic=true
default_section = THIRDPARTY
include_trailing_comma = true
known_first_party = sanic
known_third_party = pytest
line_length = 79
lines_after_imports = 2
lines_between_types = 1
multi_line_output = 3
not_skip = __init__.py

View File

@ -25,10 +25,12 @@ commands =
deps = deps =
flake8 flake8
black black
isort
commands = commands =
flake8 sanic flake8 sanic
black --check --verbose sanic black --check --verbose sanic
isort --check-only --recursive sanic
[testenv:check] [testenv:check]
deps = deps =