From ac43d9a444461e986a4d0f335aa8323a02d2ef8c Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Tue, 13 Feb 2018 12:06:53 +0000 Subject: [PATCH] prepare for v0.8 release for aiohttp 3 (#174) * prepare for v0.8 release for aiohttp 3 * cleanup run_app * set versions --- HISTORY.rst | 5 +++-- README.rst | 4 ++-- aiohttp_devtools/runserver/main.py | 20 +++++++++---------- aiohttp_devtools/runserver/serve.py | 7 +++---- .../start/template/requirements.txt | 2 +- setup.py | 8 ++++---- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index d0643bd2..0dab6d36 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,9 +3,10 @@ History ------- -0.8.0 (2018-02-XX) +0.8.0 (2018-02-12) ----------------- -* rewrite for aiohttp >= 3 stop using multiprocessing, #173 +* complete rewrite for aiohttp >= 3 stop using multiprocessing #173 +* update required packages #171 0.7.1 (2018-02-01) ------------------ diff --git a/README.rst b/README.rst index 53714555..765cfd68 100644 --- a/README.rst +++ b/README.rst @@ -5,8 +5,8 @@ aiohttp-devtools Dev tools for `aiohttp`_. -(Note: ``aiohttp-devtools>=0.3`` only supports ``aiohttp>=2.0``, if you're using older aiohttp, please use -``aiohtt-devtools==0.21``, see `History.rst`_ for details.) +(Note: ``aiohttp-devtools>=0.8`` only supports ``aiohttp>=3.0``, if you're using older aiohttp, please use +an older version of ``aiohtt-devtools``, see `History.rst`_ for details.) **aiohttp-devtools** provides a number of tools useful when developing applications with aiohttp and associated libraries. diff --git a/aiohttp_devtools/runserver/main.py b/aiohttp_devtools/runserver/main.py index deef03c5..62fb736e 100644 --- a/aiohttp_devtools/runserver/main.py +++ b/aiohttp_devtools/runserver/main.py @@ -2,6 +2,8 @@ import contextlib import os +from aiohttp.web_runner import AppRunner, TCPSite + from ..logs import rs_dft_logger as logger from .config import Config from .serve import HOST, check_port_open, create_auxiliary_app @@ -9,10 +11,11 @@ def run_app(app, port, loop): - handler = app.make_handler(access_log=None, loop=loop) + runner = AppRunner(app, access_log=None) + loop.run_until_complete(runner.setup()) - loop.run_until_complete(app.startup()) - server = loop.run_until_complete(loop.create_server(handler, HOST, port)) + site = TCPSite(runner, HOST, port, shutdown_timeout=0.01) + loop.run_until_complete(site.start()) try: loop.run_forever() @@ -20,15 +23,10 @@ def run_app(app, port, loop): pass finally: logger.info('shutting down server...') - server.close() - loop.run_until_complete(server.wait_closed()) - loop.run_until_complete(app.shutdown()) - with contextlib.suppress(asyncio.TimeoutError, KeyboardInterrupt): - loop.run_until_complete(handler.shutdown(0.1)) + start = loop.time() with contextlib.suppress(asyncio.TimeoutError, KeyboardInterrupt): - loop.run_until_complete(app.cleanup()) - with contextlib.suppress(KeyboardInterrupt): - loop.close() + loop.run_until_complete(runner.cleanup()) + logger.debug('shutdown took %0.2fs', loop.time() - start) def runserver(**config_kwargs): diff --git a/aiohttp_devtools/runserver/serve.py b/aiohttp_devtools/runserver/serve.py index d4a1322e..e1732e89 100644 --- a/aiohttp_devtools/runserver/serve.py +++ b/aiohttp_devtools/runserver/serve.py @@ -151,13 +151,12 @@ async def src_reload(app, path: str=None): async def cleanup_aux_app(app): aux_logger.debug('closing %d websockets...', len(app[WS])) - coros = [ws.close() for ws, _ in app[WS]] - await asyncio.gather(*coros) + await asyncio.gather(*(ws.close() for ws, _ in app[WS])) def create_auxiliary_app(*, static_path: str, static_url='/', livereload=True): app = web.Application() - app[WS] = [] + app[WS] = set() app.update( static_path=static_path, static_url=static_url, @@ -232,7 +231,7 @@ async def websocket_handler(request): elif command == 'info': aux_logger.debug('browser connected: %s', data) url = '/' + data['url'].split('/', 3)[-1] - request.app[WS].append((ws, url)) + request.app[WS].add((ws, url)) else: aux_logger.error('Unknown ws message %s', msg.data) await ws.close() diff --git a/aiohttp_devtools/start/template/requirements.txt b/aiohttp_devtools/start/template/requirements.txt index 5d88304a..a14732a9 100644 --- a/aiohttp_devtools/start/template/requirements.txt +++ b/aiohttp_devtools/start/template/requirements.txt @@ -1,7 +1,7 @@ # {# This file is special: lines are made unique, stripped and sorted before the new requirements.txt file is created #} # you will need to install these requirements with `pip install -r requirements.txt` -aiohttp==3.0.0 +aiohttp==3.0.1 pytest==3.4.0 pytest-aiohttp==0.3.0 pytest-cov==2.5.1 diff --git a/setup.py b/setup.py index da92822c..7eb6ae55 100644 --- a/setup.py +++ b/setup.py @@ -62,12 +62,12 @@ aiohttp-devtools=aiohttp_devtools.cli:cli """, install_requires=[ - 'aiohttp>=2.3.9', + 'aiohttp>=3.0.1', 'aiohttp_debugtoolbar>=0.4.0', 'click>=6.6', - 'isort>=4.2.5', - 'Jinja2>=2.8.1', - 'watchgod>=0.0.2', + 'isort>=4.3.3', + 'Jinja2>=2.10', + 'watchgod>=0.0.3', ], python_requires='>=3.5', )