From ba525ef7f49123de71df012ceeda1203bed9b288 Mon Sep 17 00:00:00 2001 From: Martijn Pieters Date: Sat, 30 Oct 2021 18:12:30 +0100 Subject: [PATCH] Drop support for Python 3.6 Closes #62 --- .azure-pipelines/ci.yml | 1 - .azure-pipelines/deploy.yml | 2 -- README.md | 4 ++-- changelog.d/62.removal | 1 + docs/index.rst | 4 ++-- pyproject.toml | 2 +- src/aiolimiter/__init__.py | 2 +- src/aiolimiter/compat.py | 13 ------------- src/aiolimiter/leakybucket.py | 11 ++++++----- tox.ini | 2 +- 10 files changed, 14 insertions(+), 28 deletions(-) create mode 100644 changelog.d/62.removal diff --git a/.azure-pipelines/ci.yml b/.azure-pipelines/ci.yml index a1a72f0..a36bac0 100644 --- a/.azure-pipelines/ci.yml +++ b/.azure-pipelines/ci.yml @@ -20,7 +20,6 @@ stages: - template: stage-test.yml parameters: pythonVersions: - - "3.6" - "3.7" - "3.8" - "3.9" diff --git a/.azure-pipelines/deploy.yml b/.azure-pipelines/deploy.yml index 06d6577..061a636 100644 --- a/.azure-pipelines/deploy.yml +++ b/.azure-pipelines/deploy.yml @@ -14,7 +14,6 @@ stages: - template: stage-test.yml parameters: pythonVersions: - - "3.6" - "3.7" - "3.8" - "3.9" @@ -22,7 +21,6 @@ stages: - template: stage-deploy.yml parameters: pythonVersions: - - "3.6" - "3.7" - "3.8" - "3.9" diff --git a/README.md b/README.md index 1c82325..5b93910 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,11 @@ https://aiolimiter.readthedocs.io $ pip install aiolimiter ``` -The library requires Python 3.6 or newer. +The library requires Python 3.7 or newer. ## Requirements -- Python >= 3.6 +- Python >= 3.7 ## License diff --git a/changelog.d/62.removal b/changelog.d/62.removal new file mode 100644 index 0000000..1a1c53e --- /dev/null +++ b/changelog.d/62.removal @@ -0,0 +1 @@ +Dropped support for Python 3.6 diff --git a/docs/index.rst b/docs/index.rst index 41f69d7..764fa0d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -19,12 +19,12 @@ Installation $ pip install aiolimiter -The library requires Python 3.6 or newer. +The library requires Python 3.7 or newer. Requirements ------------ -- Python >= 3.6 +- Python >= 3.7 Usage diff --git a/pyproject.toml b/pyproject.toml index 56931dd..2db24b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ include = ["CHANGELOG.md"] "GitHub: issues" = "https://github.com/mjpieters/aiolimiter/issues" [tool.poetry.dependencies] -python = "^3.6.1" +python = "^3.7" importlib_metadata = { version = ">=1.3,<5.0", python = "< 3.8" } sphinx = {version = ">=4.2.0,<5.0.0", optional = true} aiohttp-theme = {version = "^0.1.6", optional = true} diff --git a/src/aiolimiter/__init__.py b/src/aiolimiter/__init__.py index 8f3bbe8..567d3f7 100644 --- a/src/aiolimiter/__init__.py +++ b/src/aiolimiter/__init__.py @@ -6,7 +6,7 @@ # Python 3.8+ from importlib.metadata import version # type: ignore except ImportError: - # Python 3.6, 3.7 + # Python 3.7 from importlib_metadata import version # type: ignore from .leakybucket import AsyncLimiter diff --git a/src/aiolimiter/compat.py b/src/aiolimiter/compat.py index 1e8ff41..b61084c 100644 --- a/src/aiolimiter/compat.py +++ b/src/aiolimiter/compat.py @@ -4,21 +4,8 @@ # compatibility across Python versions import asyncio -import contextlib import sys -try: - # Python 3.7 or newer - AsyncContextManagerBase = contextlib.AbstractAsyncContextManager - current_task = asyncio.current_task - get_running_loop = asyncio.get_running_loop -except AttributeError: # pragma: no cover - # Python 3.6 - AsyncContextManagerBase = object # type: ignore - current_task = asyncio.Task.current_task - get_running_loop = asyncio.get_event_loop - - if sys.version_info < (3, 8): # pragma: no cover wait_for = asyncio.wait_for else: diff --git a/src/aiolimiter/leakybucket.py b/src/aiolimiter/leakybucket.py index 8b946c9..4d41bec 100644 --- a/src/aiolimiter/leakybucket.py +++ b/src/aiolimiter/leakybucket.py @@ -3,13 +3,14 @@ # Licensed under the MIT license as detailed in LICENSE.txt import asyncio +from contextlib import AbstractAsyncContextManager from types import TracebackType from typing import Dict, Optional, Type -from .compat import AsyncContextManagerBase, current_task, get_running_loop, wait_for +from .compat import wait_for -class AsyncLimiter(AsyncContextManagerBase): +class AsyncLimiter(AbstractAsyncContextManager): """A leaky bucket rate limiter. This is an :ref:`asynchronous context manager `; @@ -43,7 +44,7 @@ def __init__(self, max_rate: float, time_period: float = 60) -> None: def _leak(self) -> None: """Drip out capacity from the bucket.""" - loop = get_running_loop() + loop = asyncio.get_running_loop() if self._level: # drip out enough level for the elapsed time since # we last checked @@ -84,8 +85,8 @@ async def acquire(self, amount: float = 1) -> None: if amount > self.max_rate: raise ValueError("Can't acquire more than the maximum capacity") - loop = get_running_loop() - task = current_task(loop) + loop = asyncio.get_running_loop() + task = asyncio.current_task(loop) assert task is not None while not self.has_capacity(amount): # wait for the next drip to have left the bucket diff --git a/tox.ini b/tox.ini index 3050f46..e0d7e3c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] skipsdist = True -envlist = py36, py37, py38, py39, py310, pypy3 +envlist = py37, py38, py39, py310, pypy3 [testenv] whitelist_externals = poetry