⬆️ Migrate from Poetry to uv (#1356)
This commit is contained in:

committed by
GitHub

parent
fa97b372b4
commit
81048277c7
@@ -2,23 +2,37 @@ FROM python:3.10
|
|||||||
|
|
||||||
WORKDIR /app/
|
WORKDIR /app/
|
||||||
|
|
||||||
# Install Poetry
|
# Install uv
|
||||||
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
|
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
|
||||||
cd /usr/local/bin && \
|
COPY --from=ghcr.io/astral-sh/uv:0.4.15 /uv /bin/uv
|
||||||
ln -s /opt/poetry/bin/poetry && \
|
|
||||||
poetry config virtualenvs.create false
|
|
||||||
|
|
||||||
# Copy poetry.lock* in case it doesn't exist in the repo
|
# Place executables in the environment at the front of the path
|
||||||
COPY ./pyproject.toml ./poetry.lock* /app/
|
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment
|
||||||
|
ENV PATH="/app/.venv/bin:$PATH"
|
||||||
|
|
||||||
RUN poetry install --no-root
|
# Compile bytecode
|
||||||
|
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
|
||||||
|
ENV UV_COMPILE_BYTECODE=1
|
||||||
|
|
||||||
|
# uv Cache
|
||||||
|
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#caching
|
||||||
|
ENV UV_LINK_MODE=copy
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
|
--mount=type=bind,source=uv.lock,target=uv.lock \
|
||||||
|
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
|
||||||
|
uv sync --frozen --no-install-project
|
||||||
|
|
||||||
ENV PYTHONPATH=/app
|
ENV PYTHONPATH=/app
|
||||||
|
|
||||||
COPY ./scripts /app/scripts
|
COPY ./scripts /app/scripts
|
||||||
|
|
||||||
COPY ./alembic.ini /app/
|
COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/
|
||||||
|
|
||||||
COPY ./app /app/app
|
COPY ./app /app/app
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||||
|
uv sync
|
||||||
|
|
||||||
CMD ["fastapi", "run", "--workers", "4", "app/main.py"]
|
CMD ["fastapi", "run", "--workers", "4", "app/main.py"]
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* [Docker](https://www.docker.com/).
|
* [Docker](https://www.docker.com/).
|
||||||
* [Poetry](https://python-poetry.org/) for Python package and environment management.
|
* [uv](https://docs.astral.sh/uv/) for Python package and environment management.
|
||||||
|
|
||||||
## Docker Compose
|
## Docker Compose
|
||||||
|
|
||||||
@@ -11,21 +11,21 @@ Start the local development environment with Docker Compose following the guide
|
|||||||
|
|
||||||
## General Workflow
|
## General Workflow
|
||||||
|
|
||||||
By default, the dependencies are managed with [Poetry](https://python-poetry.org/), go there and install it.
|
By default, the dependencies are managed with [uv](https://docs.astral.sh/uv/), go there and install it.
|
||||||
|
|
||||||
From `./backend/` you can install all the dependencies with:
|
From `./backend/` you can install all the dependencies with:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ poetry install
|
$ uv sync
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you can start a shell session with the new environment with:
|
Then you can activate the virtual environment with:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ poetry shell
|
$ source .venv/bin/activate
|
||||||
```
|
```
|
||||||
|
|
||||||
Make sure your editor is using the correct Python virtual environment.
|
Make sure your editor is using the correct Python virtual environment, with the interpreter at `backend/.venv/bin/python`.
|
||||||
|
|
||||||
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`.
|
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`.
|
||||||
|
|
||||||
|
2204
backend/poetry.lock
generated
2204
backend/poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,41 @@
|
|||||||
[tool.poetry]
|
[project]
|
||||||
name = "app"
|
name = "app"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = ""
|
description = ""
|
||||||
authors = ["Admin <admin@example.com>"]
|
requires-python = ">=3.10,<4.0"
|
||||||
|
dependencies = [
|
||||||
|
"fastapi[standard]<1.0.0,>=0.114.2",
|
||||||
|
"python-multipart<1.0.0,>=0.0.7",
|
||||||
|
"email-validator<3.0.0.0,>=2.1.0.post1",
|
||||||
|
"passlib[bcrypt]<2.0.0,>=1.7.4",
|
||||||
|
"tenacity<9.0.0,>=8.2.3",
|
||||||
|
"pydantic>2.0",
|
||||||
|
"emails<1.0,>=0.6",
|
||||||
|
"jinja2<4.0.0,>=3.1.4",
|
||||||
|
"alembic<2.0.0,>=1.12.1",
|
||||||
|
"httpx<1.0.0,>=0.25.1",
|
||||||
|
"psycopg[binary]<4.0.0,>=3.1.13",
|
||||||
|
"sqlmodel<1.0.0,>=0.0.21",
|
||||||
|
# Pin bcrypt until passlib supports the latest
|
||||||
|
"bcrypt==4.0.1",
|
||||||
|
"pydantic-settings<3.0.0,>=2.2.1",
|
||||||
|
"sentry-sdk[fastapi]<2.0.0,>=1.40.6",
|
||||||
|
"pyjwt<3.0.0,>=2.8.0",
|
||||||
|
]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.uv]
|
||||||
python = "^3.10"
|
dev-dependencies = [
|
||||||
fastapi = {extras = ["standard"], version = "^0.114.2"}
|
"pytest<8.0.0,>=7.4.3",
|
||||||
python-multipart = "^0.0.7"
|
"mypy<2.0.0,>=1.8.0",
|
||||||
email-validator = "^2.1.0.post1"
|
"ruff<1.0.0,>=0.2.2",
|
||||||
passlib = {extras = ["bcrypt"], version = "^1.7.4"}
|
"pre-commit<4.0.0,>=3.6.2",
|
||||||
tenacity = "^8.2.3"
|
"types-passlib<2.0.0.0,>=1.7.7.20240106",
|
||||||
pydantic = ">2.0"
|
"coverage<8.0.0,>=7.4.3",
|
||||||
emails = "^0.6"
|
]
|
||||||
|
|
||||||
gunicorn = "^22.0.0"
|
|
||||||
jinja2 = "^3.1.4"
|
|
||||||
alembic = "^1.12.1"
|
|
||||||
httpx = "^0.25.1"
|
|
||||||
psycopg = {extras = ["binary"], version = "^3.1.13"}
|
|
||||||
sqlmodel = "^0.0.21"
|
|
||||||
# Pin bcrypt until passlib supports the latest
|
|
||||||
bcrypt = "4.0.1"
|
|
||||||
pydantic-settings = "^2.2.1"
|
|
||||||
sentry-sdk = {extras = ["fastapi"], version = "^1.40.6"}
|
|
||||||
pyjwt = "^2.8.0"
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
|
||||||
pytest = "^7.4.3"
|
|
||||||
mypy = "^1.8.0"
|
|
||||||
ruff = "^0.2.2"
|
|
||||||
pre-commit = "^3.6.2"
|
|
||||||
types-passlib = "^1.7.7.20240106"
|
|
||||||
coverage = "^7.4.3"
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry>=0.12"]
|
requires = ["hatchling"]
|
||||||
build-backend = "poetry.masonry.api"
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
strict = true
|
strict = true
|
||||||
|
1554
backend/uv.lock
generated
Normal file
1554
backend/uv.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -63,7 +63,6 @@ _exclude:
|
|||||||
# Global
|
# Global
|
||||||
- .vscode
|
- .vscode
|
||||||
- .mypy_cache
|
- .mypy_cache
|
||||||
- poetry.lock
|
|
||||||
# Python
|
# Python
|
||||||
- __pycache__
|
- __pycache__
|
||||||
- app.egg-info
|
- app.egg-info
|
||||||
@@ -71,7 +70,6 @@ _exclude:
|
|||||||
- .mypy_cache
|
- .mypy_cache
|
||||||
- .coverage
|
- .coverage
|
||||||
- htmlcov
|
- htmlcov
|
||||||
- poetry.lock
|
|
||||||
- .cache
|
- .cache
|
||||||
- .venv
|
- .venv
|
||||||
# Frontend
|
# Frontend
|
||||||
|
@@ -134,10 +134,10 @@ You can find a file `.pre-commit-config.yaml` with configurations at the root of
|
|||||||
|
|
||||||
After having the `pre-commit` tool installed and available, you need to "install" it in the local repository, so that it runs automatically before each commit.
|
After having the `pre-commit` tool installed and available, you need to "install" it in the local repository, so that it runs automatically before each commit.
|
||||||
|
|
||||||
Using Poetry, you could do it with:
|
Using `uv`, you could do it with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
❯ poetry run pre-commit install
|
❯ uv run pre-commit install
|
||||||
pre-commit installed at .git/hooks/pre-commit
|
pre-commit installed at .git/hooks/pre-commit
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -153,10 +153,10 @@ Then you can `git add` the modified/fixed files again and now you can commit.
|
|||||||
|
|
||||||
#### Running pre-commit hooks manually
|
#### Running pre-commit hooks manually
|
||||||
|
|
||||||
you can also run `pre-commit` manually on all the files, you can do it using Poetry with:
|
you can also run `pre-commit` manually on all the files, you can do it using `uv` with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
❯ poetry run pre-commit run --all-files
|
❯ uv run pre-commit run --all-files
|
||||||
check for added large files..............................................Passed
|
check for added large files..............................................Passed
|
||||||
check toml...............................................................Passed
|
check toml...............................................................Passed
|
||||||
check yaml...............................................................Passed
|
check yaml...............................................................Passed
|
||||||
|
Reference in New Issue
Block a user