Skip to content

Commit aa20e33

Browse files
committed
Enable isort in the pre-commit tool settings
1 parent d3be2a1 commit aa20e33

File tree

112 files changed

+415
-416
lines changed

Some content is hidden

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

112 files changed

+415
-416
lines changed

.flake8

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ extend-exclude =
2828
# IMPORTANT: avoid using ignore option, always use extend-ignore instead
2929
# Completely and unconditionally ignore the following errors:
3030
extend-ignore =
31-
I # flake8-isort is drunk + we have isort integrated into pre-commit
3231
B009 # FIXME: `getattr()` called with a constant arg
3332
C812 # FIXME: missing trailing comma
3433
C819 # FIXME: inline trailing comma

.isort.cfg

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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_party = pytest,unittest
12+
# length_sort = 1
13+
# Should be: 80 - 1
14+
#line_length = 79
15+
line_length = 127
16+
lines_after_imports = 2
17+
# https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html
18+
# NOTE: Another mode could be "5" for grouping multiple "import from" under
19+
# NOTE: a single instruction.
20+
multi_line_output = 9
21+
no_lines_before = LOCALFOLDER
22+
sections=FUTURE,STDLIB,TESTING,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
23+
# skip=file3.py,file4.py
24+
use_parentheses = true
25+
verbose = true

.pre-commit-config.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ repos:
77
args:
88
- --py36-plus
99

10-
# - repo: https://github.com/timothycrosley/isort.git
11-
# rev: 5.4.2
12-
# hooks:
13-
# - id: isort
14-
# args:
15-
# - --honor-noqa
10+
- repo: https://github.com/timothycrosley/isort.git
11+
rev: 5.10.0
12+
hooks:
13+
- id: isort
14+
args:
15+
- --honor-noqa
1616

1717
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
1818
rev: v1.1.7

examples/https_connect_tunnel.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
import time
1212
from typing import Any, Optional
1313

14-
from proxy.proxy import Proxy
1514
from proxy.common.utils import build_http_response
16-
from proxy.http.codes import httpStatusCodes
17-
from proxy.http.parser import httpParserStates
18-
from proxy.http.methods import httpMethods
1915
from proxy.core.acceptor import AcceptorPool
2016
from proxy.core.base import BaseTcpTunnelHandler
17+
from proxy.http.codes import httpStatusCodes
18+
from proxy.http.methods import httpMethods
19+
from proxy.http.parser import httpParserStates
20+
from proxy.proxy import Proxy
2121

2222

2323
class HttpsConnectTunnelHandler(BaseTcpTunnelHandler):

examples/pubsub_eventing.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import time
12-
import multiprocessing
1311
import logging
14-
15-
from typing import Dict, Any
12+
import multiprocessing
13+
import time
14+
from typing import Any, Dict
1615

1716
from proxy.core.event import EventQueue, EventSubscriber, eventNames
1817
from proxy.core.event.manager import EventManager
1918

19+
2020
# Enable debug logging to view core event logs
2121
logging.basicConfig(level=logging.DEBUG)
2222

examples/ssl_echo_client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
from proxy.core.connection import TcpServerConnection
1211
from proxy.common.constants import DEFAULT_BUFFER_SIZE
12+
from proxy.core.connection import TcpServerConnection
13+
1314

1415
if __name__ == '__main__':
1516
client = TcpServerConnection('::', 12345)

examples/ssl_echo_server.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
import time
1212
from typing import Optional
1313

14-
from proxy.proxy import Proxy
1514
from proxy.common.utils import wrap_socket
1615
from proxy.core.acceptor import AcceptorPool
17-
from proxy.core.connection import TcpClientConnection
18-
1916
from proxy.core.base import BaseTcpServerHandler
17+
from proxy.core.connection import TcpClientConnection
18+
from proxy.proxy import Proxy
2019

2120

2221
class EchoSSLServerHandler(BaseTcpServerHandler):

examples/tcp_echo_client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
from proxy.common.utils import socket_connection
1211
from proxy.common.constants import DEFAULT_BUFFER_SIZE
12+
from proxy.common.utils import socket_connection
13+
1314

1415
if __name__ == '__main__':
1516
with socket_connection(('::', 12345)) as client:

examples/tcp_echo_server.py

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

14-
from proxy.proxy import Proxy
1514
from proxy.core.acceptor import AcceptorPool
1615
from proxy.core.base import BaseTcpServerHandler
16+
from proxy.proxy import Proxy
1717

1818

1919
class EchoServerHandler(BaseTcpServerHandler):

examples/websocket_client.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import time
12+
1213
from proxy.http.websocket import WebsocketClient, WebsocketFrame, websocketOpcodes
1314

1415

proxy/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
from .proxy import entry_point, main, Proxy
11+
from .proxy import Proxy, entry_point, main
1212
from .testing.test_case import TestCase
1313

14+
1415
__all__ = [
1516
# PyPi package entry_point. See
1617
# https://github.com/abhinavsingh/proxy.py#from-command-line-when-installed-using-pip

proxy/__main__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"""
1111
from .proxy import entry_point
1212

13+
1314
if __name__ == '__main__':
1415
entry_point()

proxy/common/constants.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11+
import ipaddress
1112
import os
12-
import time
1313
import pathlib
14-
import ipaddress
15-
14+
import time
1615
from typing import List
1716

1817
from .version import __version__
1918

19+
2020
PROXY_PY_START_TIME = time.time()
2121

2222
# /path/to/proxy.py/proxy folder

proxy/common/flag.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import argparse
12-
from typing import Optional, List, Any
12+
from typing import Any, List, Optional
1313

1414
from .version import __version__
1515

16+
1617
__homepage__ = 'https://github.com/abhinavsingh/proxy.py'
1718

1819

proxy/common/pki.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import time
12-
import sys
1311
import argparse
1412
import contextlib
13+
import logging
1514
import os
16-
import uuid
1715
import subprocess
16+
import sys
1817
import tempfile
19-
import logging
20-
from typing import List, Generator, Optional, Tuple
18+
import time
19+
import uuid
20+
from typing import Generator, List, Optional, Tuple
2121

22-
from .utils import bytes_
2322
from .constants import COMMA
23+
from .utils import bytes_
2424
from .version import __version__
2525

2626

proxy/common/types.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 queue
1211
import ipaddress
12+
import queue
1313
import sys
14+
from typing import TYPE_CHECKING, Any, Dict, List, Union
1415

15-
from typing import TYPE_CHECKING, Dict, Any, List, Union
1616

1717
# NOTE: Using try/except causes linting problems which is why it's necessary
1818
# NOTE: to use this mypy/pylint idiom for py36-py38 compatibility

proxy/common/utils.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import ssl
12-
import socket
13-
import logging
11+
import contextlib
1412
import functools
1513
import ipaddress
16-
import contextlib
17-
14+
import logging
15+
import socket
16+
import ssl
1817
from types import TracebackType
19-
from typing import Optional, Dict, Any, List, Tuple, Type, Callable
18+
from typing import Any, Callable, Dict, List, Optional, Tuple, Type
2019

21-
from .constants import HTTP_1_1, COLON, WHITESPACE, CRLF, DEFAULT_TIMEOUT
22-
from .constants import DEFAULT_LOG_FILE, DEFAULT_LOG_FORMAT, DEFAULT_LOG_LEVEL
20+
from .constants import COLON, CRLF, DEFAULT_LOG_FILE, DEFAULT_LOG_FORMAT, DEFAULT_LOG_LEVEL, DEFAULT_TIMEOUT, HTTP_1_1
21+
from .constants import WHITESPACE
2322

2423

2524
def text_(s: Any, encoding: str = 'utf-8', errors: str = 'strict') -> Any:

proxy/core/acceptor/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"""
1111
from .acceptor import Acceptor
1212
from .pool import AcceptorPool
13-
from .work import Work
1413
from .threadless import Threadless
14+
from .work import Work
15+
1516

1617
__all__ = [
1718
'Acceptor',

proxy/core/acceptor/acceptor.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@
1515
import selectors
1616
import socket
1717
import threading
18-
1918
from multiprocessing import connection
20-
from multiprocessing.reduction import send_handle, recv_handle
21-
from typing import Optional, Type, Tuple
22-
23-
from .work import Work
24-
from .threadless import Threadless
19+
from multiprocessing.reduction import recv_handle, send_handle
20+
from typing import Optional, Tuple, Type
2521

26-
from ..connection import TcpClientConnection
27-
from ..event import EventQueue, eventNames
2822
from ...common.constants import DEFAULT_THREADLESS
2923
from ...common.flag import flags
3024
from ...common.utils import setup_logger
25+
from ..connection import TcpClientConnection
26+
from ..event import EventQueue, eventNames
27+
from .threadless import Threadless
28+
from .work import Work
29+
3130

3231
logger = logging.getLogger(__name__)
3332

proxy/core/acceptor/pool.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@
1212
import logging
1313
import multiprocessing
1414
import socket
15-
1615
from multiprocessing import connection
1716
from multiprocessing.reduction import send_handle
1817
from typing import List, Optional, Type
1918

19+
from ...common.constants import DEFAULT_BACKLOG, DEFAULT_IPV6_HOSTNAME, DEFAULT_NUM_WORKERS, DEFAULT_PORT
20+
from ...common.flag import flags
21+
from ..event import EventQueue
2022
from .acceptor import Acceptor
2123
from .work import Work
2224

23-
from ..event import EventQueue
24-
25-
from ...common.flag import flags
26-
from ...common.constants import DEFAULT_BACKLOG, DEFAULT_IPV6_HOSTNAME, DEFAULT_NUM_WORKERS, DEFAULT_PORT
2725

2826
logger = logging.getLogger(__name__)
2927

proxy/core/acceptor/threadless.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,24 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import argparse
12-
import os
13-
import socket
14-
import logging
1512
import asyncio
16-
import selectors
1713
import contextlib
14+
import logging
1815
import multiprocessing
16+
import os
17+
import selectors
18+
import socket
1919
from multiprocessing import connection
2020
from multiprocessing.reduction import recv_handle
21+
from typing import Any, Dict, Generator, List, Optional, Tuple, Type
2122

22-
from typing import Dict, Optional, Tuple, List, Generator, Any, Type
23-
24-
from .work import Work
25-
23+
from ...common.constants import DEFAULT_TIMEOUT
24+
from ...common.types import Readables, Writables
25+
from ...common.utils import setup_logger
2626
from ..connection import TcpClientConnection
2727
from ..event import EventQueue, eventNames
28+
from .work import Work
2829

29-
from ...common.utils import setup_logger
30-
from ...common.types import Readables, Writables
31-
from ...common.constants import DEFAULT_TIMEOUT
3230

3331
logger = logging.getLogger(__name__)
3432

proxy/core/acceptor/work.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
"""
1111
import argparse
1212
import socket
13-
1413
from abc import ABC, abstractmethod
15-
from uuid import uuid4, UUID
16-
from typing import Optional, Dict, Any
14+
from typing import Any, Dict, Optional
15+
from uuid import UUID, uuid4
1716

18-
from ..event import eventNames, EventQueue
19-
from ..connection import TcpClientConnection
2017
from ...common.types import Readables, Writables
18+
from ..connection import TcpClientConnection
19+
from ..event import EventQueue, eventNames
2120

2221

2322
class Work(ABC):

proxy/core/base/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .tcp_server import BaseTcpServerHandler
1212
from .tcp_tunnel import BaseTcpTunnelHandler
1313

14+
1415
__all__ = [
1516
'BaseTcpServerHandler',
1617
'BaseTcpTunnelHandler',

0 commit comments

Comments
 (0)