Skip to content

Commit 8104827

Browse files
authored
⬆️ Migrate from Poetry to uv (#1356)
1 parent fa97b37 commit 8104827

File tree

7 files changed

+1619
-2258
lines changed

7 files changed

+1619
-2258
lines changed

backend/Dockerfile

+23-9
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@ FROM python:3.10
22

33
WORKDIR /app/
44

5-
# Install Poetry
6-
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
7-
cd /usr/local/bin && \
8-
ln -s /opt/poetry/bin/poetry && \
9-
poetry config virtualenvs.create false
5+
# Install uv
6+
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
7+
COPY --from=ghcr.io/astral-sh/uv:0.4.15 /uv /bin/uv
108

11-
# Copy poetry.lock* in case it doesn't exist in the repo
12-
COPY ./pyproject.toml ./poetry.lock* /app/
9+
# Place executables in the environment at the front of the path
10+
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment
11+
ENV PATH="/app/.venv/bin:$PATH"
1312

14-
RUN poetry install --no-root
13+
# Compile bytecode
14+
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
15+
ENV UV_COMPILE_BYTECODE=1
16+
17+
# uv Cache
18+
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#caching
19+
ENV UV_LINK_MODE=copy
20+
21+
# Install dependencies
22+
RUN --mount=type=cache,target=/root/.cache/uv \
23+
--mount=type=bind,source=uv.lock,target=uv.lock \
24+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
25+
uv sync --frozen --no-install-project
1526

1627
ENV PYTHONPATH=/app
1728

1829
COPY ./scripts /app/scripts
1930

20-
COPY ./alembic.ini /app/
31+
COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/
2132

2233
COPY ./app /app/app
2334

35+
RUN --mount=type=cache,target=/root/.cache/uv \
36+
uv sync
37+
2438
CMD ["fastapi", "run", "--workers", "4", "app/main.py"]

backend/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
## Requirements
44

55
* [Docker](https://www.docker.com/).
6-
* [Poetry](https://python-poetry.org/) for Python package and environment management.
6+
* [uv](https://docs.astral.sh/uv/) for Python package and environment management.
77

88
## Docker Compose
99

1010
Start the local development environment with Docker Compose following the guide in [../development.md](../development.md).
1111

1212
## General Workflow
1313

14-
By default, the dependencies are managed with [Poetry](https://python-poetry.org/), go there and install it.
14+
By default, the dependencies are managed with [uv](https://docs.astral.sh/uv/), go there and install it.
1515

1616
From `./backend/` you can install all the dependencies with:
1717

1818
```console
19-
$ poetry install
19+
$ uv sync
2020
```
2121

22-
Then you can start a shell session with the new environment with:
22+
Then you can activate the virtual environment with:
2323

2424
```console
25-
$ poetry shell
25+
$ source .venv/bin/activate
2626
```
2727

28-
Make sure your editor is using the correct Python virtual environment.
28+
Make sure your editor is using the correct Python virtual environment, with the interpreter at `backend/.venv/bin/python`.
2929

3030
Modify or add SQLModel models for data and SQL tables in `./backend/app/models.py`, API endpoints in `./backend/app/api/`, CRUD (Create, Read, Update, Delete) utils in `./backend/app/crud.py`.
3131

backend/poetry.lock

-2,204
This file was deleted.

backend/pyproject.toml

+32-33
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1-
[tool.poetry]
1+
[project]
22
name = "app"
33
version = "0.1.0"
44
description = ""
5-
authors = ["Admin <[email protected]>"]
6-
7-
[tool.poetry.dependencies]
8-
python = "^3.10"
9-
fastapi = {extras = ["standard"], version = "^0.114.2"}
10-
python-multipart = "^0.0.7"
11-
email-validator = "^2.1.0.post1"
12-
passlib = {extras = ["bcrypt"], version = "^1.7.4"}
13-
tenacity = "^8.2.3"
14-
pydantic = ">2.0"
15-
emails = "^0.6"
16-
17-
gunicorn = "^22.0.0"
18-
jinja2 = "^3.1.4"
19-
alembic = "^1.12.1"
20-
httpx = "^0.25.1"
21-
psycopg = {extras = ["binary"], version = "^3.1.13"}
22-
sqlmodel = "^0.0.21"
23-
# Pin bcrypt until passlib supports the latest
24-
bcrypt = "4.0.1"
25-
pydantic-settings = "^2.2.1"
26-
sentry-sdk = {extras = ["fastapi"], version = "^1.40.6"}
27-
pyjwt = "^2.8.0"
5+
requires-python = ">=3.10,<4.0"
6+
dependencies = [
7+
"fastapi[standard]<1.0.0,>=0.114.2",
8+
"python-multipart<1.0.0,>=0.0.7",
9+
"email-validator<3.0.0.0,>=2.1.0.post1",
10+
"passlib[bcrypt]<2.0.0,>=1.7.4",
11+
"tenacity<9.0.0,>=8.2.3",
12+
"pydantic>2.0",
13+
"emails<1.0,>=0.6",
14+
"jinja2<4.0.0,>=3.1.4",
15+
"alembic<2.0.0,>=1.12.1",
16+
"httpx<1.0.0,>=0.25.1",
17+
"psycopg[binary]<4.0.0,>=3.1.13",
18+
"sqlmodel<1.0.0,>=0.0.21",
19+
# Pin bcrypt until passlib supports the latest
20+
"bcrypt==4.0.1",
21+
"pydantic-settings<3.0.0,>=2.2.1",
22+
"sentry-sdk[fastapi]<2.0.0,>=1.40.6",
23+
"pyjwt<3.0.0,>=2.8.0",
24+
]
2825

29-
[tool.poetry.group.dev.dependencies]
30-
pytest = "^7.4.3"
31-
mypy = "^1.8.0"
32-
ruff = "^0.2.2"
33-
pre-commit = "^3.6.2"
34-
types-passlib = "^1.7.7.20240106"
35-
coverage = "^7.4.3"
26+
[tool.uv]
27+
dev-dependencies = [
28+
"pytest<8.0.0,>=7.4.3",
29+
"mypy<2.0.0,>=1.8.0",
30+
"ruff<1.0.0,>=0.2.2",
31+
"pre-commit<4.0.0,>=3.6.2",
32+
"types-passlib<2.0.0.0,>=1.7.7.20240106",
33+
"coverage<8.0.0,>=7.4.3",
34+
]
3635

3736
[build-system]
38-
requires = ["poetry>=0.12"]
39-
build-backend = "poetry.masonry.api"
37+
requires = ["hatchling"]
38+
build-backend = "hatchling.build"
4039

4140
[tool.mypy]
4241
strict = true

0 commit comments

Comments
 (0)