Skip to content

Commit

Permalink
prepare for v0.8 release for aiohttp 3 (#174)
Browse files Browse the repository at this point in the history
* prepare for v0.8 release for aiohttp 3

* cleanup run_app

* set versions
  • Loading branch information
samuelcolvin authored Feb 13, 2018
1 parent d70b58f commit ac43d9a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
5 changes: 3 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 9 additions & 11 deletions aiohttp_devtools/runserver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@
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
from .watch import AppTask, LiveReloadTask


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()
except KeyboardInterrupt: # pragma: no branch
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):
Expand Down
7 changes: 3 additions & 4 deletions aiohttp_devtools/runserver/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion aiohttp_devtools/start/template/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)

0 comments on commit ac43d9a

Please sign in to comment.