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
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ concurrency:
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
with:
enable-cache: false
- name: Install lint tools
run: uv sync --python 3.11 --only-group lint
- name: Lint
run: uv run --no-sync ruff check --output-format=github .
- name: Check formatting
run: uv run --no-sync ruff format --check .

test:
name: Python ${{ matrix.python }}, ${{ matrix.bounds }} dependency bounds
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ __pycache__/
*.py[cod]
.venv/
.pytest_cache/
.ruff_cache/
.mypy_cache/
dist/
uv.lock
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.17.0
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,14 @@ Things to keep in mind:
## Development

```sh
uv sync --group test --group lint
uv run --group test pytest
uv run --group lint ruff check .
uv run --group lint ruff format --check .
uv run --group lint pre-commit install
uv run --group lint pre-commit run --all-files
```

Ruff checks imports, annotations and common Python errors, and formats the code.
CI runs the same Ruff version as the pre-commit hooks. Test endpoints that exercise the absence
of a response annotation intentionally omit it.
15 changes: 14 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "msgspec-fastapi"
version = "0.0.3"
version = "0.0.4"
description = "Experimental FastAPI router that decodes request bodies and encodes responses with msgspec"
readme = "README.md"
license = "BSD-3-Clause"
Expand All @@ -27,9 +27,22 @@ Issues = "https://github.com/Siyet/msgspec-fastapi/issues"

[dependency-groups]
test = ["pytest", "httpx", "httpx2", "python-multipart"]
lint = ["ruff==0.17.0", "pre-commit>=4.5,<5"]

[tool.hatch.build.targets.wheel]
packages = ["src/msgspec_fastapi"]

[tool.pytest.ini_options]
testpaths = ["tests"]

[tool.ruff]
target-version = "py311"
line-length = 100

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "I", "ANN"]
# Runtime type expressions, JSON values and forwarded FastAPI options are dynamic.
ignore = ["ANN401"]

[tool.ruff.format]
quote-style = "single"
Empty file added src/msgspec_fastapi/py.typed
Empty file.
3 changes: 3 additions & 0 deletions src/msgspec_fastapi/responses.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from typing import Any

import msgspec
from starlette.responses import JSONResponse

_JSON_ENCODER = msgspec.json.Encoder()


class MsgspecJSONResponse(JSONResponse):
"""Encode JSON with msgspec; use MsgspecRouter for output validation."""

def render(self, content: Any) -> bytes:
return _JSON_ENCODER.encode(content)
Loading
Loading