Skip to content

Commit 88e1088

Browse files
authored
migrate to uv (#9)
1 parent 0eb97b5 commit 88e1088

File tree

7 files changed

+835
-1547
lines changed

7 files changed

+835
-1547
lines changed

.github/workflows/main.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ jobs:
2121
with:
2222
python-version: "3.12"
2323
- run: |
24-
pip install -U pip poetry
25-
poetry install --sync --no-root
26-
poetry run ruff format . --check
27-
poetry run ruff check . --no-fix
28-
poetry run mypy .
24+
curl -LsSf https://astral.sh/uv/install.sh | sh
25+
uv sync --all-extras --frozen --no-install-project
26+
uv run ruff format . --check
27+
uv run ruff check . --no-fix
28+
uv run mypy .
2929
3030
pytest:
3131
runs-on: ubuntu-latest
@@ -50,10 +50,10 @@ jobs:
5050
with:
5151
python-version: "3.12"
5252
- run: |
53-
pip install -U pip poetry
54-
poetry install --sync --no-root
55-
poetry run alembic upgrade head
56-
poetry run pytest
53+
curl -LsSf https://astral.sh/uv/install.sh | sh
54+
uv sync --all-extras --frozen --no-install-project
55+
uv run alembic upgrade head
56+
uv run pytest
5757
env:
5858
ENVIRONMENT: dev
5959
PYTHONDONTWRITEBYTECODE: 1

Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
ARG ENVIRONMENT="prod"
21
FROM python:3.12-slim
32

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

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

15-
ENV POETRY_VIRTUALENVS_CREATE=false
14+
ENV UV_PYTHON_PREFERENCE=only-system
15+
ENV UV_NO_CACHE=true
1616

1717
WORKDIR /code
1818

1919
COPY pyproject.toml .
20-
COPY poetry.lock .
20+
COPY uv.lock .
2121

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

2424
COPY . .
2525

Taskfile.yml

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,33 @@ tasks:
1515
desc: "run pytest (pass args after '--')"
1616
cmds:
1717
- task: down
18-
- docker compose run application sh -c "sleep 1 && alembic downgrade base && alembic upgrade head && pytest {{.CLI_ARGS}}"
18+
- docker compose run application sh -c "sleep 1 && uv run alembic downgrade base && uv run alembic upgrade head && uv run pytest {{.CLI_ARGS}}"
1919
- task: down
2020

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

2727
build:
2828
desc: "build app docker container"
2929
cmds:
3030
- docker compose build application
3131

32+
lock:
33+
desc: lock with update
34+
cmds:
35+
- uv lock --upgrade
36+
3237
install:
3338
desc: "install local dependencies"
3439
cmds:
35-
- poetry install --sync --no-root
40+
- uv sync --all-extras --no-install-project --frozen
3641

3742
lint:
3843
desc: "run linters"
3944
cmds:
40-
- poetry run ruff format .
41-
- poetry run ruff check . --fix
42-
- poetry run mypy .
45+
- uv run ruff format .
46+
- uv run ruff check . --fix
47+
- uv run mypy .

docker-compose.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
restart: always
99
volumes:
1010
- .:/code
11+
- /code/.venv
1112
ports:
1213
- "8000:8000"
1314
depends_on:
@@ -17,7 +18,7 @@ services:
1718
- DEBUG=true
1819
- DB_ECHO=true
1920
command:
20-
["python", "-m", "app"]
21+
["uv", "run", "python", "-m", "app"]
2122

2223
db:
2324
image: postgres:14

poetry.lock

-1,501
This file was deleted.

pyproject.toml

+32-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
1-
[tool.poetry]
1+
[project]
22
name = "litestar-sqlalchemy-template"
33
version = "0"
44
description = "Async template on LiteStar and SQLAlchemy 2"
5-
authors = ["Artur Shiriev <[email protected]>"]
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
authors = [
8+
{ email = "[email protected]" },
9+
{ name = "Artur Shiriev"}
10+
]
611
license = "MIT License"
12+
dependencies = [
13+
"litestar",
14+
"advanced-alchemy",
15+
"pydantic-settings",
16+
"granian",
17+
"that-depends",
18+
# database
19+
"alembic",
20+
"psycopg2",
21+
"sqlalchemy",
22+
"asyncpg",
23+
]
724

8-
9-
[tool.poetry.dependencies]
10-
python = "3.12.*"
11-
litestar = "*"
12-
advanced-alchemy = "*"
13-
pydantic-settings = "*"
14-
granian = "*"
15-
that-depends = "*"
16-
# database
17-
alembic = "*"
18-
psycopg2 = "*"
19-
sqlalchemy = "*"
20-
asyncpg = "*"
21-
22-
[tool.poetry.group.dev.dependencies]
23-
polyfactory = "*"
24-
httpx = "*"
25-
pytest = "*"
26-
pytest-cov = "*"
27-
pytest-asyncio = "*"
28-
ruff = "*"
29-
mypy = "*"
30-
asyncpg-stubs = "*"
25+
[project.optional-dependencies]
26+
test = [
27+
"polyfactory",
28+
"httpx",
29+
"pytest",
30+
"pytest-cov",
31+
"pytest-asyncio",
32+
]
33+
lint = [
34+
"ruff",
35+
"mypy",
36+
"asyncpg-stubs",
37+
]
3138

3239
[tool.ruff]
3340
fix = true

0 commit comments

Comments
 (0)