From 36c19dda2bb3c89a85b9dbcf908a5ca78509bed6 Mon Sep 17 00:00:00 2001 From: Jesse Saran <8915311+swrap@users.noreply.github.com> Date: Tue, 22 Jul 2025 10:53:17 -0400 Subject: [PATCH 1/2] Create python-package.yml --- .github/workflows/python-package.yml | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..ebd8741 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -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 + ruff check . + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + ruff format --check . + + - name: Test with pytest + run: | + pytest From 5c2e062e2ce6e65e8ffba8440e1f1815811bb346 Mon Sep 17 00:00:00 2001 From: Jesse Saran <8915311+swrap@users.noreply.github.com> Date: Tue, 22 Jul 2025 11:00:10 -0400 Subject: [PATCH 2/2] Lint fixed. - Fixed linting issues --- .../workflows/{python-package.yml => python-checks.yml} | 6 +++--- pyproject.toml | 8 +++++++- src/aioadaptive/client/__init__.py | 2 ++ src/aioadaptive/client/_adaptive_client.py | 1 + src/aioadaptive/limiter/__init__.py | 2 ++ src/aioadaptive/limiter/_vegas.py | 7 +++++-- tests/__init__.py | 1 - tests/client/test_adaptive_client.py | 5 ++--- 8 files changed, 22 insertions(+), 10 deletions(-) rename .github/workflows/{python-package.yml => python-checks.yml} (92%) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-checks.yml similarity index 92% rename from .github/workflows/python-package.yml rename to .github/workflows/python-checks.yml index ebd8741..955f625 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-checks.yml @@ -36,10 +36,10 @@ jobs: - name: Ruff Linting run: | # stop the build if there are Python syntax errors or undefined names - ruff check . + uv run ruff check . # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - ruff format --check . + uv run ruff format --check . - name: Test with pytest run: | - pytest + uv run pytest diff --git a/pyproject.toml b/pyproject.toml index 20e55e9..a3684b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 @@ -47,10 +52,11 @@ fixable = ["ALL"] "D101", "D102", "D103", # Checks for undocumented public function definitions + "D104", "ANN001", "ANN101", "ANN201", "TRY002", "TRY003", - "EM001", + "EM101", ] diff --git a/src/aioadaptive/client/__init__.py b/src/aioadaptive/client/__init__.py index 84bc30b..82255d0 100644 --- a/src/aioadaptive/client/__init__.py +++ b/src/aioadaptive/client/__init__.py @@ -1,3 +1,5 @@ +"""Clients for adaptive rate limiting.""" + from aioadaptive.client._adaptive_client import AdaptiveClient, AdaptiveClientConfig __all__ = ["AdaptiveClient", "AdaptiveClientConfig"] diff --git a/src/aioadaptive/client/_adaptive_client.py b/src/aioadaptive/client/_adaptive_client.py index 72b27d3..f98496f 100644 --- a/src/aioadaptive/client/_adaptive_client.py +++ b/src/aioadaptive/client/_adaptive_client.py @@ -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() diff --git a/src/aioadaptive/limiter/__init__.py b/src/aioadaptive/limiter/__init__.py index 6426f6a..93f9919 100644 --- a/src/aioadaptive/limiter/__init__.py +++ b/src/aioadaptive/limiter/__init__.py @@ -1,3 +1,5 @@ +"""Limiters for adaptive rate limiting.""" + from aioadaptive.limiter._limiter import AbstractLimiter from aioadaptive.limiter._vegas import VegasLimiter diff --git a/src/aioadaptive/limiter/_vegas.py b/src/aioadaptive/limiter/_vegas.py index ace15bf..acf1b48 100644 --- a/src/aioadaptive/limiter/_vegas.py +++ b/src/aioadaptive/limiter/_vegas.py @@ -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 diff --git a/tests/__init__.py b/tests/__init__.py index ae0efef..e69de29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +0,0 @@ -# Tests package for aioadaptive diff --git a/tests/client/test_adaptive_client.py b/tests/client/test_adaptive_client.py index ae8a868..eec6e13 100644 --- a/tests/client/test_adaptive_client.py +++ b/tests/client/test_adaptive_client.py @@ -2,6 +2,7 @@ from unittest.mock import Mock, call, patch import pytest + from aioadaptive import AdaptiveClient, AdaptiveClientConfig from aioadaptive.limiter._limiter import AbstractLimiter @@ -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")