Skip to content

Commit dc8c020

Browse files
authored
Switch to Litestar and add UV along the way (#115)
* Switch to Litestar and add UV along the way Signed-off-by: GitHub <[email protected]> * Bump CI Signed-off-by: GitHub <[email protected]> * Fix up container Signed-off-by: GitHub <[email protected]> * Fixup lints Signed-off-by: GitHub <[email protected]> * Fixup tests Signed-off-by: GitHub <[email protected]> * Revert to 3.12 because msgspec Signed-off-by: GitHub <[email protected]> * Enable all OpenAPI render plugins Signed-off-by: GitHub <[email protected]> --------- Signed-off-by: GitHub <[email protected]>
1 parent 091bc78 commit dc8c020

30 files changed

+2616
-614
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: "Container Build and Push"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- v*
9+
pull_request:
10+
11+
permissions:
12+
contents: read
13+
packages: write
14+
# Used by actions/attest-build-provenance
15+
id-token: write
16+
attestations: write
17+
18+
jobs:
19+
build-push:
20+
uses: darbiadev/.github/.github/workflows/container-build-push.yaml@41518576ed6c499ed3e68d5cbceaeaa50abd471a # v14.1.0
21+
with:
22+
file-name: Dockerfile

.github/workflows/docker-build-push.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/python-ci.yaml

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Python CI"
1+
name: Python CI
22

33
on:
44
push:
@@ -7,24 +7,46 @@ on:
77
pull_request:
88

99
jobs:
10-
pre-commit:
11-
uses: darbiadev/.github/.github/workflows/generic-precommit.yaml@29197a38ef3741064f47b623ede0c1ad22402c57 # v13.0.3
10+
lint-test:
11+
runs-on: ubuntu-latest
1212

13-
lint:
14-
needs: pre-commit
15-
uses: darbiadev/.github/.github/workflows/python-lint.yaml@29197a38ef3741064f47b623ede0c1ad22402c57 # v13.0.3
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1616

17-
test:
18-
needs: lint
19-
strategy:
20-
matrix:
21-
os: [ ubuntu-latest ]
22-
python-version: [ "3.11" ]
17+
- name: Setup Python
18+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
19+
with:
20+
python-version: 3.12
21+
allow-prereleases: true
22+
cache: pip
23+
cache-dependency-path: uv.lock
2324

24-
uses: darbiadev/.github/.github/workflows/python-test.yaml@29197a38ef3741064f47b623ede0c1ad22402c57 # v13.0.3
25-
with:
26-
os: ${{ matrix.os }}
27-
python-version: ${{ matrix.python-version }}
25+
- name: Set up uv
26+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
27+
28+
- name: Sync dependencies
29+
run: uv sync --group dev --group tests
30+
31+
- name: Run pre-commit
32+
run: uv run pre-commit run --all-files
33+
34+
- name: Check formatting
35+
run: uv run ruff format --check .
36+
37+
- name: Run Ruff checks
38+
run: uv run ruff check --output-format=github .
39+
40+
- name: Run mypy
41+
run: uv run mypy --strict src/
42+
43+
- name: Run tests
44+
run: uv run python -m coverage run -m pytest -v
45+
46+
- name: Upload coverage reports to Codecov
47+
uses: codecov/codecov-action@d168679d447a7d9f9917d4b26caf2cfbf080cfb4 # v5.0.6
48+
env:
49+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2850

2951
docs:
3052
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
@@ -33,4 +55,4 @@ jobs:
3355
pages: write
3456
id-token: write
3557

36-
uses: darbiadev/.github/.github/workflows/github-pages-python-sphinx.yaml@29197a38ef3741064f47b623ede0c1ad22402c57 # v13.0.3
58+
uses: darbiadev/.github/.github/workflows/github-pages-python-sphinx.yaml@41518576ed6c499ed3e68d5cbceaeaa50abd471a # v14.1.0

.pre-commit-config.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-case-conflict
66
- id: check-merge-conflict
@@ -12,3 +12,23 @@ repos:
1212
- id: mixed-line-ending
1313
args: [ --fix=lf ]
1414
- id: end-of-file-fixer
15+
exclude: .devcontainer/devcontainer-lock.json
16+
17+
- repo: https://github.com/astral-sh/uv-pre-commit
18+
rev: 0.5.4
19+
hooks:
20+
- id: uv-lock
21+
- id: uv-export
22+
args:
23+
- --frozen
24+
- --no-emit-project
25+
- --output-file=requirements.txt
26+
files: pyproject.toml|uv.lock
27+
- id: uv-export
28+
args:
29+
- --frozen
30+
- --no-emit-project
31+
- --all-extras
32+
- --all-groups
33+
- --output-file=requirements-dependabot.txt
34+
files: pyproject.toml|uv.lock

Containerfile renamed to Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ FROM python:3.12-slim@sha256:43a49c9cc2e614468e3d1a903aabe17a97a4c788c76cf5337b5
44
ARG git_sha="development"
55
ENV GIT_SHA=$git_sha
66

7-
WORKDIR /home/api
8-
9-
COPY requirements/requirements.txt .
7+
COPY requirements.txt requirements.txt
108
RUN python -m pip install --requirement requirements.txt
119

12-
COPY pyproject.toml pyproject.toml
10+
COPY pyproject.toml README.md ./
1311
COPY src/ src/
14-
RUN python -m pip install .
12+
RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir .
1513

1614
RUN adduser --disabled-password api
1715
USER api
1816

1917
# HTTP
2018
EXPOSE 8080
2119

22-
CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "8080"]
20+
ENTRYPOINT ["gunicorn", "--bind", "0.0.0.0:8080", "--workers", "4", "--worker-class", "uvicorn.workers.UvicornWorker", "api.server:app"]

docs/source/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def linkcode_resolve(domain: str, info: dict) -> str:
6060
if not info["module"]:
6161
return None
6262

63-
import importlib # noqa: PLC0415
64-
import inspect # noqa: PLC0415
65-
import types # noqa: PLC0415
63+
import importlib
64+
import inspect
65+
import types
6666

6767
mod = importlib.import_module(info["module"])
6868

make.ps1

Lines changed: 0 additions & 126 deletions
This file was deleted.

noxfile.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""Noxfile."""
2+
3+
import shutil
4+
from pathlib import Path
5+
6+
import nox
7+
8+
nox.options.default_venv_backend = "none"
9+
nox.options.sessions = ["lints"]
10+
11+
12+
CLEANABLE_TARGETS = [
13+
"./dist",
14+
"./build",
15+
"./.nox",
16+
"./.coverage",
17+
"./.coverage.*",
18+
"./coverage.json",
19+
"./**/.mypy_cache",
20+
"./**/.pytest_cache",
21+
"./**/__pycache__",
22+
"./**/*.pyc",
23+
"./**/*.pyo",
24+
]
25+
26+
27+
@nox.session
28+
def tests(session: nox.Session) -> None:
29+
"""Run tests."""
30+
session.run("pytest")
31+
32+
33+
@nox.session
34+
def lints(session: nox.Session) -> None:
35+
"""Run lints."""
36+
session.run("pre-commit", "run", "--all-files")
37+
session.run("ruff", "format", ".")
38+
session.run("ruff", "check", "--fix", ".")
39+
session.run("mypy", "--strict", "src/")
40+
41+
42+
@nox.session
43+
def clean(_: nox.Session) -> None:
44+
"""Clean cache, .pyc, .pyo, and test/build artifact files from project."""
45+
count = 0
46+
for searchpath in CLEANABLE_TARGETS:
47+
for filepath in Path().glob(searchpath):
48+
if filepath.is_dir():
49+
shutil.rmtree(filepath)
50+
else:
51+
filepath.unlink()
52+
count += 1

0 commit comments

Comments
 (0)