Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extend-exclude =
# IMPORTANT: avoid using ignore option, always use extend-ignore instead
# Completely and unconditionally ignore the following errors:
extend-ignore =
I # flake8-isort is drunk + we have isort integrated into pre-commit
B009 # FIXME: `getattr()` called with a constant arg
C812 # FIXME: missing trailing comma
C819 # FIXME: inline trailing comma
Expand Down
25 changes: 25 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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
line_length = 127
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 = 9
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhinavsingh this one corresponds best to the style you already use in the repo but I usually prefer 5: https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. We can use 5 which is reasonable limit.

I am unsure what will be the implications. I guess need to split multiple grouped imports or may be longer import lines? Irrespective, happy to get this in. Let's keep it consistent with aio-libs which is already accepted widely in the developer community :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a limit, it's a style (or "mode") of formatting, follow the lint and you'll see. aiohttp actually uses 3 for some reason but I didn't set that up and try not to change the formatting settings in that project.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"isort your imports, so you don't have to."

I see what you mean now. It's part of a fixture config :).

Happy to see this integration, indeed following a standard is the way to go, I was sorting them based upon a random in-my-brain-only logic 🗡️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, also one of the most common import orders is to have stdlib at the top, followed by third-party imports and finally project-local. But with isort you can define extra sections if some things have additional semantical meaning within the project or explicitly declare that some things belong to certain sections.

no_lines_before = LOCALFOLDER
sections=FUTURE,STDLIB,TESTING,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
# skip=file3.py,file4.py
use_parentheses = true
verbose = true
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ repos:
args:
- --py36-plus

# - repo: https://github.com/timothycrosley/isort.git
# rev: 5.4.2
# hooks:
# - id: isort
# args:
# - --honor-noqa
- repo: https://github.com/timothycrosley/isort.git
rev: 5.10.0
hooks:
- id: isort
args:
- --honor-noqa

- repo: https://github.com/Lucas-C/pre-commit-hooks.git
rev: v1.1.7
Expand Down
5 changes: 3 additions & 2 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import sys
import subprocess

import sys
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
3 changes: 1 addition & 2 deletions examples/https_connect_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
:license: BSD, see LICENSE for more details.
"""
import time

from typing import Any, Optional

from proxy import Proxy
from proxy.common.utils import build_http_response
from proxy.core.base import BaseTcpTunnelHandler
from proxy.http import httpStatusCodes
from proxy.http.parser import httpParserStates
from proxy.core.base import BaseTcpTunnelHandler


class HttpsConnectTunnelHandler(BaseTcpTunnelHandler):
Expand Down
8 changes: 4 additions & 4 deletions examples/pubsub_eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import time
import multiprocessing
import logging

from typing import Dict, Any, Optional
import multiprocessing
import time
from typing import Any, Dict, Optional

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)

logger = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion examples/ssl_echo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"""
import logging

from proxy.core.connection import TcpServerConnection
from proxy.common.constants import DEFAULT_BUFFER_SIZE
from proxy.core.connection import TcpServerConnection


logger = logging.getLogger(__name__)

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 @@ -13,9 +13,8 @@

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

from proxy.core.base import BaseTcpServerHandler
from proxy.core.connection import TcpClientConnection


class EchoSSLServerHandler(BaseTcpServerHandler):
Expand Down
3 changes: 2 additions & 1 deletion examples/tcp_echo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"""
import logging

from proxy.common.utils import socket_connection
from proxy.common.constants import DEFAULT_BUFFER_SIZE
from proxy.common.utils import socket_connection


logger = logging.getLogger(__name__)

Expand Down
5 changes: 2 additions & 3 deletions examples/web_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import time
import socket

import time
from typing import Dict

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


class WebScraper(Work):
Expand Down
3 changes: 2 additions & 1 deletion examples/websocket_client.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 time
import logging
import time

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


# globals
client: WebsocketClient
last_dispatch_time: float
Expand Down
3 changes: 2 additions & 1 deletion proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
Submodules
Subpackages
"""
from .proxy import entry_point, main, Proxy
from .proxy import Proxy, entry_point, main
from .testing import TestCase


__all__ = [
# PyPi package entry_point. See
# https://github.com/abhinavsingh/proxy.py#from-command-line-when-installed-using-pip
Expand Down
1 change: 1 addition & 0 deletions proxy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"""
from .proxy import entry_point


if __name__ == '__main__':
entry_point()
1 change: 1 addition & 0 deletions proxy/common/_scm_version.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
# autogenerated on build and absent on mypy checks time
from typing import Tuple, Union


version: str
version_tuple: Tuple[Union[int, str], ...]
4 changes: 3 additions & 1 deletion proxy/common/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
"""
from typing import Tuple, Union


try:
# pylint: disable=unused-import
from ._scm_version import version as __version__, version_tuple as _ver_tup # noqa: WPS433, WPS436
from ._scm_version import version as __version__ # noqa: WPS433, WPS436
from ._scm_version import version_tuple as _ver_tup
except ImportError:
from pkg_resources import get_distribution as _get_dist # noqa: WPS433
__version__ = _get_dist('proxy.py').version # noqa: WPS440
Expand Down
9 changes: 4 additions & 5 deletions proxy/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import ipaddress
import os
import sys
import time
import secrets
import pathlib
import secrets
import sys
import sysconfig
import ipaddress

import time
from typing import Any, List

from ._compat import IS_WINDOWS # noqa: WPS436
Expand Down
26 changes: 12 additions & 14 deletions proxy/common/flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,28 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
import os
import sys
import base64
import socket
import argparse
import ipaddress
import base64
import collections
import ipaddress
import multiprocessing

from typing import Optional, List, Any, cast
import os
import socket
import sys
from typing import Any, List, Optional, cast

from ._compat import IS_WINDOWS # noqa: WPS436
from .constants import COMMA, DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_DISABLE_HEADERS
from .constants import DEFAULT_MIN_COMPRESSION_LIMIT, DEFAULT_NUM_ACCEPTORS, DEFAULT_NUM_WORKERS, PLUGIN_DASHBOARD
from .constants import PLUGIN_DEVTOOLS_PROTOCOL, PLUGIN_HTTP_PROXY, PLUGIN_INSPECT_TRAFFIC, PLUGIN_PAC_FILE, PLUGIN_PROXY_AUTH
from .constants import PLUGIN_WEB_SERVER, PY2_DEPRECATION_MESSAGE
from .logger import Logger
from .plugins import Plugins
from .types import IpAddress
from .utils import bytes_, is_py2, set_open_file_limit
from .constants import COMMA, DEFAULT_DATA_DIRECTORY_PATH, DEFAULT_NUM_ACCEPTORS, DEFAULT_NUM_WORKERS
from .constants import DEFAULT_DEVTOOLS_WS_PATH, DEFAULT_DISABLE_HEADERS, PY2_DEPRECATION_MESSAGE
from .constants import PLUGIN_DASHBOARD, PLUGIN_DEVTOOLS_PROTOCOL, DEFAULT_MIN_COMPRESSION_LIMIT
from .constants import PLUGIN_HTTP_PROXY, PLUGIN_INSPECT_TRAFFIC, PLUGIN_PAC_FILE
from .constants import PLUGIN_WEB_SERVER, PLUGIN_PROXY_AUTH
from .logger import Logger

from .version import __version__


__homepage__ = 'https://github.com/abhinavsingh/proxy.py'


Expand Down
4 changes: 2 additions & 2 deletions proxy/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
:license: BSD, see LICENSE for more details.
"""
import logging

from typing import Optional, Any
from typing import Any, Optional

from .constants import DEFAULT_LOG_FILE, DEFAULT_LOG_FORMAT, DEFAULT_LOG_LEVEL


SINGLE_CHAR_TO_LEVEL = {
'D': 'DEBUG',
'I': 'INFO',
Expand Down
17 changes: 8 additions & 9 deletions proxy/common/pki.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@

pki
"""
import os
import sys
import uuid
import time
import logging
import tempfile
import argparse
import contextlib
import logging
import os
import subprocess
import sys
import tempfile
import time
import uuid
from typing import Generator, List, Optional, Tuple

from typing import List, Generator, Optional, Tuple

from .utils import bytes_
from .constants import COMMA
from .utils import bytes_
from .version import __version__


Expand Down
12 changes: 6 additions & 6 deletions proxy/common/plugins.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 os
import abc
import logging
import importlib
import inspect
import itertools
import importlib

from typing import Any, List, Dict, Optional, Tuple, Union
import logging
import os
from typing import Any, Dict, List, Optional, Tuple, Union

from .constants import COMMA, DEFAULT_ABC_PLUGINS, DOT
from .utils import bytes_, text_
from .constants import DOT, DEFAULT_ABC_PLUGINS, COMMA


logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions proxy/common/types.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 queue
import ipaddress
import queue
import sys
from typing import TYPE_CHECKING, Any, Dict, List, Union

from typing import TYPE_CHECKING, Dict, Any, List, Union

# NOTE: Using try/except causes linting problems which is why it's necessary
# NOTE: to use this mypy/pylint idiom for py36-py38 compatibility
Expand Down
16 changes: 8 additions & 8 deletions proxy/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
Websocket
WebSocket
"""
import sys
import ssl
import socket
import logging
import contextlib
import functools
import ipaddress
import contextlib

import logging
import socket
import ssl
import sys
from types import TracebackType
from typing import Optional, Dict, Any, List, Tuple, Type, Callable
from typing import Any, Callable, Dict, List, Optional, Tuple, Type

from ._compat import IS_WINDOWS # noqa: WPS436
from .constants import HTTP_1_1, COLON, WHITESPACE, CRLF, DEFAULT_TIMEOUT, DEFAULT_THREADLESS
from .constants import COLON, CRLF, DEFAULT_THREADLESS, DEFAULT_TIMEOUT, HTTP_1_1, WHITESPACE


if not IS_WINDOWS:
import resource
Expand Down
2 changes: 1 addition & 1 deletion proxy/common/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
from ._version import __version__, VERSION # noqa: WPS436
from ._version import VERSION, __version__ # noqa: WPS436


__all__ = '__version__', 'VERSION'
Loading