Skip to content
Commits on Source (4)
[bumpversion]
current_version = 0.3.2
current_version = 1.0.0
commit = True
tag = True
......
image: "python:3.6"
image: "python:3.7"
before_script:
- pip install .
- pip install -r requirements-dev.txt
- pip install pipenv
- pipenv install -d --system
stages:
- test
- upload
check-code:
lint-code:
stage: test
script: make check
script: make lint
run-test:
inspect-code:
stage: test
script: make inspect
run-test-3.6:
image: "python:3.6"
stage: test
script: pytest
run-test-3.7:
stage: test
script: pytest
upload-to-pypi:
stage: upload
before_script:
- pip install twine
script:
- python setup.py bdist_wheel
- twine upload dist/*
......
......@@ -22,7 +22,7 @@ jobs=4
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=pylint_common
load-plugins=
# Pickle collected data for later comparisons.
persistent=yes
......
......@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [1.0.0] - 2019-03-03
### Changed
- Migrate to `rethinkdb >= 2.4.0` usage
## [0.3.2] - 2018-07-02
### Added
......
check:
lint:
pylint async_repool
mypy --ignore-missing-imports async_repool
pycodestyle async_repool
inspect:
pipenv check
bandit -r async_repool
pytest:
pytest
\ No newline at end of file
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
pylint = ">=2.1.1"
mypy = ">=0.641"
pycodestyle = ">=2.4.0"
twine = "~=1.11.0"
pytest = "~=3.7.1"
pytest-cov = "~=2.5.1"
asynctest = "~=0.12.2"
pytest-sugar = "~=0.9.1"
ipdb = '*'
ipython = '*'
bandit = "*"
[packages]
async-repool = {path = "."}
[requires]
# python_version = "3.7"
This diff is collapsed.
......@@ -4,7 +4,7 @@ __author__ = "Bogdan Gladyshev"
__copyright__ = "Copyright 2017, Bogdan Gladyshev"
__credits__ = ["Bogdan Gladyshev"]
__license__ = "MIT"
__version__ = "0.3.2"
__version__ = "1.0.0"
__maintainer__ = "Bogdan Gladyshev"
__email__ = "siredvin.dark@gmail.com"
__status__ = "Production"
from asyncio import Queue, Lock
import logging
from typing import Dict, Union, Any, AsyncIterable, Optional
from typing import Dict, Union, Optional
import time
import rethinkdb as R
import rethinkdb
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential
__author__ = "Bogdan Gladyshev"
__copyright__ = "Copyright 2017, Bogdan Gladyshev"
__credits__ = ["Bogdan Gladyshev"]
__license__ = "MIT"
__version__ = "0.3.2"
__version__ = "1.0.0"
__maintainer__ = "Bogdan Gladyshev"
__email__ = "siredvin.dark@gmail.com"
__status__ = "Production"
__all__ = ['AsyncConnectionPool', 'fetch_cursor', 'PoolException']
__all__ = ['AsyncConnectionPool', 'PoolException', 'R']
_log = logging.getLogger(__name__)
R = rethinkdb.RethinkDB()
R.set_loop_type('asyncio')
RETRY_ATTEMPTS = 20
......@@ -26,16 +27,7 @@ class PoolException(Exception):
pass
async def fetch_cursor(cursor) -> AsyncIterable[Dict[str, Any]]:
"""
Additonal method that wraps asyncio rethinkDB cursos to AsyncIterable.
Just util method to allow async for usage
"""
while await cursor.fetch_next():
yield await cursor.next()
class AsyncConnectionWrapper(object):
class AsyncConnectionWrapper:
def __init__(self, pool: 'AsyncConnectionPool', conn=None, **kwargs) -> None:
self._pool = pool
......@@ -84,7 +76,7 @@ class AsyncConnectionContextManager: # pylint: disable=too-few-public-methods
await self.pool.release(self.conn)
class AsyncConnectionPool(object):
class AsyncConnectionPool:
__slots__ = (
'pool_size', 'connection_ttl', '_current_acquired',
......
pylint>=1.7.4
pylint-common>=0.2.5
mypy>=0.550
pycodestyle>=2.3.1
pytest>=3.3.1
pytest-sugar
asynctest>=0.11.1
twine>=1.9.1
\ No newline at end of file
......@@ -11,7 +11,7 @@ with open('README.rst') as readme_file:
setup(
name='async-repool',
version='0.3.2',
version='1.0.0',
description="AsyncIO connection pool for RethinkDB",
long_description=readme,
author="Bogdan Gladyshev",
......@@ -20,8 +20,8 @@ setup(
packages=find_packages(),
include_package_data=True,
install_requires=[
"rethinkdb>=2.3.0.post6",
"tenacity>=4.12.0"
"rethinkdb>=2.4.0",
"tenacity>=5.0.0"
],
license="MIT license",
zip_safe=False,
......
......@@ -10,7 +10,7 @@ class ConnectionMock:
class TestPool(asynctest.TestCase):
@asynctest.patch('rethinkdb.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
@asynctest.patch('async_repool.async_pool.R.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
async def test_create_pool(self, mocked_connect):
from async_repool.async_pool import AsyncConnectionPool
p = AsyncConnectionPool(dict())
......@@ -18,7 +18,7 @@ class TestPool(asynctest.TestCase):
self.assertFalse(p.empty)
await p.release_pool()
@asynctest.patch('rethinkdb.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
@asynctest.patch('async_repool.async_pool.R.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
async def test_acquire_release_one(self, mocked_connect):
from async_repool.async_pool import AsyncConnectionPool
p = AsyncConnectionPool(dict())
......@@ -30,7 +30,7 @@ class TestPool(asynctest.TestCase):
self.assertEqual(nb_init, nb_term)
await p.release_pool()
@asynctest.patch('rethinkdb.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
@asynctest.patch('async_repool.async_pool.R.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
async def test_acquire_one(self, mocked_connect):
from async_repool.async_pool import AsyncConnectionPool
p = AsyncConnectionPool(dict())
......@@ -42,7 +42,7 @@ class TestPool(asynctest.TestCase):
await p.release(conn)
await p.release_pool()
@asynctest.patch('rethinkdb.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
@asynctest.patch('async_repool.async_pool.R.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
async def test_acquire(self, mocked_connect):
from async_repool.async_pool import AsyncConnectionPool
p = AsyncConnectionPool(dict())
......@@ -52,7 +52,7 @@ class TestPool(asynctest.TestCase):
await p.release(conn)
await p.release_pool()
@asynctest.patch('rethinkdb.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
@asynctest.patch('async_repool.async_pool.R.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
async def test_release_pool(self, mocked_connect):
from async_repool.async_pool import AsyncConnectionPool, PoolException
p = AsyncConnectionPool(dict())
......@@ -63,7 +63,7 @@ class TestPool(asynctest.TestCase):
with self.assertRaises(PoolException):
await p.release_pool()
@asynctest.patch('rethinkdb.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
@asynctest.patch('async_repool.async_pool.R.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
async def test_connect(self, mocked_connect):
from async_repool.async_pool import AsyncConnectionPool
p = AsyncConnectionPool(dict(), pool_size=1)
......@@ -76,7 +76,7 @@ class TestPool(asynctest.TestCase):
class TestComplexPool(asynctest.TestCase):
@asynctest.patch('rethinkdb.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
@asynctest.patch('async_repool.async_pool.R.connect', new_callable=asynctest.CoroutineMock, return_value=ConnectionMock())
async def test_pool_overlap_with_wait(self, mocked_connect):
from async_repool.async_pool import AsyncConnectionPool
p = AsyncConnectionPool(dict(), pool_size=1)
......