Skip to content

Commit

Permalink
Merge pull request #333 from fantix/pyup-update-aiocontextvars-0.1.2-…
Browse files Browse the repository at this point in the history
…to-0.2.0

Update aiocontextvars to 0.2.0
  • Loading branch information
fantix authored Sep 10, 2018
2 parents 7d7b9c4 + 07a11b0 commit e0a17ab
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 52 deletions.
9 changes: 1 addition & 8 deletions gino/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@
import sys
import time

from aiocontextvars import ContextVar
from sqlalchemy.engine import Engine, Connection
from sqlalchemy.sql import schema

from .transaction import GinoTransaction


if sys.version_info >= (3, 7):
# noinspection PyPackageRequirements,PyUnresolvedReferences
from contextvars import ContextVar
else:
# noinspection PyPackageRequirements
from aiocontextvars import ContextVar # pragma: no cover


class _BaseDBAPIConnection:
_reset_agent = None
gino_conn = None
Expand Down
14 changes: 0 additions & 14 deletions gino/ext/aiohttp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# noinspection PyPackageRequirements
from aiohttp.web import HTTPNotFound, middleware
from sqlalchemy.engine.url import URL
try:
# noinspection PyPackageRequirements
from aiocontextvars import enable_inherit, disable_inherit
except ImportError:
enable_inherit = disable_inherit = lambda loop: None

from ..api import Gino as _Gino, GinoExecutor as _Executor
from ..engine import GinoConnection as _Connection, GinoEngine as _Engine
Expand Down Expand Up @@ -114,15 +109,9 @@ async def _middleware(self, request, handler):
def init_app(self, app):
app['db'] = self

inherit_enabled = [False]

config = app['config'].get('gino', {})

async def before_server_start(app_):
if config.setdefault('enable_inherit', True):
enable_inherit(app_.loop)
inherit_enabled[0] = True

if config.get('dsn'):
dsn = config['dsn']
else:
Expand All @@ -145,9 +134,6 @@ async def before_server_start(app_):

async def after_server_stop(app_):
await self.pop_bind().close()
if inherit_enabled[0]:
disable_inherit(app_.loop)
inherit_enabled[0] = False

app.on_startup.append(before_server_start)
app.on_cleanup.append(after_server_stop)
Expand Down
8 changes: 0 additions & 8 deletions gino/ext/quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
# noinspection PyPackageRequirements
from quart.exceptions import NotFound
from sqlalchemy.engine.url import URL
try:
# noinspection PyPackageRequirements
from aiocontextvars import enable_inherit, disable_inherit
except ImportError:
enable_inherit = disable_inherit = lambda loop: None

from ..api import Gino as _Gino, GinoExecutor as _Executor
from ..engine import GinoConnection as _Connection, GinoEngine as _Engine
Expand Down Expand Up @@ -108,9 +103,6 @@ async def after_response(response):

@app.before_first_request
async def before_first_request():
if app.config.setdefault('DB_USE_CONNECTION_FOR_REQUEST', True):
enable_inherit(asyncio.get_event_loop())

dsn = app.config.get('DB_DSN')
if not dsn:
dsn = URL(
Expand Down
14 changes: 0 additions & 14 deletions gino/ext/sanic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# noinspection PyPackageRequirements
from sanic.exceptions import NotFound
from sqlalchemy.engine.url import URL
try:
# noinspection PyPackageRequirements
from aiocontextvars import enable_inherit, disable_inherit
except ImportError:
enable_inherit = disable_inherit = lambda loop: None

from ..api import Gino as _Gino, GinoExecutor as _Executor
from ..engine import GinoConnection as _Connection, GinoEngine as _Engine
Expand Down Expand Up @@ -86,8 +81,6 @@ def __init__(self, app=None, *args, **kwargs):
self.init_app(app)

def init_app(self, app):
inherit_enabled = [False]

if app.config.setdefault('DB_USE_CONNECTION_FOR_REQUEST', True):
@app.middleware('request')
async def on_request(request):
Expand All @@ -101,10 +94,6 @@ async def on_response(request, _):

@app.listener('before_server_start')
async def before_server_start(_, loop):
if app.config.setdefault('DB_USE_CONNECTION_FOR_REQUEST', True):
enable_inherit(loop)
inherit_enabled[0] = True

if app.config.get('DB_DSN'):
dsn = app.config.DB_DSN
else:
Expand All @@ -128,9 +117,6 @@ async def before_server_start(_, loop):
@app.listener('after_server_stop')
async def after_server_stop(_, loop):
await self.pop_bind().close()
if inherit_enabled[0]:
disable_inherit(loop)
inherit_enabled[0] = False

async def first_or_404(self, *args, **kwargs):
rv = await self.first(*args, **kwargs)
Expand Down
7 changes: 0 additions & 7 deletions gino/ext/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ async def get(self, uid):

from sqlalchemy.engine.url import URL
from tornado.options import options as _options, define as _define
try:
# noinspection PyPackageRequirements
from aiocontextvars import enable_inherit as _enable_inherit
except ImportError:
_enable_inherit = lambda _: None # NOQA

from ..api import Gino as _Gino, GinoExecutor as _Executor
from ..engine import GinoConnection as _Connection, GinoEngine as _Engine
Expand Down Expand Up @@ -325,8 +320,6 @@ async def late_init(self, db: Gino, *, loop=None, options=_options):
else:
raise RuntimeError('AsyncIOLoop is required to run GINO')

_enable_inherit(asyncio_loop)

self.db = db

if 'dsn' in options:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
asyncpg==0.17.0
SQLAlchemy==1.2.11
aiocontextvars==0.1.2;python_version<"3.7"
aiocontextvars==0.2.0

0 comments on commit e0a17ab

Please sign in to comment.