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
36 changes: 24 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: release
permissions:
id-token: write
env:
UV_SYSTEM_PYTHON: 1
steps:
- uses: actions/checkout@v2
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/checkout@v5
with:
python-version: "3.11"
- name: Install deps
run: poetry install
- name: Set version
run: poetry version "${{ github.ref_name }}"
persist-credentials: false
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v6
with:
python-version: '3.14'
- id: setup-uv
name: Setup UV
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-suffix: '3.14'
github-token: ${{ github.token }}
version: "3.14"
- run: uv build
- name: Release package
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: poetry publish --build
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: uv publish
74 changes: 43 additions & 31 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,69 @@
name: Testing package

on: push
on:
pull_request:

permissions:
actions: read
contents: read
pull-requests: read

jobs:
lint:
strategy:
matrix:
cmd:
- black
- mypy
- ruff
cmd: ["black", "ruff", "mypy"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/checkout@v5
with:
persist-credentials: false
fetch-depth: 0
- id: setup-uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.11"
cache: "poetry"
enable-cache: true
cache-suffix: 3.11
version: "latest"
python-version: 3.11
- name: Install deps
run: poetry install
run: uv sync --all-extras
- name: Run lint check
run: poetry run pre-commit run -a ${{ matrix.cmd }}
run: uv run pre-commit run -a ${{ matrix.cmd }}
pytest:
permissions:
checks: write
pull-requests: write
contents: write
strategy:
matrix:
py_version: ["3.9", "3.10", "3.11", "3.12"]
py_version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
runs-on: "ubuntu-latest"
env:
UV_SYSTEM_PYTHON: 1
steps:
- uses: actions/checkout@v2
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/checkout@v5
with:
persist-credentials: false
fetch-depth: 0
- name: Setup python
uses: actions/setup-python@v6
with:
python-version: "${{ matrix.py_version }}"
cache: "poetry"
- id: setup-uv
name: Setup UV
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-suffix: ${{ matrix.py_version }}
github-token: ${{ github.token }}
version: "latest"
- name: Install deps
run: poetry install
run: uv sync --all-extras --locked
- name: Run pytest check
run: poetry run pytest -vv -n auto --cov="aiohttp_deps" .
run: uv run pytest -vv -n auto --cov="aiohttp_deps" .
- name: Generate report
run: poetry run coverage xml
run: uv run coverage xml
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
if: matrix.py_version == '3.9'
uses: codecov/codecov-action@v5
if: matrix.os == 'ubuntu-latest' && matrix.py_version == '3.10'
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
41 changes: 28 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,57 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v6.0.0
hooks:
- id: check-ast
- id: trailing-whitespace
- id: check-toml
- id: end-of-file-fixer

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
rev: v4.0.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/crate-ci/typos
rev: v1.38.1
hooks:
- id: typos

- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
args: [
'--exclude-files', 'README.md',
'--exclude-files', 'tests/.*',
]

- repo: local
hooks:
- id: black
name: Format with Black
entry: poetry run black
language: system
types: [python]


- id: mypy
name: Validate types with MyPy
entry: poetry run mypy
entry: uv run black
language: system
types: [python]
pass_filenames: false
args: [aiohttp_deps]

- id: ruff
name: Run ruff lints
entry: poetry run ruff check
entry: uv run ruff
language: system
pass_filenames: false
types: [python]
args:
- "check"
- "--fix"
- "aiohttp_deps"
- "tests"

- id: mypy
name: Validate types with MyPy
entry: uv run mypy
language: system
pass_filenames: false
types: [python]
args:
- ./aiohttp_deps/
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# AioHTTP deps


This project was initially created to show the abillities of [taskiq-dependencies](https://github.com/taskiq-python/taskiq-dependencies) project, which is used by [taskiq](https://github.com/taskiq-python/taskiq) to provide you with the best experience of sending distributed tasks.
This project was initially created to show the abilities of [taskiq-dependencies](https://github.com/taskiq-python/taskiq-dependencies) project, which is used by [taskiq](https://github.com/taskiq-python/taskiq) to provide you with the best experience of sending distributed tasks.

This project adds [FastAPI](https://github.com/tiangolo/fastapi)-like dependency injection to your [AioHTTP](https://github.com/aio-libs/aiohttp) application and swagger documentation based on types.

Expand All @@ -26,7 +26,7 @@ web.run_app(app)
```


If you use mypy, then we have a custom router with propper types.
If you use mypy, then we have a custom router with proper types.


```python
Expand Down Expand Up @@ -123,7 +123,7 @@ async def handler() -> web.Response:

This example illustrates how much you can do with this decorator. You
can have multiple content-types for a single status, or you can have different
possble statuses. This function is pretty simple and if you want to make
possible statuses. This function is pretty simple and if you want to make
your own decorator for your responses, it won't be hard.


Expand Down Expand Up @@ -289,7 +289,7 @@ async def shop(item_id: str = Depends(Query())) -> web.Response:

the name of the parameter is the same as the name of function parameter.

The Query dependency is acually the same as the Header dependency, so everything about the `Header` dependency also applies to `Query`.
The Query dependency is actually the same as the Header dependency, so everything about the `Header` dependency also applies to `Query`.

## Views

Expand All @@ -312,7 +312,7 @@ class MyView(View):

## Forms

Now you can easiy get and validate form data from your request.
Now you can easily get and validate form data from your request.
To make the magic happen, please add `arbitrary_types_allowed` to the config of your model.


Expand Down Expand Up @@ -370,7 +370,7 @@ You can check how this thing can be used in our [examples/swagger_auth.py](https
Sometimes for tests you don't want to calculate actual functions
and you want to pass another functions instead.

To do so, you can add "dependency_overrides" or "values_overrides" to the aplication's state.
To do so, you can add "dependency_overrides" or "values_overrides" to the application's state.
These values should be dicts. The keys for these values can be found in `aiohttp_deps.keys` module.

Here's an example.
Expand All @@ -388,7 +388,7 @@ class MyView(View):
Imagine you have a handler that depends on some function,
but instead of `1` you want to have `2` in your tests.

To do it, jsut add `dependency_overrides` somewhere,
To do it, just add `dependency_overrides` somewhere,
where you create your application. And make sure that keys
of that dict are actual function that are being replaced.

Expand Down
22 changes: 11 additions & 11 deletions aiohttp_deps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
from aiohttp_deps.view import View

__all__ = [
"init",
"setup_swagger",
"extra_openapi",
"Header",
"DEPENDENCY_OVERRIDES_KEY",
"VALUES_OVERRIDES_KEY",
"Depends",
"Router",
"View",
"Json",
"Query",
"ExtraOpenAPI",
"Form",
"Header",
"Json",
"Path",
"ExtraOpenAPI",
"Query",
"Router",
"View",
"extra_openapi",
"init",
"openapi_response",
"DEPENDENCY_OVERRIDES_KEY",
"VALUES_OVERRIDES_KEY",
"setup_swagger",
]
4 changes: 2 additions & 2 deletions aiohttp_deps/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
_T = TypeVar("_T")

REF_TEMPLATE = "#/components/schemas/{model}"
SWAGGER_HTML_TEMPALTE = """
SWAGGER_HTML_TEMPLATE = """
<html lang="en">

<head>
Expand Down Expand Up @@ -333,7 +333,7 @@ async def event_handler(app: web.Application) -> None: # noqa: C901
app.router.add_get(
swagger_ui_url,
_get_swagger_handler(
SWAGGER_HTML_TEMPALTE.replace("{schema_url}", schema_url),
SWAGGER_HTML_TEMPLATE.replace("{schema_url}", schema_url),
),
)

Expand Down
2 changes: 1 addition & 1 deletion aiohttp_deps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,6 @@ def __call__(self) -> None:
"""
This method is called when dependency is resolved.

It's empty, becuase it's used only by the `setup_swagger` function and
It's empty, because it's used only by the `setup_swagger` function and
there is no actual dependency.
"""
2 changes: 1 addition & 1 deletion aiohttp_deps/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class View(web.View):
Custom View.

If you're going to use dependency injection
in handlers, please subclass this View instad of
in handlers, please subclass this View instead of
the default View from AioHTTP.
"""

Expand Down
Loading
Loading