diff --git a/.circleci/config.yml b/.circleci/config.yml index 17720878e2..7b33fdfd83 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -113,24 +113,24 @@ eth2_fixtures: ð2_fixtures - ./eth2-fixtures key: cache-v3-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }}-{{ checksum "./.circleci/get_eth2_fixtures.sh" }}-{{ checksum "./.circleci/build_geth.sh" }} jobs: - py36-lint: + py38-lint: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-lint + TOXENV: py38-lint py37-lint: <<: *common docker: - image: circleci/python:3.7 environment: TOXENV: py37-lint - py36-lint-eth2: + py38-lint-eth2: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-lint-eth2 + TOXENV: py38-lint-eth2 py37-lint-eth2: <<: *common docker: @@ -138,148 +138,148 @@ jobs: environment: TOXENV: py37-lint-eth2 - py36-docs: + py38-docs: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-docs + TOXENV: py38-docs - py36-rpc-state-byzantium: + py38-rpc-state-byzantium: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-rpc-state-byzantium - py36-rpc-state-constantinople: + TOXENV: py38-rpc-state-byzantium + py38-rpc-state-constantinople: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-rpc-state-constantinople - py36-rpc-state-frontier: + TOXENV: py38-rpc-state-constantinople + py38-rpc-state-frontier: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-rpc-state-frontier - py36-rpc-state-homestead: + TOXENV: py38-rpc-state-frontier + py38-rpc-state-homestead: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-rpc-state-homestead - py36-rpc-state-istanbul: + TOXENV: py38-rpc-state-homestead + py38-rpc-state-istanbul: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-rpc-state-istanbul - py36-rpc-state-petersburg: + TOXENV: py38-rpc-state-istanbul + py38-rpc-state-petersburg: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-rpc-state-petersburg + TOXENV: py38-rpc-state-petersburg - py36-rpc-state-tangerine_whistle: + py38-rpc-state-tangerine_whistle: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-rpc-state-tangerine_whistle - py36-rpc-state-spurious_dragon: + TOXENV: py38-rpc-state-tangerine_whistle + py38-rpc-state-spurious_dragon: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-rpc-state-spurious_dragon - py36-rpc-blockchain: + TOXENV: py38-rpc-state-spurious_dragon + py38-rpc-blockchain: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-rpc-blockchain + TOXENV: py38-rpc-blockchain - py36-eth1-core: + py38-eth1-core: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-eth1-core - py36-integration: + TOXENV: py38-eth1-core + py38-integration: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-integration - py36-lightchain_integration: + TOXENV: py38-integration + py38-lightchain_integration: <<: *geth_steps docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-lightchain_integration + TOXENV: py38-lightchain_integration GETH_VERSION: v1.8.22 - py36-long_run_integration: + py38-long_run_integration: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-long_run_integration - py36-p2p: + TOXENV: py38-long_run_integration + py38-p2p: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-p2p - py36-p2p-trio: + TOXENV: py38-p2p + py38-p2p-trio: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-p2p-trio - py36-eth2-core: + TOXENV: py38-p2p-trio + py38-eth2-core: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-eth2-core - py36-eth2-utils: + TOXENV: py38-eth2-core + py38-eth2-utils: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-eth2-utils - py36-eth2-fixtures: + TOXENV: py38-eth2-utils + py38-eth2-fixtures: <<: *eth2_fixtures docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-eth2-fixtures - py36-eth2-integration: + TOXENV: py38-eth2-fixtures + py38-eth2-integration: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-eth2-integration - py36-wheel-cli: + TOXENV: py38-eth2-integration + py38-wheel-cli: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-wheel-cli - py36-eth1-components: + TOXENV: py38-wheel-cli + py38-eth1-components: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-eth1-components - py36-eth2-trio: + TOXENV: py38-eth1-components + py38-eth2-trio: <<: *common docker: - - image: circleci/python:3.6 + - image: circleci/python:3.8 environment: - TOXENV: py36-eth2-trio + TOXENV: py38-eth2-trio py37-rpc-state-quadratic: <<: *common @@ -398,16 +398,16 @@ workflows: test: jobs: # These tests are long, so should be started first to optimize for total suite run time - - py36-integration - - py36-wheel-cli + - py38-integration + - py38-wheel-cli - py37-wheel-cli - - py36-long_run_integration + - py38-long_run_integration - py37-rpc-state-sstore - - py36-eth2-core + - py38-eth2-core - py37-eth2-core - py37-libp2p - - py36-docs + - py38-docs - py37-eth1-core - py37-p2p @@ -422,28 +422,28 @@ workflows: - py37-rpc-state-quadratic - py37-rpc-state-zero_knowledge - - py36-rpc-state-byzantium - - py36-rpc-state-constantinople - - py36-rpc-state-frontier - - py36-rpc-state-homestead - - py36-rpc-state-petersburg - - py36-rpc-state-spurious_dragon - - py36-rpc-state-tangerine_whistle - - py36-rpc-blockchain + - py38-rpc-state-byzantium + - py38-rpc-state-constantinople + - py38-rpc-state-frontier + - py38-rpc-state-homestead + - py38-rpc-state-petersburg + - py38-rpc-state-spurious_dragon + - py38-rpc-state-tangerine_whistle + - py38-rpc-blockchain - - py36-eth1-core - - py36-p2p - - py36-p2p-trio - - py36-eth2-utils - - py36-eth2-fixtures - - py36-eth2-integration - - py36-eth1-components - - py36-eth2-trio + - py38-eth1-core + - py38-p2p + - py38-p2p-trio + - py38-eth2-utils + - py38-eth2-fixtures + - py38-eth2-integration + - py38-eth1-components + - py38-eth2-trio - - py36-lightchain_integration + - py38-lightchain_integration - - py36-lint - - py36-lint-eth2 + - py38-lint + - py38-lint-eth2 - py37-lint - py37-lint-eth2 diff --git a/.readthedocs.yml b/.readthedocs.yml index e050c327aa..dcdde61de8 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -3,7 +3,7 @@ version: 2 build: image: latest python: - version: 3.6 + version: 3.7 install: - method: pip path: . diff --git a/docs/guides/quickstart.rst b/docs/guides/quickstart.rst index 57c5e33f7f..8d68b48f4b 100644 --- a/docs/guides/quickstart.rst +++ b/docs/guides/quickstart.rst @@ -12,8 +12,8 @@ To develop on top of Trinity or to contribute to the project, check out the Installing on Ubuntu -------------------- -Trinity requires Python 3.6 as well as some tools to compile its dependencies. On Ubuntu, the -``python3.6-dev`` package contains everything we need. Run the following command to install it. +Trinity requires Python 3.7 as well as some tools to compile its dependencies. On Ubuntu, the +``python3.7-dev`` package contains everything we need. Run the following command to install it. .. code:: sh diff --git a/newsfragments/1675.removal.rst b/newsfragments/1675.removal.rst new file mode 100644 index 0000000000..6c0eadc894 --- /dev/null +++ b/newsfragments/1675.removal.rst @@ -0,0 +1 @@ +Drop support for Python 3.6 making Python 3.7 the minimal supported Python version. \ No newline at end of file diff --git a/p2p/_utils.py b/p2p/_utils.py index f3b5e44111..385ed8767b 100644 --- a/p2p/_utils.py +++ b/p2p/_utils.py @@ -1,5 +1,5 @@ import collections -from typing import Hashable, Sequence, Tuple, TypeVar +from typing import Hashable, Sequence, Tuple, TypeVar, AsyncGenerator, Any import rlp @@ -71,3 +71,18 @@ def duplicates(elements: Sequence[TValue]) -> Tuple[TValue, ...]: collections.Counter(elements).items() if count > 1 ) + + +TCo = TypeVar('TCo') +TContra = TypeVar('TContra') + + +class aclosing: + def __init__(self, aiter: AsyncGenerator[TCo, TContra]) -> None: + self._aiter = aiter + + async def __aenter__(self) -> AsyncGenerator[TCo, TContra]: + return self._aiter + + async def __aexit__(self, *args: Any) -> None: + await self._aiter.aclose() diff --git a/p2p/behaviors.py b/p2p/behaviors.py index 7a1fd556f7..575feb2114 100644 --- a/p2p/behaviors.py +++ b/p2p/behaviors.py @@ -1,9 +1,8 @@ +import contextlib from typing import ( AsyncIterator, ) -from async_generator import asynccontextmanager - from eth_utils import ValidationError from p2p.abc import ( @@ -36,7 +35,7 @@ def should_apply_to(self, connection: 'ConnectionAPI') -> bool: # mypy bug: https://github.com/python/mypy/issues/708 return self.qualifier(connection, self.logic) # type: ignore - @asynccontextmanager + @contextlib.asynccontextmanager async def apply(self, connection: ConnectionAPI) -> AsyncIterator[None]: if self._applied_to is not None: raise ValidationError( diff --git a/p2p/discovery.py b/p2p/discovery.py index 76dc606c35..a4665a7c6b 100644 --- a/p2p/discovery.py +++ b/p2p/discovery.py @@ -29,8 +29,6 @@ TypeVar, ) -from async_generator import aclosing - import trio import eth_utils.toolz @@ -82,7 +80,7 @@ ) from p2p.kademlia import ( Address, Node, check_relayed_addr, create_stub_enr, sort_by_distance, KademliaRoutingTable) -from p2p._utils import get_logger +from p2p._utils import get_logger, aclosing from p2p import trio_utils # V4 handler are async methods that take a Node, payload and msg_hash as arguments. diff --git a/p2p/discv5/message_dispatcher.py b/p2p/discv5/message_dispatcher.py index 29a1bf6714..cea58292f1 100644 --- a/p2p/discv5/message_dispatcher.py +++ b/p2p/discv5/message_dispatcher.py @@ -1,3 +1,4 @@ +import contextlib import logging import random from types import ( @@ -14,8 +15,6 @@ TypeVar, ) -from async_generator import asynccontextmanager - import trio from trio.abc import ( ReceiveChannel, @@ -289,7 +288,7 @@ async def get_endpoint_from_node_db(self, receiver_node_id: NodeID) -> Endpoint: return Endpoint(ip_address, udp_port) - @asynccontextmanager + @contextlib.asynccontextmanager async def request_response_subscription(self, receiver_node_id: NodeID, message: BaseMessage, diff --git a/p2p/exchange/exchange.py b/p2p/exchange/exchange.py index 1a3663b72d..06b20bdc71 100644 --- a/p2p/exchange/exchange.py +++ b/p2p/exchange/exchange.py @@ -1,11 +1,11 @@ from functools import partial +import contextlib from typing import ( AsyncIterator, Callable, Type, ) -from async_generator import asynccontextmanager from async_service import background_asyncio_service from p2p.abc import ConnectionAPI @@ -25,7 +25,7 @@ class BaseExchange(ExchangeAPI[TRequestCommand, TResponseCommand, TResult]): def __init__(self) -> None: self.tracker = self.tracker_class() - @asynccontextmanager + @contextlib.asynccontextmanager async def run_exchange(self, connection: ConnectionAPI) -> AsyncIterator[None]: protocol = connection.get_protocol_for_command_type(self.get_request_cmd_type()) diff --git a/p2p/exchange/logic.py b/p2p/exchange/logic.py index 3e8bdf29d2..c08c6396d8 100644 --- a/p2p/exchange/logic.py +++ b/p2p/exchange/logic.py @@ -1,7 +1,6 @@ +import contextlib from typing import Any, AsyncIterator -from async_generator import asynccontextmanager - from p2p.abc import ConnectionAPI, LogicAPI from p2p.exceptions import UnknownProtocol from p2p.logic import BaseLogic @@ -29,7 +28,7 @@ def qualifier(self, connection: ConnectionAPI, logic: LogicAPI) -> bool: else: return protocol.supports_command(self.exchange.get_response_cmd_type()) - @asynccontextmanager + @contextlib.asynccontextmanager async def apply(self, connection: ConnectionAPI) -> AsyncIterator[None]: async with self.exchange.run_exchange(connection): yield diff --git a/p2p/logic.py b/p2p/logic.py index 68db8492c8..05f1b26095 100644 --- a/p2p/logic.py +++ b/p2p/logic.py @@ -1,4 +1,5 @@ from abc import abstractmethod +import contextlib from typing import ( cast, AsyncIterator, @@ -7,9 +8,6 @@ Type, ) -from async_generator import asynccontextmanager -from async_exit_stack import AsyncExitStack - from p2p.abc import ( BehaviorAPI, ConnectionAPI, @@ -49,7 +47,7 @@ class CommandHandler(BaseLogic, Generic[TCommand]): def qualifier(self) -> QualifierFn: # type: ignore return HasCommand(self.command_type) - @asynccontextmanager + @contextlib.asynccontextmanager async def apply(self, connection: ConnectionAPI) -> AsyncIterator[None]: self.connection = connection @@ -76,11 +74,11 @@ class Application(BaseLogic): def add_child_behavior(self, behavior: BehaviorAPI) -> None: self._behaviors += (behavior,) - @asynccontextmanager + @contextlib.asynccontextmanager async def apply(self, connection: ConnectionAPI) -> AsyncIterator[None]: self.connection = connection - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: # First apply all the child behaviors for behavior in self._behaviors: if behavior.should_apply_to(connection): diff --git a/p2p/multiplexer.py b/p2p/multiplexer.py index d8e0f545f1..6f75e003cf 100644 --- a/p2p/multiplexer.py +++ b/p2p/multiplexer.py @@ -1,5 +1,6 @@ import asyncio import collections +import contextlib import time from typing import ( Any, @@ -16,8 +17,6 @@ import snappy from cached_property import cached_property -from async_generator import asynccontextmanager - from eth_utils import ValidationError from eth_utils.toolz import cons import rlp @@ -289,7 +288,7 @@ async def _stream_protocol_messages(self, # # Message reading and streaming API # - @asynccontextmanager + @contextlib.asynccontextmanager async def multiplex(self) -> AsyncIterator[None]: """ API for running the background task that feeds individual protocol diff --git a/p2p/p2p_api.py b/p2p/p2p_api.py index 43ed17f69c..ea2e440b4d 100644 --- a/p2p/p2p_api.py +++ b/p2p/p2p_api.py @@ -1,8 +1,7 @@ import asyncio +import contextlib from typing import Any, AsyncIterator, cast -from async_generator import asynccontextmanager - from cached_property import cached_property from async_service import ( @@ -80,7 +79,7 @@ class DisconnectIfIdle(BaseLogic): def __init__(self, idle_timeout: float) -> None: self.idle_timeout = idle_timeout - @asynccontextmanager + @contextlib.asynccontextmanager async def apply(self, connection: ConnectionAPI) -> AsyncIterator[None]: service = PingAndDisconnectIfIdle(connection, self.idle_timeout) async with background_asyncio_service(service): diff --git a/p2p/peer.py b/p2p/peer.py index cb003f6362..e1f5c2be83 100644 --- a/p2p/peer.py +++ b/p2p/peer.py @@ -18,8 +18,6 @@ TYPE_CHECKING, ) -from async_exit_stack import AsyncExitStack - from async_service import Service from lahja import EndpointAPI @@ -261,7 +259,7 @@ async def run(self) -> None: self._start_time = time.monotonic() self.connection.add_command_handler(Disconnect, cast(HandlerFn, self._handle_disconnect)) try: - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: await stack.enter_async_context(P2PAPI().as_behavior().apply(self.connection)) self.p2p_api = self.connection.get_logic('p2p', P2PAPI) diff --git a/p2p/resource_lock.py b/p2p/resource_lock.py index 2a0321e9c2..5d7e9265c5 100644 --- a/p2p/resource_lock.py +++ b/p2p/resource_lock.py @@ -1,10 +1,9 @@ import asyncio from collections import defaultdict from collections.abc import Hashable +import contextlib from typing import AsyncIterator, DefaultDict, Dict, Generic, TypeVar -from async_generator import asynccontextmanager - TResource = TypeVar('TResource', bound=Hashable) @@ -20,7 +19,7 @@ def __init__(self) -> None: self._locks = {} self._reference_counts = defaultdict(int) - @asynccontextmanager + @contextlib.asynccontextmanager async def lock(self, resource: TResource) -> AsyncIterator[None]: if resource not in self._locks: self._locks[resource] = asyncio.Lock() diff --git a/p2p/service.py b/p2p/service.py index 8b2dd24733..851d9d23b7 100644 --- a/p2p/service.py +++ b/p2p/service.py @@ -1,6 +1,7 @@ from abc import abstractmethod import asyncio import concurrent +import contextlib import functools import time from typing import ( @@ -15,7 +16,6 @@ from weakref import WeakSet from async_service import Service, ServiceAPI -from async_generator import asynccontextmanager from cancel_token import CancelToken, OperationCancelled from eth_utils import ( @@ -423,7 +423,7 @@ async def _cleanup(self) -> None: TService = TypeVar('TService', bound=AsyncioServiceAPI) -@asynccontextmanager +@contextlib.asynccontextmanager async def run_service(service: TService) -> AsyncIterator[TService]: task = asyncio.ensure_future(service.run()) await service.events.started.wait() diff --git a/p2p/tools/asyncio_streams.py b/p2p/tools/asyncio_streams.py index dc0c7f4cfb..e339013beb 100644 --- a/p2p/tools/asyncio_streams.py +++ b/p2p/tools/asyncio_streams.py @@ -71,7 +71,11 @@ def abort(self) -> None: def get_directly_connected_streams(alice_extra_info: Dict[str, Any] = None, - bob_extra_info: Dict[str, Any] = None) -> TConnectedStreams: + bob_extra_info: Dict[str, Any] = None, + loop: asyncio.AbstractEventLoop = None) -> TConnectedStreams: + if loop is None: + loop = asyncio.get_event_loop() + alice_reader = asyncio.StreamReader() bob_reader = asyncio.StreamReader() @@ -83,8 +87,8 @@ def get_directly_connected_streams(alice_extra_info: Dict[str, Any] = None, # Link the alice's writer to the bob's reader, and the bob's writer to the # alice's reader. - bob_writer = asyncio.StreamWriter(bob_transport, bob_protocol, alice_reader, loop=None) - alice_writer = asyncio.StreamWriter(alice_transport, alice_protocol, bob_reader, loop=None) + bob_writer = asyncio.StreamWriter(bob_transport, bob_protocol, alice_reader, loop=loop) + alice_writer = asyncio.StreamWriter(alice_transport, alice_protocol, bob_reader, loop=loop) return ( (alice_reader, alice_writer), (bob_reader, bob_writer), diff --git a/p2p/tools/factories/connection.py b/p2p/tools/factories/connection.py index 4610e3ae43..943b5cf2a5 100644 --- a/p2p/tools/factories/connection.py +++ b/p2p/tools/factories/connection.py @@ -1,8 +1,7 @@ import asyncio +import contextlib from typing import AsyncIterator, Tuple -from async_generator import asynccontextmanager - from async_service import background_asyncio_service from eth_keys import keys @@ -20,7 +19,7 @@ from .transport import MemoryTransportPairFactory -@asynccontextmanager +@contextlib.asynccontextmanager async def ConnectionPairFactory(*, alice_handshakers: Tuple[HandshakerAPI[ProtocolAPI], ...] = (), bob_handshakers: Tuple[HandshakerAPI[ProtocolAPI], ...] = (), diff --git a/p2p/tools/factories/peer.py b/p2p/tools/factories/peer.py index e588d38798..18dbe50ad1 100644 --- a/p2p/tools/factories/peer.py +++ b/p2p/tools/factories/peer.py @@ -1,8 +1,7 @@ import asyncio +import contextlib from typing import cast, AsyncContextManager, AsyncIterator, Tuple, Type -from async_generator import asynccontextmanager - from lahja import EndpointAPI from eth_keys import keys @@ -15,7 +14,7 @@ from .connection import ConnectionPairFactory -@asynccontextmanager +@contextlib.asynccontextmanager async def PeerPairFactory(*, alice_peer_context: BasePeerContext, alice_peer_factory_class: Type[BasePeerFactory], diff --git a/setup.py b/setup.py index 7a94e08327..2fa061420b 100644 --- a/setup.py +++ b/setup.py @@ -9,8 +9,6 @@ deps = { 'p2p': [ - "async-exit-stack==1.0.1", - "async-generator==1.10", "async-service==0.1.0a7", "asyncio-cancel-token>=0.2,<0.3", "async_lru>=0.1.0,<1.0.0", @@ -34,7 +32,6 @@ "bloom-filter==1.3", "cachetools>=3.1.0,<4.0.0", "coincurve>=10.0.0,<11.0.0", - "dataclasses>=0.6, <1;python_version<'3.7'", "eth-utils>=1.8.4,<2", # Fixing this dependency due to: requests 2.20.1 has requirement # idna<2.8,>=2.5, but you'll have idna 2.8 which is incompatible. @@ -42,7 +39,7 @@ # idna 2.7 is not supported by requests 2.18 "requests>=2.20,<3", "ipython>=7.8.0,<7.10.0", # attach fails with v7.10.{0,1} - "plyvel==1.1.0", + "plyvel==1.2.0", PYEVM_DEPENDENCY, "web3==5.4.0", "lahja>=0.16.0,<0.17", @@ -52,7 +49,7 @@ "jsonschema==3.0.1", "mypy-extensions>=0.4.3,<0.5.0", "typing_extensions>=3.7.4,<4.0.0", - "ruamel.yaml==0.15.98", + "ruamel.yaml==0.16.10", "argcomplete>=1.10.0,<2", "multiaddr>=0.0.8,<0.1.0", "prometheus-client==0.7.1", @@ -76,7 +73,7 @@ # xdist pinned at <1.29 due to: https://github.com/pytest-dev/pytest-xdist/issues/472 "pytest-xdist>=1.29.0,<1.30", # only for eth2 - "ruamel.yaml==0.15.98", + "ruamel.yaml==0.16.10", "eth-tester==0.2.0b3", ], # We have to keep some separation between trio and asyncio based tests @@ -124,8 +121,8 @@ "asks>=2.3.6,<3", # validator client "eth-keyfile", # validator client ], - 'eth2-extra': [ - "milagro-bls-binding==0.1.3", + "eth2-extra": [ + "milagro-bls-binding==0.1.4", ], 'eth2-lint': [ "black==19.3b0", @@ -188,7 +185,7 @@ def filter_dependencies(package_list, *package_name): url='https://github.com/ethereum/trinity', include_package_data=True, py_modules=['trinity', 'p2p', 'eth2'], - python_requires=">=3.6,<4", + python_requires=">=3.7,<4", install_requires=install_requires, extras_require=deps, license='MIT', @@ -200,7 +197,7 @@ def filter_dependencies(package_list, *package_name): 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Natural Language :: English', - 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', ], # trinity entry_points={ diff --git a/tests-trio/p2p-trio/conftest.py b/tests-trio/p2p-trio/conftest.py index b61a9e796a..767a045df1 100644 --- a/tests-trio/p2p-trio/conftest.py +++ b/tests-trio/p2p-trio/conftest.py @@ -1,10 +1,9 @@ +import contextlib import logging import trio import pytest_trio -from async_generator import asynccontextmanager - from async_service import background_trio_service from eth_hash.auto import keccak @@ -38,7 +37,7 @@ async def socket_pair(): return sending_socket, receiving_socket -@asynccontextmanager +@contextlib.asynccontextmanager async def _manually_driven_discovery(seed, socket, nursery): _, port = socket.getsockname() discovery = ManuallyDrivenDiscoveryService( diff --git a/tests/conftest.py b/tests/conftest.py index d1a9b04f11..3e17522e76 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,12 +1,10 @@ import asyncio +import contextlib import os from pathlib import Path import tempfile import uuid -from async_generator import ( - asynccontextmanager, -) import pytest from async_service import background_asyncio_service @@ -97,7 +95,7 @@ def event_loop(): loop.close() -@asynccontextmanager +@contextlib.asynccontextmanager async def make_networking_event_bus(): # Tests run concurrently, therefore we need unique IPC paths ipc_path = Path(f"networking-{uuid.uuid4()}.ipc") diff --git a/tests/core/integration_test_helpers.py b/tests/core/integration_test_helpers.py index 63d61d620d..f7d86bd810 100644 --- a/tests/core/integration_test_helpers.py +++ b/tests/core/integration_test_helpers.py @@ -1,12 +1,10 @@ import asyncio +import contextlib from enum import Enum from pathlib import Path from tempfile import TemporaryDirectory from zipfile import ZipFile -from async_generator import ( - asynccontextmanager, -) from async_service import background_asyncio_service from cancel_token import OperationCancelled from eth_keys import keys @@ -93,7 +91,7 @@ def load_fixture_db(db_fixture, db_class=LevelDB): yield db_class(Path(tmpdir) / db_fixture.value) -@asynccontextmanager +@contextlib.asynccontextmanager async def run_peer_pool_event_server(event_bus, peer_pool, handler_type=None): handler_type = DefaultPeerPoolEventServer if handler_type is None else handler_type diff --git a/tests/core/json-rpc/test_ipc.py b/tests/core/json-rpc/test_ipc.py index de4a161dfd..151bda720c 100644 --- a/tests/core/json-rpc/test_ipc.py +++ b/tests/core/json-rpc/test_ipc.py @@ -96,13 +96,13 @@ async def get_ipc_response( assert wait_for(jsonrpc_ipc_pipe_path), "IPC server did not successfully start with IPC file" - reader, writer = await asyncio.open_unix_connection(str(jsonrpc_ipc_pipe_path), loop=event_loop) + reader, writer = await asyncio.open_unix_connection(str(jsonrpc_ipc_pipe_path)) writer.write(request_msg) await writer.drain() result_bytes = b'' while not can_decode_json(result_bytes): - result_bytes += await asyncio.tasks.wait_for(reader.readuntil(b'}'), 0.25, loop=event_loop) + result_bytes += await asyncio.tasks.wait_for(reader.readuntil(b'}'), 0.25) writer.close() return json.loads(result_bytes.decode()) diff --git a/tests/core/json-rpc/test_rpc_during_beam_sync.py b/tests/core/json-rpc/test_rpc_during_beam_sync.py index 2979ede388..92e845be52 100644 --- a/tests/core/json-rpc/test_rpc_during_beam_sync.py +++ b/tests/core/json-rpc/test_rpc_during_beam_sync.py @@ -1,12 +1,11 @@ import asyncio +import contextlib import json import os import pytest import time from typing import Dict -from async_generator import asynccontextmanager - from eth_hash.auto import keccak from eth_utils.toolz import ( assoc, @@ -80,13 +79,13 @@ async def get_ipc_response( assert wait_for(jsonrpc_ipc_pipe_path), "IPC server did not successfully start with IPC file" - reader, writer = await asyncio.open_unix_connection(str(jsonrpc_ipc_pipe_path), loop=event_loop) + reader, writer = await asyncio.open_unix_connection(str(jsonrpc_ipc_pipe_path)) writer.write(request_msg) await writer.drain() result_bytes = b'' while not can_decode_json(result_bytes): - result_bytes += await asyncio.tasks.wait_for(reader.readuntil(b'}'), 0.25, loop=event_loop) + result_bytes += await asyncio.tasks.wait_for(reader.readuntil(b'}'), 0.25) writer.close() return json.loads(result_bytes.decode()) @@ -158,7 +157,7 @@ async def make_request(*args): @pytest.fixture def fake_beam_syncer(chain, event_bus): - @asynccontextmanager + @contextlib.asynccontextmanager async def fake_beam_sync(removed_nodes: Dict): # beam sync starts, it fetches requested nodes from remote peers diff --git a/tests/core/p2p-proto/test_requests.py b/tests/core/p2p-proto/test_requests.py index f9dd37828c..4ab697e4c1 100644 --- a/tests/core/p2p-proto/test_requests.py +++ b/tests/core/p2p-proto/test_requests.py @@ -1,8 +1,8 @@ import asyncio +import contextlib import pytest -from async_exit_stack import AsyncExitStack from async_service import background_asyncio_service from eth_utils import decode_hex @@ -65,7 +65,7 @@ async def test_proxy_peer_requests(request, client_peer_pool = MockPeerPoolWithConnectedPeers([client_peer], event_bus=client_event_bus) server_peer_pool = MockPeerPoolWithConnectedPeers([server_peer], event_bus=server_event_bus) - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: await stack.enter_async_context(run_peer_pool_event_server( client_event_bus, client_peer_pool, handler_type=ETHPeerPoolEventServer )) @@ -125,7 +125,7 @@ async def test_get_pooled_transactions_request(request, client_peer_pool = MockPeerPoolWithConnectedPeers([client_peer], event_bus=client_event_bus) server_peer_pool = MockPeerPoolWithConnectedPeers([server_peer], event_bus=server_event_bus) - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: await stack.enter_async_context(run_peer_pool_event_server( client_event_bus, client_peer_pool, handler_type=ETHPeerPoolEventServer )) @@ -172,7 +172,7 @@ async def test_proxy_peer_requests_with_timeouts(request, client_peer_pool = MockPeerPoolWithConnectedPeers([client_peer], event_bus=client_event_bus) server_peer_pool = MockPeerPoolWithConnectedPeers([server_peer], event_bus=server_event_bus) - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: await stack.enter_async_context(run_peer_pool_event_server( client_event_bus, client_peer_pool, handler_type=ETHPeerPoolEventServer )) @@ -222,7 +222,7 @@ async def test_requests_when_peer_in_client_vanishs(request, client_peer_pool = MockPeerPoolWithConnectedPeers([client_peer], event_bus=client_event_bus) server_peer_pool = MockPeerPoolWithConnectedPeers([server_peer], event_bus=server_event_bus) - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: await stack.enter_async_context(run_peer_pool_event_server( client_event_bus, client_peer_pool, handler_type=ETHPeerPoolEventServer )) diff --git a/tests/core/test_contextgroup.py b/tests/core/test_contextgroup.py index c771dfb8b5..42448593ed 100644 --- a/tests/core/test_contextgroup.py +++ b/tests/core/test_contextgroup.py @@ -1,11 +1,10 @@ import asyncio +import contextlib import pytest from trio import MultiError -from async_generator import asynccontextmanager - from trinity.contextgroup import AsyncContextGroup @@ -13,7 +12,7 @@ async def test_basic(): exit_count = 0 - @asynccontextmanager + @contextlib.asynccontextmanager async def ctx(v): nonlocal exit_count await asyncio.sleep(0) @@ -32,7 +31,7 @@ async def ctx(v): async def test_exception_entering_context(): exit_count = 0 - @asynccontextmanager + @contextlib.asynccontextmanager async def ctx(should_raise=False): nonlocal exit_count await asyncio.sleep(0) @@ -64,7 +63,7 @@ async def f(should_raise): if should_raise: raise ValueError() - @asynccontextmanager + @contextlib.asynccontextmanager async def ctx(should_raise=False): nonlocal exit_count await asyncio.sleep(0) @@ -87,7 +86,7 @@ async def ctx(should_raise=False): async def test_exception_exiting(): exit_count = 0 - @asynccontextmanager + @contextlib.asynccontextmanager async def ctx(should_raise=False): nonlocal exit_count await asyncio.sleep(0) diff --git a/tests/core/tx-pool/test_tx_pool.py b/tests/core/tx-pool/test_tx_pool.py index bc978d791e..e6020e0344 100644 --- a/tests/core/tx-pool/test_tx_pool.py +++ b/tests/core/tx-pool/test_tx_pool.py @@ -1,8 +1,8 @@ import asyncio +import contextlib import pytest import uuid -from async_exit_stack import AsyncExitStack from async_service import background_asyncio_service from eth._utils.address import ( force_bytes_to_address @@ -76,7 +76,7 @@ async def two_connected_tx_pools(event_bus, bob_peer_pool = MockPeerPoolWithConnectedPeers([bob], event_bus=bob_event_bus) alice_peer_pool = MockPeerPoolWithConnectedPeers([alice], event_bus=alice_event_bus) - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: await stack.enter_async_context(run_peer_pool_event_server( bob_event_bus, bob_peer_pool, handler_type=ETHPeerPoolEventServer )) diff --git a/tests/libp2p/bcc/test_syncing.py b/tests/libp2p/bcc/test_syncing.py index 25256dd6d8..50794c0511 100644 --- a/tests/libp2p/bcc/test_syncing.py +++ b/tests/libp2p/bcc/test_syncing.py @@ -1,6 +1,6 @@ import asyncio +import contextlib -from async_generator import asynccontextmanager import pytest from trinity.tools.bcc_factories import ( @@ -11,7 +11,7 @@ ) -@asynccontextmanager +@contextlib.asynccontextmanager async def get_sync_setup( request, event_loop, diff --git a/tests/p2p/test_behavior_and_logic_api.py b/tests/p2p/test_behavior_and_logic_api.py index d19815c29b..d5d03b8f36 100644 --- a/tests/p2p/test_behavior_and_logic_api.py +++ b/tests/p2p/test_behavior_and_logic_api.py @@ -1,8 +1,7 @@ import asyncio +import contextlib import pytest -from async_generator import asynccontextmanager - from eth_utils import ValidationError from p2p.p2p_proto import Ping @@ -18,7 +17,7 @@ class SimpleLogic(BaseLogic): - @asynccontextmanager + @contextlib.asynccontextmanager async def apply(self, connection): yield diff --git a/tests/p2p/test_qualifiers.py b/tests/p2p/test_qualifiers.py index e1733ec495..882fdc7b6a 100644 --- a/tests/p2p/test_qualifiers.py +++ b/tests/p2p/test_qualifiers.py @@ -1,7 +1,6 @@ +import contextlib import pytest -from async_generator import asynccontextmanager - from p2p.abc import ConnectionAPI, LogicAPI from p2p.logic import BaseLogic from p2p.qualifiers import ( @@ -18,7 +17,7 @@ class SimpleLogic(BaseLogic): - @asynccontextmanager + @contextlib.asynccontextmanager async def apply(self, connection): yield diff --git a/tox.ini b/tox.ini index 2b9a85171a..545a33b4ff 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,15 @@ [tox] envlist= - py{36,37}-{eth1-core,p2p,p2p-trio,integration,lightchain_integration,eth2-core,eth2-fixtures,eth2-integration,eth1-components,eth2-utils,eth2-trio} - py36-long_run_integration - py36-rpc-blockchain - py36-rpc-state-{frontier,homestead,tangerine_whistle,spurious_dragon,byzantium,constantinople,petersburg,istanbul} + py{37,38}-{eth1-core,p2p,p2p-trio,integration,lightchain_integration,eth2-core,eth2-fixtures,eth2-integration,eth1-components,eth2-utils,eth2-trio} + py38-long_run_integration + py38-rpc-blockchain + py38-rpc-state-{frontier,homestead,tangerine_whistle,spurious_dragon,byzantium,constantinople,petersburg,istanbul} py37-rpc-state-{quadratic,sstore,zero_knowledge} py37-{libp2p,eth2-components} - py{36,37}-lint - py{36,37}-lint-eth2 - py{36,37}-wheel-cli - py36-docs + py{38,37}-lint + py{38,37}-lint-eth2 + py{38,37}-wheel-cli + py38-docs [flake8] max-line-length= 100 @@ -60,10 +60,10 @@ commands= deps = .[p2p,trinity,eth2,test,test-asyncio] basepython = - py36: python3.6 py37: python3.7 + py38: python3.8 -[testenv:py36-p2p-trio] +[testenv:py38-p2p-trio] deps = .[p2p,test,test-trio] commands = pytest -n 4 {posargs:tests-trio/p2p-trio} @@ -71,7 +71,7 @@ commands = pytest -n 4 {posargs:tests-trio/p2p-trio} deps = .[p2p,test,test-trio] commands = pytest -n 4 {posargs:tests-trio/p2p-trio} -[testenv:py36-eth2-trio] +[testenv:py38-eth2-trio] deps = .[eth2,trinity,test,test-trio] commands = pytest -n 4 {posargs:tests-trio/eth2} @@ -79,7 +79,7 @@ commands = pytest -n 4 {posargs:tests-trio/eth2} deps = .[eth2,trinity,test,test-trio] commands = pytest -n 4 {posargs:tests-trio/eth2} -[testenv:py36-docs] +[testenv:py38-docs] whitelist_externals= make deps = .[p2p, trinity, eth2, doc] @@ -104,7 +104,7 @@ commands= /bin/bash -c 'pip install --upgrade "$(ls dist/*.whl)""[p2p,trinity]" --progress-bar off' pytest {posargs:tests/integration/ -k 'trinity_cli' --log-cli-level 0} -[testenv:py36-wheel-cli] +[testenv:py38-wheel-cli] deps = {[common-wheel-cli]deps} whitelist_externals = {[common-wheel-cli]whitelist_externals} commands = {[common-wheel-cli]commands} @@ -131,7 +131,7 @@ commands= # The `trinity_cli` tests are already run by the pyxx-wheel-cli jobs. No need to repeat them here pytest --integration -n 1 {posargs:tests/integration/ -k 'not lightchain_integration and not trinity_cli'} -[testenv:py36-integration] +[testenv:py38-integration] deps = {[common-integration]deps} passenv = {[common-integration]passenv} commands = {[common-integration]commands} @@ -141,7 +141,7 @@ deps = {[common-integration]deps} passenv = {[common-integration]passenv} commands = {[common-integration]commands} -[testenv:py36-long_run_integration] +[testenv:py38-long_run_integration] deps = {[common-integration]deps} passenv = {[common-integration]passenv} commands = @@ -176,7 +176,7 @@ commands= mypy -p p2p --config-file {toxinidir}/mypy.ini -[testenv:py36-lint] +[testenv:py38-lint] deps = {[common-lint]deps} commands= {[common-lint]commands} @@ -193,7 +193,7 @@ commands= black --check eth2 trinity/components/eth2 tests/eth2 tests/libp2p tests/components/eth2 tests-trio/eth2 isort --recursive --check-only eth2 trinity/components/eth2 tests/eth2 tests/libp2p tests/components/eth2 tests-trio/eth2 -[testenv:py36-lint-eth2] +[testenv:py38-lint-eth2] deps = {[common-lint-eth2]deps} commands= {[common-lint-eth2]commands} @@ -204,13 +204,13 @@ commands= {[common-lint-eth2]commands} [common-eth2-utils] deps = .[eth2,eth2-extra,test] -[testenv:py36-eth2-utils] +[testenv:py38-eth2-utils] deps = {[common-eth2-utils]deps} [testenv:py37-eth2-utils] deps = {[common-eth2-utils]deps} -[testenv:py36-eth2-fixtures] +[testenv:py38-eth2-fixtures] deps = .[eth2,eth2-extra,test] commands= pytest -n 4 --config minimal {posargs:tests/eth2/fixtures/} diff --git a/trinity/_utils/version.py b/trinity/_utils/version.py index 3cb3b53866..93a3124138 100644 --- a/trinity/_utils/version.py +++ b/trinity/_utils/version.py @@ -9,7 +9,7 @@ def construct_trinity_client_identifier() -> str: """ Constructs the client identifier string - e.g. 'Trinity/v1.2.3/darwin-amd64/python3.6.5' + e.g. 'Trinity/v1.2.3/darwin-amd64/python3.7.3' """ return ( "Trinity/" diff --git a/trinity/components/builtin/json_rpc/component.py b/trinity/components/builtin/json_rpc/component.py index 63062b2730..cadf298185 100644 --- a/trinity/components/builtin/json_rpc/component.py +++ b/trinity/components/builtin/json_rpc/component.py @@ -6,7 +6,6 @@ from typing import Iterator, Tuple, Union from async_service import background_asyncio_service, Service -from async_exit_stack import AsyncExitStack from lahja import EndpointAPI @@ -147,7 +146,7 @@ async def do_run(cls, boot_info: BootInfo, event_bus: EndpointAPI) -> None: ) services_to_exit += (http_server,) - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: managers = tuple([ await stack.enter_async_context(background_asyncio_service(service)) for service in services_to_exit diff --git a/trinity/components/builtin/metrics/component.py b/trinity/components/builtin/metrics/component.py index a5d1ad99c3..f0a4ce0e79 100644 --- a/trinity/components/builtin/metrics/component.py +++ b/trinity/components/builtin/metrics/component.py @@ -4,9 +4,9 @@ Namespace, _SubParsersAction, ) +import contextlib from typing import Type -from async_exit_stack import AsyncExitStack from async_service import background_trio_service from eth_utils import ValidationError @@ -143,7 +143,7 @@ async def do_run(cls, boot_info: BootInfo, event_bus: EndpointAPI) -> None: services_to_exit = (metrics_service, system_metrics_collector,) - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: managers = tuple([ await stack.enter_async_context(background_trio_service(service)) for service in services_to_exit diff --git a/trinity/components/builtin/network_db/component.py b/trinity/components/builtin/network_db/component.py index 788e9cc6db..f0dad4367a 100644 --- a/trinity/components/builtin/network_db/component.py +++ b/trinity/components/builtin/network_db/component.py @@ -4,10 +4,10 @@ _SubParsersAction, ) import asyncio +import contextlib import logging from typing import ClassVar, Iterable -from async_exit_stack import AsyncExitStack from async_service import background_asyncio_service, Service from eth_utils import ValidationError, to_tuple from lahja import EndpointAPI @@ -240,7 +240,7 @@ async def do_run(cls, boot_info: BootInfo, event_bus: EndpointAPI) -> None: except BadDatabaseError as err: cls.logger.exception(f"Unrecoverable error in Network Component: {err}") - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: tracker_managers = tuple([ await stack.enter_async_context(background_asyncio_service(service)) for service in tracker_services diff --git a/trinity/components/eth2/beacon/component.py b/trinity/components/eth2/beacon/component.py index 04bb4af2b1..3a10d589cf 100644 --- a/trinity/components/eth2/beacon/component.py +++ b/trinity/components/eth2/beacon/component.py @@ -1,9 +1,9 @@ from argparse import ArgumentParser, _SubParsersAction import asyncio +import contextlib import logging from typing import Set, Tuple -from async_exit_stack import AsyncExitStack from lahja import EndpointAPI from libp2p.crypto.keys import KeyPair from libp2p.crypto.secp256k1 import create_new_key_pair @@ -174,7 +174,7 @@ async def do_run(cls, boot_info: BootInfo, event_bus: EndpointAPI) -> None: if boot_info.args.bn_only: services += (chain_maintainer, validator_handler) - async with AsyncExitStack() as stack: + async with contextlib.AsyncExitStack() as stack: for service in services: await stack.enter_async_context(run_service(service)) diff --git a/trinity/extensibility/component.py b/trinity/extensibility/component.py index 98b27db5c8..1e921e1d1d 100644 --- a/trinity/extensibility/component.py +++ b/trinity/extensibility/component.py @@ -7,12 +7,12 @@ _SubParsersAction, ) import asyncio +import contextlib import logging import pathlib import signal from typing import AsyncIterator, Type, TYPE_CHECKING, Union -from async_generator import asynccontextmanager from lahja import AsyncioEndpoint, ConnectionConfig, EndpointAPI, TrioEndpoint @@ -125,7 +125,7 @@ async def _cleanup_component_task(component_name: str, task: "asyncio.Future[Non logger.debug("Stopped component: %s", component_name) -@asynccontextmanager +@contextlib.asynccontextmanager async def run_component(component: ComponentAPI) -> AsyncIterator[None]: task = asyncio.ensure_future(component.run()) logger.debug("Starting component: %s", component.name) @@ -135,7 +135,7 @@ async def run_component(component: ComponentAPI) -> AsyncIterator[None]: await _cleanup_component_task(component.name, task) -@asynccontextmanager +@contextlib.asynccontextmanager async def _run_asyncio_component_in_proc( component_type: Type['AsyncioIsolatedComponent'], event_bus: EndpointAPI, @@ -152,7 +152,7 @@ async def _run_asyncio_component_in_proc( await _cleanup_component_task(component_type.name, task) -@asynccontextmanager +@contextlib.asynccontextmanager async def _run_trio_component_in_proc( component_type: Type['TrioIsolatedComponent'], event_bus: EndpointAPI, @@ -170,7 +170,7 @@ async def _run_trio_component_in_proc( logger.debug("Stopped component: %s", component_type.name) -@asynccontextmanager +@contextlib.asynccontextmanager async def _run_standalone_component( component_type: Union[Type['TrioIsolatedComponent'], Type['AsyncioIsolatedComponent']], app_identifier: str, diff --git a/trinity/protocol/bcc_libp2p/node.py b/trinity/protocol/bcc_libp2p/node.py index 8596a53a78..556d5fcee1 100644 --- a/trinity/protocol/bcc_libp2p/node.py +++ b/trinity/protocol/bcc_libp2p/node.py @@ -1,4 +1,5 @@ import asyncio +import contextlib from dataclasses import dataclass import logging import operator @@ -152,7 +153,6 @@ get_requested_beacon_blocks, get_beacon_blocks_by_root, ) -from async_generator import asynccontextmanager from trinity.metrics.events import ( Libp2pPeersRequest, @@ -547,7 +547,7 @@ def _register_rpc_handlers(self) -> None: async def new_stream(self, peer_id: ID, protocol: TProtocol) -> INetStream: return await self.host.new_stream(peer_id, [protocol]) - @asynccontextmanager + @contextlib.asynccontextmanager async def new_handshake_interaction(self, stream: INetStream) -> AsyncIterator[Interaction]: try: async with Interaction(stream) as interaction: @@ -567,7 +567,7 @@ async def new_handshake_interaction(self, stream: INetStream) -> AsyncIterator[I ) raise HandshakeFailure from error - @asynccontextmanager + @contextlib.asynccontextmanager async def post_handshake_handler_interaction( self, stream: INetStream @@ -585,7 +585,7 @@ async def post_handshake_handler_interaction( await stream.reset() return - @asynccontextmanager + @contextlib.asynccontextmanager async def my_request_interaction(self, stream: INetStream) -> AsyncIterator[Interaction]: try: async with Interaction(stream) as interaction: diff --git a/trinity/server.py b/trinity/server.py index 7e3095c4f3..2c14b23a47 100644 --- a/trinity/server.py +++ b/trinity/server.py @@ -1,5 +1,6 @@ from abc import abstractmethod import asyncio +import contextlib from typing import ( AsyncIterator, Generic, @@ -8,7 +9,6 @@ TypeVar, ) -from async_generator import asynccontextmanager from async_service import Service @@ -103,7 +103,7 @@ def __init__(self, def _make_peer_pool(self) -> TPeerPool: ... - @asynccontextmanager + @contextlib.asynccontextmanager async def tcp_listener(self) -> AsyncIterator[None]: # TODO: Support IPv6 addresses as well. tcp_listener = await asyncio.start_server( diff --git a/trinity/sync/common/headers.py b/trinity/sync/common/headers.py index bd4ed3707b..ffdfbee172 100644 --- a/trinity/sync/common/headers.py +++ b/trinity/sync/common/headers.py @@ -1,6 +1,7 @@ from abc import ABC, abstractmethod import asyncio from concurrent.futures import CancelledError +import contextlib from operator import attrgetter, itemgetter from random import randrange from typing import ( @@ -16,9 +17,6 @@ Type, ) -from async_generator import ( - asynccontextmanager, -) from cancel_token import CancelToken, OperationCancelled from eth_typing import ( BlockIdentifier, @@ -924,7 +922,7 @@ async def _build_skeleton(self) -> None: async with self._get_skeleton_syncer(peer) as syncer: await self._full_skeleton_sync(syncer) - @asynccontextmanager + @contextlib.asynccontextmanager async def _get_skeleton_syncer( self, peer: TChainPeer) -> AsyncIterator[SkeletonSyncer[TChainPeer]]: if self._is_syncing_skeleton: diff --git a/trinity/tools/async_process_runner.py b/trinity/tools/async_process_runner.py index beddf80f03..c7eb83b9f8 100644 --- a/trinity/tools/async_process_runner.py +++ b/trinity/tools/async_process_runner.py @@ -1,4 +1,5 @@ import asyncio +import contextlib import logging import os import signal @@ -10,7 +11,6 @@ Tuple, ) -from async_generator import asynccontextmanager from async_timeout import timeout @@ -21,7 +21,7 @@ class AsyncProcessRunner(): proc: asyncio.subprocess.Process @classmethod - @asynccontextmanager + @contextlib.asynccontextmanager async def run(cls, cmds: Tuple[str, ...], timeout_sec: int = 10) -> AsyncIterator['AsyncProcessRunner']: diff --git a/trinity/tools/bcc_factories.py b/trinity/tools/bcc_factories.py index 83a601f743..0a3a9e9fc6 100644 --- a/trinity/tools/bcc_factories.py +++ b/trinity/tools/bcc_factories.py @@ -1,9 +1,8 @@ from eth2.beacon.tools.factories import BeaconChainFactory import asyncio +import contextlib from typing import Any, AsyncIterator, Dict, Iterable, Collection, Tuple, Type, Sequence -from async_generator import asynccontextmanager - from cancel_token import CancelToken from lahja import EndpointAPI @@ -90,7 +89,7 @@ class Meta: head_slot = 0 -@asynccontextmanager +@contextlib.asynccontextmanager async def ConnectionPairFactory( alice_chaindb: AsyncBeaconChainDB = None, alice_branch: Collection[BaseSignedBeaconBlock] = None, diff --git a/trinity/tools/event_bus.py b/trinity/tools/event_bus.py index 6e81b9becd..c3bb839636 100644 --- a/trinity/tools/event_bus.py +++ b/trinity/tools/event_bus.py @@ -1,11 +1,11 @@ import asyncio +import contextlib from typing import AsyncIterator, Type -from async_generator import asynccontextmanager from lahja import BaseEvent, EndpointAPI -@asynccontextmanager +@contextlib.asynccontextmanager async def mock_request_response(request_type: Type[BaseEvent], response: BaseEvent, event_bus: EndpointAPI) -> AsyncIterator[None]: