Skip to content

Commit

Permalink
isort everything except lib (for now) (#952)
Browse files Browse the repository at this point in the history
* isort the tests folder

* Carry over changes from #672

* Disable pre-commit

* Revert flake8 config change

* isort examples too
  • Loading branch information
abhinavsingh authored Jan 10, 2022
1 parent 9344a54 commit 35e9c57
Show file tree
Hide file tree
Showing 44 changed files with 209 additions and 160 deletions.
24 changes: 24 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# https://github.com/timothycrosley/isort/wiki/isort-Settings
[settings]
default_section = THIRDPARTY
# force_to_top=file1.py,file2.py
# forced_separate = django.contrib,django.utils
include_trailing_comma = true
indent = 4
known_first_party = proxy
# known_future_library = future,pies
# known_standard_library = std,std2
known_testing = pytest,unittest
length_sort = 1
# Should be: 80 - 1
line_length = 79
lines_after_imports = 2
# https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html
# NOTE: Another mode could be "5" for grouping multiple "import from" under
# NOTE: a single instruction.
multi_line_output = 5
no_lines_before = LOCALFOLDER
sections=FUTURE,STDLIB,TESTING,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
# skip=file3.py,file4.py
use_parentheses = true
verbose = true
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- --py36-plus

# - repo: https://github.com/timothycrosley/isort.git
# rev: 5.4.2
# rev: 5.10.0
# hooks:
# - id: isort
# args:
Expand Down
3 changes: 2 additions & 1 deletion check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"""
import sys
import subprocess

from pathlib import Path

from proxy.common.version import __version__ as lib_version


# This script ensures our versions never run out of sync.
#
# 1. TODO: Version is hardcoded in homebrew stable package
Expand Down
8 changes: 2 additions & 6 deletions examples/https_connect_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
:license: BSD, see LICENSE for more details.
"""
import time

from typing import Any, Optional

from proxy import Proxy

from proxy.core.base import BaseTcpTunnelHandler
from proxy.http.responses import (
PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT,
PROXY_TUNNEL_UNSUPPORTED_SCHEME,
PROXY_TUNNEL_UNSUPPORTED_SCHEME, PROXY_TUNNEL_ESTABLISHED_RESPONSE_PKT,
)

from proxy.core.base import BaseTcpTunnelHandler


class HttpsConnectTunnelHandler(BaseTcpTunnelHandler):
"""A https CONNECT tunnel."""
Expand Down
10 changes: 6 additions & 4 deletions examples/pubsub_eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
:license: BSD, see LICENSE for more details.
"""
import time
import multiprocessing
import logging
import multiprocessing
from typing import Any, Dict, Optional

from typing import Dict, Any, Optional

from proxy.core.event import (
EventQueue, EventManager, EventSubscriber, eventNames,
)
from proxy.common.constants import DEFAULT_LOG_FORMAT
from proxy.core.event import EventManager, EventQueue, EventSubscriber, eventNames


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

Expand Down
1 change: 1 addition & 0 deletions examples/ssl_echo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from proxy.core.connection import TcpServerConnection
from proxy.common.constants import DEFAULT_BUFFER_SIZE


logger = logging.getLogger(__name__)

if __name__ == '__main__':
Expand Down
3 changes: 1 addition & 2 deletions examples/ssl_echo_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
from typing import Optional

from proxy import Proxy
from proxy.core.base import BaseTcpServerHandler
from proxy.common.utils import wrap_socket
from proxy.core.connection import TcpClientConnection

from proxy.core.base import BaseTcpServerHandler


class EchoSSLServerHandler(BaseTcpServerHandler):
"""Wraps client socket during initialization."""
Expand Down
1 change: 1 addition & 0 deletions examples/tcp_echo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from proxy.common.utils import socket_connection
from proxy.common.constants import DEFAULT_BUFFER_SIZE


logger = logging.getLogger(__name__)

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion examples/web_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import time

from proxy import Proxy
from proxy.common.types import Readables, Writables, SelectableEvents
from proxy.core.acceptor import Work
from proxy.core.connection import TcpClientConnection
from proxy.common.types import Readables, SelectableEvents, Writables


class WebScraper(Work[TcpClientConnection]):
Expand Down
5 changes: 4 additions & 1 deletion examples/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import time
import logging

from proxy.http.websocket import WebsocketClient, WebsocketFrame, websocketOpcodes
from proxy.http.websocket import (
WebsocketFrame, WebsocketClient, websocketOpcodes,
)


# globals
client: WebsocketClient
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

from proxy.common.constants import DEFAULT_LOG_FORMAT


logging.basicConfig(level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)
9 changes: 4 additions & 5 deletions tests/common/test_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import unittest
from typing import Dict, List

import unittest
from unittest import mock
from typing import List, Dict

from proxy.plugin import CacheResponsesPlugin, FilterByUpstreamHostPlugin
from proxy.http.proxy import HttpProxyPlugin
from proxy.plugin import CacheResponsesPlugin
from proxy.plugin import FilterByUpstreamHostPlugin
from proxy.common.utils import bytes_
from proxy.common.flag import FlagParser
from proxy.common.utils import bytes_
from proxy.common.version import __version__
from proxy.common.constants import PLUGIN_HTTP_PROXY, PY2_DEPRECATION_MESSAGE

Expand Down
5 changes: 3 additions & 2 deletions tests/common/test_pki.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"""
import os
import tempfile
import unittest
import subprocess
from unittest import mock
from typing import Tuple

import unittest
from unittest import mock

from proxy.common import pki


Expand Down
9 changes: 6 additions & 3 deletions tests/common/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
:license: BSD, see LICENSE for more details.
"""
import socket

import unittest
from unittest import mock

from proxy.common.constants import DEFAULT_IPV6_HOSTNAME, DEFAULT_IPV4_HOSTNAME, DEFAULT_PORT, DEFAULT_TIMEOUT
from proxy.common.constants import DEFAULT_HTTP_PORT
from proxy.common.utils import new_socket_connection, socket_connection
from proxy.common.utils import socket_connection, new_socket_connection
from proxy.common.constants import (
DEFAULT_PORT, DEFAULT_TIMEOUT, DEFAULT_HTTP_PORT, DEFAULT_IPV4_HOSTNAME,
DEFAULT_IPV6_HOSTNAME,
)


class TestSocketConnectionUtils(unittest.TestCase):
Expand Down
5 changes: 3 additions & 2 deletions tests/core/test_acceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import unittest
import socket
import selectors
import multiprocessing

import unittest
from unittest import mock

from proxy.core.acceptor import Acceptor
from proxy.common.flag import FlagParser
from proxy.core.acceptor import Acceptor


class TestAcceptor(unittest.TestCase):
Expand Down
1 change: 0 additions & 1 deletion tests/core/test_acceptor_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
:license: BSD, see LICENSE for more details.
"""
import unittest

from unittest import mock

from proxy.common.flag import FlagParser
Expand Down
5 changes: 3 additions & 2 deletions tests/core/test_conn_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import pytest
import unittest
import selectors

import pytest
import unittest
from unittest import mock

from pytest_mock import MockerFixture

from proxy.core.connection import UpstreamConnectionPool
Expand Down
17 changes: 11 additions & 6 deletions tests/core/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import unittest
import socket
import ssl
import socket
from typing import Union, Optional

import unittest
from unittest import mock
from typing import Optional, Union

from proxy.core.connection import tcpConnectionTypes, TcpConnectionUninitializedException
from proxy.core.connection import TcpServerConnection, TcpConnection, TcpClientConnection
from proxy.common.constants import DEFAULT_IPV6_HOSTNAME, DEFAULT_PORT, DEFAULT_IPV4_HOSTNAME
from proxy.core.connection import (
TcpConnection, TcpClientConnection, TcpServerConnection,
TcpConnectionUninitializedException, tcpConnectionTypes,
)
from proxy.common.constants import (
DEFAULT_PORT, DEFAULT_IPV4_HOSTNAME, DEFAULT_IPV6_HOSTNAME,
)


class TestTcpConnection(unittest.TestCase):
Expand Down
7 changes: 3 additions & 4 deletions tests/core/test_event_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
:license: BSD, see LICENSE for more details.
"""
import os
import threading
import unittest
import queue
import threading
import multiprocessing

from multiprocessing import connection

import unittest
from unittest import mock

from proxy.core.event import EventDispatcher, EventQueue, eventNames
from proxy.core.event import EventQueue, EventDispatcher, eventNames


class TestEventDispatcher(unittest.TestCase):
Expand Down
1 change: 0 additions & 1 deletion tests/core/test_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
:license: BSD, see LICENSE for more details.
"""
import unittest

from unittest import mock

from proxy.core.event import EventManager
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_event_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import multiprocessing
import os
import threading
import unittest
import multiprocessing

import unittest
from unittest import mock

from proxy.core.event import EventQueue, eventNames
Expand Down
9 changes: 6 additions & 3 deletions tests/core/test_event_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import os
import queue
import threading
import unittest
import multiprocessing
from typing import Dict, Any
from typing import Any, Dict

import unittest
from unittest import mock

from proxy.core.event import EventQueue, EventDispatcher, EventSubscriber, eventNames
from proxy.core.event import (
EventQueue, EventDispatcher, EventSubscriber, eventNames,
)


PUBLISHER_ID = threading.get_ident()

Expand Down
7 changes: 3 additions & 4 deletions tests/core/test_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
import os
import socket
import tempfile
import unittest

from unittest import mock

import pytest
import unittest
from unittest import mock

from proxy.common.flag import FlagParser
from proxy.core.acceptor import Listener
from proxy.common.constants import IS_WINDOWS
from proxy.common.flag import FlagParser


class TestListener(unittest.TestCase):
Expand Down
8 changes: 4 additions & 4 deletions tests/http/exceptions/test_http_proxy_auth_failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import pytest
import selectors

import pytest

from pytest_mock import MockerFixture

from proxy.common.flag import FlagParser
from proxy.http import HttpProtocolHandler, httpHeaders
from proxy.common.flag import FlagParser
from proxy.common.utils import build_http_request
from proxy.http.responses import PROXY_AUTH_FAILED_RESPONSE_PKT
from proxy.core.connection import TcpClientConnection
from proxy.common.utils import build_http_request

from ...test_assertions import Assertions


Expand Down
2 changes: 1 addition & 1 deletion tests/http/exceptions/test_http_request_rejected.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

from proxy.http import httpStatusCodes
from proxy.http.parser import HttpParser, httpParserTypes
from proxy.common.utils import build_http_response
from proxy.http.exception import HttpRequestRejected
from proxy.common.constants import CRLF
from proxy.common.utils import build_http_response


class TestHttpRequestRejected(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/http/test_chunk_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
import unittest

from proxy.http.parser import chunkParserStates, ChunkParser
from proxy.http.parser import ChunkParser, chunkParserStates


class TestChunkParser(unittest.TestCase):
Expand Down
Loading

0 comments on commit 35e9c57

Please sign in to comment.