From 3b9d7c7acd7af955b4e1855effac85aec44ca81f Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 10 Dec 2019 17:07:21 -0800 Subject: [PATCH] Apply PR feedback --- .circleci/config.yml | 20 +++++++++++++------- libp2p/network/connection/raw_connection.py | 5 +++-- libp2p/tools/factories.py | 10 +++------- libp2p/transport/tcp/tcp.py | 6 ++++-- setup.py | 3 ++- tests_interop/conftest.py | 5 +++-- tox.ini | 3 +-- 7 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c3094b9..fa7691e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,24 +48,30 @@ jobs: - image: circleci/python:3.6 environment: TOXENV: lint - py36-test: + py36-core: <<: *common docker: - image: circleci/python:3.6 environment: - TOXENV: py36-test - py37-test: + TOXENV: py36-core + py37-core: <<: *common docker: - image: circleci/python:3.7 environment: - TOXENV: py37-test - + TOXENV: py37-core + pypy3-core: + <<: *common + docker: + - image: pypy + environment: + TOXENV: pypy3-core workflows: version: 2 test: jobs: - docs - lint - - py36-test - - py37-test + - py36-core + - py37-core + - pypy3-core diff --git a/libp2p/network/connection/raw_connection.py b/libp2p/network/connection/raw_connection.py index 55b47ef..4f01b12 100644 --- a/libp2p/network/connection/raw_connection.py +++ b/libp2p/network/connection/raw_connection.py @@ -53,5 +53,6 @@ class RawConnection(IRawConnection): async def close(self) -> None: self.writer.close() - if sys.version_info[0:2] > (3, 6): - await self.writer.wait_closed() + if sys.version_info < (3, 7): + return + await self.writer.wait_closed() diff --git a/libp2p/tools/factories.py b/libp2p/tools/factories.py index 5e22313..5c9c310 100644 --- a/libp2p/tools/factories.py +++ b/libp2p/tools/factories.py @@ -1,6 +1,8 @@ import asyncio from typing import Any, AsyncIterator, Dict, Tuple, cast +# NOTE: import ``asynccontextmanager`` from ``contextlib`` when support for python 3.6 is dropped. +from async_generator import asynccontextmanager import factory from libp2p import generate_new_rsa_identity, generate_peer_id_from @@ -32,12 +34,6 @@ from .constants import ( ) from .utils import connect, connect_swarm -try: - from contextlib import asynccontextmanager -except ImportError: - # NOTE: mypy complains about a duplicate import without the following ``# type: ignore`` - from async_generator import asynccontextmanager # type: ignore - def initialize_peerstore_with_our_keypair(self_id: ID, key_pair: KeyPair) -> PeerStore: peer_store = PeerStore() @@ -177,7 +173,7 @@ async def host_pair_factory(is_secure: bool) -> Tuple[BasicHost, BasicHost]: return hosts[0], hosts[1] -@asynccontextmanager +@asynccontextmanager # type: ignore async def pair_of_connected_hosts( is_secure: bool = True ) -> AsyncIterator[Tuple[BasicHost, BasicHost]]: diff --git a/libp2p/transport/tcp/tcp.py b/libp2p/transport/tcp/tcp.py index c27de0e..f5c2aa4 100644 --- a/libp2p/transport/tcp/tcp.py +++ b/libp2p/transport/tcp/tcp.py @@ -54,9 +54,11 @@ class TCPListener(IListener): if self.server is None: return self.server.close() - if sys.version_info[0:2] > (3, 6): - await self.server.wait_closed() + server = self.server self.server = None + if sys.version_info < (3, 7): + return + await server.wait_closed() class TCP(ITransport): diff --git a/setup.py b/setup.py index 35b17bf..56a6bf2 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ install_requires = [ "coincurve>=10.0.0,<11.0.0", "pynacl==1.3.0", "dataclasses>=0.7, <1;python_version<'3.7'", - "async_generator==1.10;python_version<'3.7'", + "async_generator==1.10", ] @@ -96,6 +96,7 @@ setup( "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", ], platforms=["unix", "linux", "osx"], diff --git a/tests_interop/conftest.py b/tests_interop/conftest.py index 3fcc74f..08df614 100644 --- a/tests_interop/conftest.py +++ b/tests_interop/conftest.py @@ -151,8 +151,9 @@ class DaemonStream(ReadWriteCloser): async def close(self) -> None: self.writer.close() - if sys.version_info[0:2] > (3, 6): - await self.writer.wait_closed() + if sys.version_info < (3, 7): + return + await self.writer.wait_closed() async def read(self, n: int = -1) -> bytes: return await self.reader.read(n) diff --git a/tox.ini b/tox.ini index a482e70..21f4643 100644 --- a/tox.ini +++ b/tox.ini @@ -3,8 +3,7 @@ # TODO: consider pypy3 support [tox] envlist = - py36-test - py37-test + py{36,37}-test py37-interop lint docs