Skip to content

Commit e142db7

Browse files
committed
Enable isort in the pre-commit tool settings
1 parent 2b3f0cb commit e142db7

File tree

131 files changed

+479
-505
lines changed

Some content is hidden

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

131 files changed

+479
-505
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 = 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

check.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import sys
1211
import subprocess
13-
12+
import sys
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
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
1615
from proxy.common.utils import build_http_response
16+
from proxy.core.base import BaseTcpTunnelHandler
1717
from proxy.http import httpStatusCodes
1818
from proxy.http.parser import httpParserStates
19-
from proxy.core.base import BaseTcpTunnelHandler
2019

2120

2221
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, Optional
12+
import multiprocessing
13+
import time
14+
from typing import Any, Dict, Optional
1615

1716
from proxy.common.constants import DEFAULT_LOG_FORMAT
1817
from proxy.core.event import EventManager, EventQueue, EventSubscriber, eventNames
1918

19+
2020
logging.basicConfig(level=logging.DEBUG, format=DEFAULT_LOG_FORMAT)
2121

2222
logger = logging.getLogger(__name__)

examples/ssl_echo_client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"""
1111
import logging
1212

13-
from proxy.core.connection import TcpServerConnection
1413
from proxy.common.constants import DEFAULT_BUFFER_SIZE
14+
from proxy.core.connection import TcpServerConnection
15+
1516

1617
logger = logging.getLogger(__name__)
1718

examples/ssl_echo_server.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313

1414
from proxy import Proxy
1515
from proxy.common.utils import wrap_socket
16-
from proxy.core.connection import TcpClientConnection
17-
1816
from proxy.core.base import BaseTcpServerHandler
17+
from proxy.core.connection import TcpClientConnection
1918

2019

2120
class EchoSSLServerHandler(BaseTcpServerHandler):

examples/tcp_echo_client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
"""
1111
import logging
1212

13-
from proxy.common.utils import socket_connection
1413
from proxy.common.constants import DEFAULT_BUFFER_SIZE
14+
from proxy.common.utils import socket_connection
15+
1516

1617
logger = logging.getLogger(__name__)
1718

examples/web_scraper.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import time
1211
import socket
13-
12+
import time
1413
from typing import Dict
1514

1615
from proxy import Proxy
17-
from proxy.core.acceptor import Work
1816
from proxy.common.types import Readables, Writables
17+
from proxy.core.acceptor import Work
1918

2019

2120
class WebScraper(Work):

examples/websocket_client.py

+2-1
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 time
1211
import logging
12+
import time
1313

1414
from proxy.http.websocket import WebsocketClient, WebsocketFrame, websocketOpcodes
1515

16+
1617
# globals
1718
client: WebsocketClient
1819
last_dispatch_time: float

proxy/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
Submodules
1515
Subpackages
1616
"""
17-
from .proxy import entry_point, main, Proxy
17+
from .proxy import Proxy, entry_point, main
1818
from .testing import TestCase
1919

20+
2021
__all__ = [
2122
# PyPi package entry_point. See
2223
# 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/_scm_version.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
# autogenerated on build and absent on mypy checks time
33
from typing import Tuple, Union
44

5+
56
version: str
67
version_tuple: Tuple[Union[int, str], ...]

proxy/common/_version.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"""
1313
from typing import Tuple, Union
1414

15+
1516
try:
1617
# pylint: disable=unused-import
17-
from ._scm_version import version as __version__, version_tuple as _ver_tup # noqa: WPS433, WPS436
18+
from ._scm_version import version as __version__ # noqa: WPS433, WPS436
19+
from ._scm_version import version_tuple as _ver_tup
1820
except ImportError:
1921
from pkg_resources import get_distribution as _get_dist # noqa: WPS433
2022
__version__ = _get_dist('proxy.py').version # noqa: WPS440

proxy/common/constants.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
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 sys
13-
import time
14-
import secrets
1513
import pathlib
14+
import secrets
15+
import sys
1616
import sysconfig
17-
import ipaddress
18-
17+
import time
1918
from typing import Any, List
2019

2120
from ._compat import IS_WINDOWS # noqa: WPS436

proxy/common/flag.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,28 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
import os
12-
import sys
13-
import base64
14-
import socket
1511
import argparse
16-
import ipaddress
12+
import base64
1713
import collections
14+
import ipaddress
1815
import multiprocessing
19-
20-
from typing import Optional, List, Any, cast
16+
import os
17+
import socket
18+
import sys
19+
from typing import Any, List, Optional, cast
2120

2221
from ._compat import IS_WINDOWS # noqa: WPS436
22+
from .constants import COMMA, DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_DISABLE_HEADERS
23+
from .constants import DEFAULT_MIN_COMPRESSION_LIMIT, DEFAULT_NUM_ACCEPTORS, DEFAULT_NUM_WORKERS, PLUGIN_DASHBOARD
24+
from .constants import PLUGIN_DEVTOOLS_PROTOCOL, PLUGIN_HTTP_PROXY, PLUGIN_INSPECT_TRAFFIC, PLUGIN_PAC_FILE, PLUGIN_PROXY_AUTH
25+
from .constants import PLUGIN_WEB_SERVER, PY2_DEPRECATION_MESSAGE
26+
from .logger import Logger
2327
from .plugins import Plugins
2428
from .types import IpAddress
2529
from .utils import bytes_, is_py2, set_open_file_limit
26-
from .constants import COMMA, DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_NUM_ACCEPTORS, DEFAULT_NUM_WORKERS
27-
from .constants import DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_DISABLE_HEADERS, PY2_DEPRECATION_MESSAGE
28-
from .constants import PLUGIN_DASHBOARD, PLUGIN_DEVTOOLS_PROTOCOL, DEFAULT_MIN_COMPRESSION_LIMIT
29-
from .constants import PLUGIN_HTTP_PROXY, PLUGIN_INSPECT_TRAFFIC, PLUGIN_PAC_FILE
30-
from .constants import PLUGIN_WEB_SERVER, PLUGIN_PROXY_AUTH
31-
from .logger import Logger
32-
3330
from .version import __version__
3431

32+
3533
__homepage__ = 'https://github.com/abhinavsingh/proxy.py'
3634

3735

proxy/common/logger.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111
import logging
12-
13-
from typing import Optional, Any
12+
from typing import Any, Optional
1413

1514
from .constants import DEFAULT_LOG_FILE, DEFAULT_LOG_FORMAT, DEFAULT_LOG_LEVEL
1615

16+
1717
SINGLE_CHAR_TO_LEVEL = {
1818
'D': 'DEBUG',
1919
'I': 'INFO',

proxy/common/pki.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@
1212
1313
pki
1414
"""
15-
import os
16-
import sys
17-
import uuid
18-
import time
19-
import logging
20-
import tempfile
2115
import argparse
2216
import contextlib
17+
import logging
18+
import os
2319
import subprocess
20+
import sys
21+
import tempfile
22+
import time
23+
import uuid
24+
from typing import Generator, List, Optional, Tuple
2425

25-
from typing import List, Generator, Optional, Tuple
26-
27-
from .utils import bytes_
2826
from .constants import COMMA
27+
from .utils import bytes_
2928
from .version import __version__
3029

3130

proxy/common/plugins.py

+6-6
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 os
1211
import abc
13-
import logging
12+
import importlib
1413
import inspect
1514
import itertools
16-
import importlib
17-
18-
from typing import Any, List, Dict, Optional, Tuple, Union
15+
import logging
16+
import os
17+
from typing import Any, Dict, List, Optional, Tuple, Union
1918

19+
from .constants import COMMA, DEFAULT_ABC_PLUGINS, DOT
2020
from .utils import bytes_, text_
21-
from .constants import DOT, DEFAULT_ABC_PLUGINS, COMMA
21+
2222

2323
logger = logging.getLogger(__name__)
2424

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
Websocket
1616
WebSocket
1717
"""
18-
import sys
19-
import ssl
20-
import socket
21-
import logging
18+
import contextlib
2219
import functools
2320
import ipaddress
24-
import contextlib
25-
21+
import logging
22+
import socket
23+
import ssl
24+
import sys
2625
from types import TracebackType
27-
from typing import Optional, Dict, Any, List, Tuple, Type, Callable
26+
from typing import Any, Callable, Dict, List, Optional, Tuple, Type
2827

2928
from ._compat import IS_WINDOWS # noqa: WPS436
30-
from .constants import HTTP_1_1, COLON, WHITESPACE, CRLF, DEFAULT_TIMEOUT, DEFAULT_THREADLESS
29+
from .constants import COLON, CRLF, DEFAULT_THREADLESS, DEFAULT_TIMEOUT, HTTP_1_1, WHITESPACE
30+
3131

3232
if not IS_WINDOWS:
3333
import resource

proxy/common/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:copyright: (c) 2013-present by Abhinav Singh and contributors.
99
:license: BSD, see LICENSE for more details.
1010
"""
11-
from ._version import __version__, VERSION # noqa: WPS436
11+
from ._version import VERSION, __version__ # noqa: WPS436
1212

1313

1414
__all__ = '__version__', 'VERSION'

0 commit comments

Comments
 (0)