Skip to content

Commit 35e9c57

Browse files
authored
isort everything except lib (for now) (#952)
* isort the tests folder * Carry over changes from #672 * Disable pre-commit * Revert flake8 config change * isort examples too
1 parent 9344a54 commit 35e9c57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+209
-160
lines changed

.isort.cfg

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# https://github.com/timothycrosley/isort/wiki/isort-Settings
2+
[settings]
3+
default_section = THIRDPARTY
4+
# force_to_top=file1.py,file2.py
5+
# forced_separate = django.contrib,django.utils
6+
include_trailing_comma = true
7+
indent = 4
8+
known_first_party = proxy
9+
# known_future_library = future,pies
10+
# known_standard_library = std,std2
11+
known_testing = pytest,unittest
12+
length_sort = 1
13+
# Should be: 80 - 1
14+
line_length = 79
15+
lines_after_imports = 2
16+
# https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html
17+
# NOTE: Another mode could be "5" for grouping multiple "import from" under
18+
# NOTE: a single instruction.
19+
multi_line_output = 5
20+
no_lines_before = LOCALFOLDER
21+
sections=FUTURE,STDLIB,TESTING,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
22+
# skip=file3.py,file4.py
23+
use_parentheses = true
24+
verbose = true

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
- --py36-plus
99

1010
# - repo: https://github.com/timothycrosley/isort.git
11-
# rev: 5.4.2
11+
# rev: 5.10.0
1212
# hooks:
1313
# - id: isort
1414
# args:

check.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
"""
1111
import sys
1212
import subprocess
13-
1413
from pathlib import Path
14+
1515
from proxy.common.version import __version__ as lib_version
1616

17+
1718
# This script ensures our versions never run out of sync.
1819
#
1920
# 1. TODO: Version is hardcoded in homebrew stable package

examples/https_connect_tunnel.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import time
12-
1312
from typing import Any, Optional
1413

1514
from proxy import Proxy
16-
15+
from proxy.core.base import BaseTcpTunnelHandler
1716
from proxy.http.responses import (
18-
PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT,
19-
PROXY_TUNNEL_UNSUPPORTED_SCHEME,
17+
PROXY_TUNNEL_UNSUPPORTED_SCHEME, PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT,
2018
)
2119

22-
from proxy.core.base import BaseTcpTunnelHandler
23-
2420

2521
class HttpsConnectTunnelHandler(BaseTcpTunnelHandler):
2622
"""A https CONNECT tunnel."""

examples/pubsub_eventing.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import time
12-
import multiprocessing
1312
import logging
13+
import multiprocessing
14+
from typing import Any, Dict, Optional
1415

15-
from typing import Dict, Any, Optional
16-
16+
from proxy.core.event import (
17+
EventQueue, EventManager, EventSubscriber, eventNames,
18+
)
1719
from proxy.common.constants import DEFAULT_LOG_FORMAT
18-
from proxy.core.event import EventManager, EventQueue, EventSubscriber, eventNames
20+
1921

2022
logging.basicConfig(level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)
2123

examples/ssl_echo_client.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from proxy.core.connection import TcpServerConnection
1414
from proxy.common.constants import DEFAULT_BUFFER_SIZE
1515

16+
1617
logger = logging.getLogger(__name__)
1718

1819
if __name__ == '__main__':

examples/ssl_echo_server.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
from typing import Optional
1313

1414
from proxy import Proxy
15+
from proxy.core.base import BaseTcpServerHandler
1516
from proxy.common.utils import wrap_socket
1617
from proxy.core.connection import TcpClientConnection
1718

18-
from proxy.core.base import BaseTcpServerHandler
19-
2019

2120
class EchoSSLServerHandler(BaseTcpServerHandler):
2221
"""Wraps client socket during initialization."""

examples/tcp_echo_client.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from proxy.common.utils import socket_connection
1414
from proxy.common.constants import DEFAULT_BUFFER_SIZE
1515

16+
1617
logger = logging.getLogger(__name__)
1718

1819
if __name__ == '__main__':

examples/web_scraper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import time
1212

1313
from proxy import Proxy
14+
from proxy.common.types import Readables, Writables, SelectableEvents
1415
from proxy.core.acceptor import Work
1516
from proxy.core.connection import TcpClientConnection
16-
from proxy.common.types import Readables, SelectableEvents, Writables
1717

1818

1919
class WebScraper(Work[TcpClientConnection]):

examples/websocket_client.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import time
1212
import logging
1313

14-
from proxy.http.websocket import WebsocketClient, WebsocketFrame, websocketOpcodes
14+
from proxy.http.websocket import (
15+
WebsocketFrame, WebsocketClient, websocketOpcodes,
16+
)
17+
1518

1619
# globals
1720
client: WebsocketClient

tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212

1313
from proxy.common.constants import DEFAULT_LOG_FORMAT
1414

15+
1516
logging.basicConfig(level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)

tests/common/test_flags.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import unittest
11+
from typing import Dict, List
1212

13+
import unittest
1314
from unittest import mock
14-
from typing import List, Dict
1515

16+
from proxy.plugin import CacheResponsesPlugin, FilterByUpstreamHostPlugin
1617
from proxy.http.proxy import HttpProxyPlugin
17-
from proxy.plugin import CacheResponsesPlugin
18-
from proxy.plugin import FilterByUpstreamHostPlugin
19-
from proxy.common.utils import bytes_
2018
from proxy.common.flag import FlagParser
19+
from proxy.common.utils import bytes_
2120
from proxy.common.version import __version__
2221
from proxy.common.constants import PLUGIN_HTTP_PROXY, PY2_DEPRECATION_MESSAGE
2322

tests/common/test_pki.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
"""
1111
import os
1212
import tempfile
13-
import unittest
1413
import subprocess
15-
from unittest import mock
1614
from typing import Tuple
1715

16+
import unittest
17+
from unittest import mock
18+
1819
from proxy.common import pki
1920

2021

tests/common/test_utils.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import socket
12+
1213
import unittest
1314
from unittest import mock
1415

15-
from proxy.common.constants import DEFAULT_IPV6_HOSTNAME, DEFAULT_IPV4_HOSTNAME, DEFAULT_PORT, DEFAULT_TIMEOUT
16-
from proxy.common.constants import DEFAULT_HTTP_PORT
17-
from proxy.common.utils import new_socket_connection, socket_connection
16+
from proxy.common.utils import socket_connection, new_socket_connection
17+
from proxy.common.constants import (
18+
DEFAULT_PORT, DEFAULT_TIMEOUT, DEFAULT_HTTP_PORT, DEFAULT_IPV4_HOSTNAME,
19+
DEFAULT_IPV6_HOSTNAME,
20+
)
1821

1922

2023
class TestSocketConnectionUtils(unittest.TestCase):

tests/core/test_acceptor.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import unittest
1211
import socket
1312
import selectors
1413
import multiprocessing
14+
15+
import unittest
1516
from unittest import mock
1617

17-
from proxy.core.acceptor import Acceptor
1818
from proxy.common.flag import FlagParser
19+
from proxy.core.acceptor import Acceptor
1920

2021

2122
class TestAcceptor(unittest.TestCase):

tests/core/test_acceptor_pool.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import unittest
12-
1312
from unittest import mock
1413

1514
from proxy.common.flag import FlagParser

tests/core/test_conn_pool.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import pytest
12-
import unittest
1311
import selectors
1412

13+
import pytest
14+
import unittest
1515
from unittest import mock
16+
1617
from pytest_mock import MockerFixture
1718

1819
from proxy.core.connection import UpstreamConnectionPool

tests/core/test_connection.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import unittest
12-
import socket
1311
import ssl
12+
import socket
13+
from typing import Union, Optional
14+
15+
import unittest
1416
from unittest import mock
15-
from typing import Optional, Union
1617

17-
from proxy.core.connection import tcpConnectionTypes, TcpConnectionUninitializedException
18-
from proxy.core.connection import TcpServerConnection, TcpConnection, TcpClientConnection
19-
from proxy.common.constants import DEFAULT_IPV6_HOSTNAME, DEFAULT_PORT, DEFAULT_IPV4_HOSTNAME
18+
from proxy.core.connection import (
19+
TcpConnection, TcpClientConnection, TcpServerConnection,
20+
TcpConnectionUninitializedException, tcpConnectionTypes,
21+
)
22+
from proxy.common.constants import (
23+
DEFAULT_PORT, DEFAULT_IPV4_HOSTNAME, DEFAULT_IPV6_HOSTNAME,
24+
)
2025

2126

2227
class TestTcpConnection(unittest.TestCase):

tests/core/test_event_dispatcher.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import os
12-
import threading
13-
import unittest
1412
import queue
13+
import threading
1514
import multiprocessing
16-
1715
from multiprocessing import connection
1816

17+
import unittest
1918
from unittest import mock
2019

21-
from proxy.core.event import EventDispatcher, EventQueue, eventNames
20+
from proxy.core.event import EventQueue, EventDispatcher, eventNames
2221

2322

2423
class TestEventDispatcher(unittest.TestCase):

tests/core/test_event_manager.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import unittest
12-
1312
from unittest import mock
1413

1514
from proxy.core.event import EventManager

tests/core/test_event_queue.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import multiprocessing
1211
import os
1312
import threading
14-
import unittest
13+
import multiprocessing
1514

15+
import unittest
1616
from unittest import mock
1717

1818
from proxy.core.event import EventQueue, eventNames

tests/core/test_event_subscriber.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
import os
1212
import queue
1313
import threading
14-
import unittest
1514
import multiprocessing
16-
from typing import Dict, Any
15+
from typing import Any, Dict
1716

17+
import unittest
1818
from unittest import mock
1919

20-
from proxy.core.event import EventQueue, EventDispatcher, EventSubscriber, eventNames
20+
from proxy.core.event import (
21+
EventQueue, EventDispatcher, EventSubscriber, eventNames,
22+
)
23+
2124

2225
PUBLISHER_ID = threading.get_ident()
2326

tests/core/test_listener.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
import os
1212
import socket
1313
import tempfile
14-
import unittest
15-
16-
from unittest import mock
1714

1815
import pytest
16+
import unittest
17+
from unittest import mock
1918

19+
from proxy.common.flag import FlagParser
2020
from proxy.core.acceptor import Listener
2121
from proxy.common.constants import IS_WINDOWS
22-
from proxy.common.flag import FlagParser
2322

2423

2524
class TestListener(unittest.TestCase):

tests/http/exceptions/test_http_proxy_auth_failed.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import pytest
1211
import selectors
1312

13+
import pytest
14+
1415
from pytest_mock import MockerFixture
1516

16-
from proxy.common.flag import FlagParser
1717
from proxy.http import HttpProtocolHandler, httpHeaders
18+
from proxy.common.flag import FlagParser
19+
from proxy.common.utils import build_http_request
1820
from proxy.http.responses import PROXY_AUTH_FAILED_RESPONSE_PKT
1921
from proxy.core.connection import TcpClientConnection
20-
from proxy.common.utils import build_http_request
21-
2222
from ...test_assertions import Assertions
2323

2424

tests/http/exceptions/test_http_request_rejected.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
from proxy.http import httpStatusCodes
1414
from proxy.http.parser import HttpParser, httpParserTypes
15+
from proxy.common.utils import build_http_response
1516
from proxy.http.exception import HttpRequestRejected
1617
from proxy.common.constants import CRLF
17-
from proxy.common.utils import build_http_response
1818

1919

2020
class TestHttpRequestRejected(unittest.TestCase):

tests/http/test_chunk_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"""
1111
import unittest
1212

13-
from proxy.http.parser import chunkParserStates, ChunkParser
13+
from proxy.http.parser import ChunkParser, chunkParserStates
1414

1515

1616
class TestChunkParser(unittest.TestCase):

0 commit comments

Comments
 (0)