Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/python-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.13"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install uv and setup the python version
uses: astral-sh/setup-uv@v6
with:
version: "~0.8.0"

- name: Install the project
run: uv sync --all-groups

- name: Ruff Linting
run: |
# stop the build if there are Python syntax errors or undefined names
uv run ruff check .
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
uv run ruff format --check .

- name: Test with pytest
run: |
uv run pytest
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ select = ["ALL"]
fixable = ["ALL"]

[tool.ruff.lint.per-file-ignores]
"**/*.py" = [
"TD002",
"FIX002",
]
"__init__.py" = ["E402"]
"**/{tests}/*" = [
"ARG001", # Unused function argument
"ARG002",
"E722", # Do not use bare except
"INP001", # File is part of an implicit namespace package
"PLR2004", # Magic value used in comparison
Expand All @@ -47,10 +52,11 @@ fixable = ["ALL"]
"D101",
"D102",
"D103", # Checks for undocumented public function definitions
"D104",
"ANN001",
"ANN101",
"ANN201",
"TRY002",
"TRY003",
"EM001",
"EM101",
]
2 changes: 2 additions & 0 deletions src/aioadaptive/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Clients for adaptive rate limiting."""

from aioadaptive.client._adaptive_client import AdaptiveClient, AdaptiveClientConfig

__all__ = ["AdaptiveClient", "AdaptiveClientConfig"]
1 change: 1 addition & 0 deletions src/aioadaptive/client/_adaptive_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async def use(self: Self) -> AsyncGenerator[Self, None]:

Yields:
AsyncGenerator[Self, None]: The client instance.

"""
async with self._capacity_limiter:
start = time.time()
Expand Down
2 changes: 2 additions & 0 deletions src/aioadaptive/limiter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Limiters for adaptive rate limiting."""

from aioadaptive.limiter._limiter import AbstractLimiter
from aioadaptive.limiter._vegas import VegasLimiter

Expand Down
7 changes: 5 additions & 2 deletions src/aioadaptive/limiter/_vegas.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ def update(self: Self, round_trip_time: float) -> int:
# https://github.com/Netflix/concurrency-limits/blob/main/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limit/VegasLimit.java#L39-L40
self._alpha = max(ALPHA, self._limit * 0.1)
self._beta = max(BETA, self._limit * 0.2)
logger.debug(
f"RTT: {round_trip_time}ms, Queue Size: {queue_size}, Limit: {self._limit}, Queue Low: {self._alpha}, Queue High: {self._beta}",

debug_msg = (
f"RTT: {round_trip_time}ms, Queue Size: {queue_size}, "
f"Limit: {self._limit}, Queue Low: {self._alpha}, Queue High: {self._beta}"
)
logger.debug(debug_msg)

# TODO: Future work is to update estimator: https://github.com/Netflix/concurrency-limits/blob/main/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limit/VegasLimit.java#L279-L321

Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# Tests package for aioadaptive
5 changes: 2 additions & 3 deletions tests/client/test_adaptive_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import Mock, call, patch

import pytest

from aioadaptive import AdaptiveClient, AdaptiveClientConfig
from aioadaptive.limiter._limiter import AbstractLimiter

Expand Down Expand Up @@ -45,9 +46,7 @@ async def test_use_context_manager_limit_update(self: Self, client, limiter_mock
]
assert client._capacity_limiter.total_tokens == 2

async def test_use_context_manager_limit_exception(
self: Self, client, limiter_mock
):
async def test_use_context_manager_limit_exception(self: Self, client, limiter_mock):
with pytest.raises(Exception, match="test exception"):
async with client.use():
raise Exception("test exception")
Expand Down