From f20b78c93f91f938e509417912282b9d442746f9 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Fri, 28 Jun 2019 17:00:28 +0200 Subject: [PATCH 1/5] Replace pylint with flake8 This change removes the use of pylint and implements similar code style checks. This is complementary with black code formatter. --- .flake8 | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..15e152a1 --- /dev/null +++ b/.flake8 @@ -0,0 +1,6 @@ +[flake8] +ignore = E203, E266, E501, W503 +max-line-length = 80 +max-complexity = 18 +select = B,C,E,F,W,T4,B9 + From 727342a767f4b89d322b9a1439e77d872d01839e Mon Sep 17 00:00:00 2001 From: mhchia Date: Sun, 4 Aug 2019 00:11:49 +0800 Subject: [PATCH 2/5] Move flake8 settings to tox.ini And add flake8 in the Makefile. --- .flake8 | 6 ------ Makefile | 1 + tox.ini | 8 +++++--- 3 files changed, 6 insertions(+), 9 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 15e152a1..00000000 --- a/.flake8 +++ /dev/null @@ -1,6 +0,0 @@ -[flake8] -ignore = E203, E266, E501, W503 -max-line-length = 80 -max-complexity = 18 -select = B,C,E,F,W,T4,B9 - diff --git a/Makefile b/Makefile index 0edddd0d..2cc4959f 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ lintroll: # TODO: add flake8 black --check $(FILES_TO_LINT) isort --recursive --check-only $(FILES_TO_LINT) + flake8 $(FILES_TO_LINT) protobufs: cd libp2p/pubsub/pb && protoc --python_out=. rpc.proto diff --git a/tox.ini b/tox.ini index cb55dd56..57edafcd 100644 --- a/tox.ini +++ b/tox.ini @@ -6,9 +6,11 @@ envlist = lint [flake8] -max-line-length= 100 -exclude=*_pb2*.py -ignore= +max-line-length = 100 +exclude = *_pb2*.py +ignore = E203, E266, E501, W503 +max-complexity = 18 +select = B,C,E,F,W,T4,B9 [isort] force_sort_within_sections=True From 0a5b4a88caa046d954b7585361a7a0d5caddd493 Mon Sep 17 00:00:00 2001 From: mhchia Date: Sun, 4 Aug 2019 00:18:30 +0800 Subject: [PATCH 3/5] Fix flake8 for the existing code --- libp2p/security/insecure_security.py | 3 +-- libp2p/security/security_multistream.py | 1 - libp2p/security/typing.py | 2 +- libp2p/transport/tcp/tcp.py | 1 - tests/examples/test_chat.py | 2 -- tests/pubsub/factories.py | 2 -- 6 files changed, 2 insertions(+), 9 deletions(-) diff --git a/libp2p/security/insecure_security.py b/libp2p/security/insecure_security.py index 981869ed..23b5fa67 100644 --- a/libp2p/security/insecure_security.py +++ b/libp2p/security/insecure_security.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Any, Dict, cast +from typing import TYPE_CHECKING, cast from libp2p.security.secure_conn_interface import ISecureConn from libp2p.security.secure_transport_interface import ISecureTransport @@ -6,7 +6,6 @@ from libp2p.security.secure_transport_interface import ISecureTransport if TYPE_CHECKING: from libp2p.network.connection.raw_connection_interface import IRawConnection from libp2p.peer.id import ID - from .secure_conn_interface import ISecureConn from .typing import TSecurityDetails diff --git a/libp2p/security/security_multistream.py b/libp2p/security/security_multistream.py index 3ec8b32a..212d5aa8 100644 --- a/libp2p/security/security_multistream.py +++ b/libp2p/security/security_multistream.py @@ -7,7 +7,6 @@ from libp2p.protocol_muxer.multiselect_client import MultiselectClient if TYPE_CHECKING: from libp2p.network.connection.raw_connection_interface import IRawConnection from libp2p.peer.id import ID - from .typing import TSecurityDetails from .secure_conn_interface import ISecureConn from .secure_transport_interface import ISecureTransport diff --git a/libp2p/security/typing.py b/libp2p/security/typing.py index 66b93168..b34a4da2 100644 --- a/libp2p/security/typing.py +++ b/libp2p/security/typing.py @@ -1,3 +1,3 @@ -from typing import Any, Dict, NewType, TypeVar +from typing import Dict, NewType TSecurityDetails = NewType("TSecurityDetails", Dict[str, str]) diff --git a/libp2p/transport/tcp/tcp.py b/libp2p/transport/tcp/tcp.py index e497c732..b04f488a 100644 --- a/libp2p/transport/tcp/tcp.py +++ b/libp2p/transport/tcp/tcp.py @@ -3,7 +3,6 @@ import asyncio import multiaddr from libp2p.network.connection.raw_connection import RawConnection -from libp2p.peer.id import ID from ..listener_interface import IListener from ..transport_interface import ITransport diff --git a/tests/examples/test_chat.py b/tests/examples/test_chat.py index 1eaec5f1..8a431524 100644 --- a/tests/examples/test_chat.py +++ b/tests/examples/test_chat.py @@ -1,9 +1,7 @@ import asyncio -import multiaddr import pytest -from libp2p import new_node from libp2p.peer.peerinfo import info_from_p2p_addr from libp2p.protocol_muxer.multiselect_client import MultiselectClientError from tests.utils import cleanup, set_up_nodes_by_transport_opt diff --git a/tests/pubsub/factories.py b/tests/pubsub/factories.py index 9bcd4a71..5572ce12 100644 --- a/tests/pubsub/factories.py +++ b/tests/pubsub/factories.py @@ -1,5 +1,3 @@ -import functools - import factory from libp2p import initialize_default_swarm From 1cc7e388469a601f7068fd7c9d239b881a2f465a Mon Sep 17 00:00:00 2001 From: mhchia Date: Sun, 4 Aug 2019 00:27:02 +0800 Subject: [PATCH 4/5] Add flake8 to lint deps --- setup.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a46d8794..eceff428 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,12 @@ extras_require = { "pytest-cov>=2.7.1,<3.0.0", "pytest-asyncio>=0.10.0,<1.0.0", ], - "lint": ["mypy>=0.701,<1.0", "black==19.3b0", "isort==4.3.21"], + "lint": [ + "mypy>=0.701,<1.0", + "black==19.3b0", + "isort==4.3.21", + "flake8>=3.7.7,<4.0.0", + ], "dev": ["tox>=3.13.2,<4.0.0"], } From 0b11e3200056e38ed1b561bfd0d80f428d36b4b7 Mon Sep 17 00:00:00 2001 From: mhchia Date: Sun, 4 Aug 2019 00:32:32 +0800 Subject: [PATCH 5/5] Remove the `TODO` flag for flake8 --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 2cc4959f..3e8feeb3 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,6 @@ format: lintroll: # NOTE: disabling `mypy` until we get typing sorted in this repo # mypy -p libp2p -p examples --config-file {toxinidir}/mypy.ini - # TODO: add flake8 black --check $(FILES_TO_LINT) isort --recursive --check-only $(FILES_TO_LINT) flake8 $(FILES_TO_LINT)