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
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
with:
python-version: "3.12"
- run: |
pip install -U pip poetry
poetry install --sync --no-root
poetry run ruff format . --check
poetry run ruff check . --no-fix
poetry run mypy .
curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync --all-extras --frozen --no-install-project
uv run ruff format . --check
uv run ruff check . --no-fix
uv run mypy .

pytest:
runs-on: ubuntu-latest
Expand All @@ -50,10 +50,10 @@ jobs:
with:
python-version: "3.12"
- run: |
pip install -U pip poetry
poetry install --sync --no-root
poetry run alembic upgrade head
poetry run pytest
curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync --all-extras --frozen --no-install-project
uv run alembic upgrade head
uv run pytest
env:
ENVIRONMENT: dev
PYTHONDONTWRITEBYTECODE: 1
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ARG ENVIRONMENT="prod"
FROM python:3.12-slim

# required for psycopg2
Expand All @@ -9,17 +8,18 @@ RUN apt update \
&& apt clean \
&& rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir --upgrade pip poetry
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
RUN useradd --no-create-home --gid root runner

ENV POETRY_VIRTUALENVS_CREATE=false
ENV UV_PYTHON_PREFERENCE=only-system
ENV UV_NO_CACHE=true

WORKDIR /code

COPY pyproject.toml .
COPY poetry.lock .
COPY uv.lock .

RUN [ "$ENVIRONMENT" = "prod" ] && poetry install --no-dev || poetry install
RUN uv sync --all-extras --frozen --no-install-project

COPY . .

Expand Down
17 changes: 11 additions & 6 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,33 @@ tasks:
desc: "run pytest (pass args after '--')"
cmds:
- task: down
- docker compose run application sh -c "sleep 1 && alembic downgrade base && alembic upgrade head && pytest {{.CLI_ARGS}}"
- docker compose run application sh -c "sleep 1 && uv run alembic downgrade base && uv run alembic upgrade head && uv run pytest {{.CLI_ARGS}}"
- task: down

migration:
desc: "create alembic migration (pass args after '--')"
cmds:
- docker compose run application sh -c "sleep 1 && alembic upgrade head && alembic revision --autogenerate {{.CLI_ARGS}}"
- docker compose run application sh -c "sleep 1 && uv run alembic upgrade head && uv run alembic revision --autogenerate {{.CLI_ARGS}}"
- task: down

build:
desc: "build app docker container"
cmds:
- docker compose build application

lock:
desc: lock with update
cmds:
- uv lock --upgrade

install:
desc: "install local dependencies"
cmds:
- poetry install --sync --no-root
- uv sync --all-extras --no-install-project --frozen

lint:
desc: "run linters"
cmds:
- poetry run ruff format .
- poetry run ruff check . --fix
- poetry run mypy .
- uv run ruff format .
- uv run ruff check . --fix
- uv run mypy .
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
restart: always
volumes:
- .:/code
- /code/.venv
ports:
- "8000:8000"
depends_on:
Expand All @@ -17,7 +18,7 @@ services:
- DEBUG=true
- DB_ECHO=true
command:
["python", "-m", "app"]
["uv", "run", "python", "-m", "app"]

db:
image: postgres:14
Expand Down
1,194 changes: 0 additions & 1,194 deletions poetry.lock

This file was deleted.

57 changes: 32 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
[tool.poetry]
[project]
name = "fast-api-sqlalchemy-template"
version = "0"
description = "Async template on FastAPI and SQLAlchemy 2"
authors = ["Artur Shiriev <[email protected]>"]
readme = "README.md"
requires-python = ">=3.12"
authors = [
{ email = "[email protected]" },
{ name = "Artur Shiriev"}
]
license = "MIT License"
dependencies = [
"fastapi>=0.76",
"advanced-alchemy",
"pydantic-settings",
"granian",
"that-depends",
# database
"alembic",
"psycopg2",
"sqlalchemy",
"asyncpg",
]


[tool.poetry.dependencies]
python = "3.12.*"
fastapi = ">=0.76"
advanced-alchemy = "*"
pydantic-settings = "*"
granian = "*"
that-depends = "*"
# database
alembic = "*"
psycopg2 = "*"
sqlalchemy = "*"
asyncpg = "*"

[tool.poetry.group.dev.dependencies]
polyfactory = "*"
httpx = "*"
pytest = "*"
pytest-cov = "*"
pytest-asyncio = "*"
ruff = "*"
mypy = "*"
asyncpg-stubs = "*"
[project.optional-dependencies]
test = [
"polyfactory",
"httpx",
"pytest",
"pytest-cov",
"pytest-asyncio",
]
lint = [
"ruff",
"mypy",
"asyncpg-stubs",
]

[tool.ruff]
fix = true
Expand Down
Loading
Loading