⬆️ 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/
|
||||
|
||||
# Install Poetry
|
||||
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
|
||||
cd /usr/local/bin && \
|
||||
ln -s /opt/poetry/bin/poetry && \
|
||||
poetry config virtualenvs.create false
|
||||
# Install uv
|
||||
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
|
||||
COPY --from=ghcr.io/astral-sh/uv:0.4.15 /uv /bin/uv
|
||||
|
||||
# Copy poetry.lock* in case it doesn't exist in the repo
|
||||
COPY ./pyproject.toml ./poetry.lock* /app/
|
||||
# Place executables in the environment at the front of the path
|
||||
# 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
|
||||
|
||||
COPY ./scripts /app/scripts
|
||||
|
||||
COPY ./alembic.ini /app/
|
||||
COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/
|
||||
|
||||
COPY ./app /app/app
|
||||
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
uv sync
|
||||
|
||||
CMD ["fastapi", "run", "--workers", "4", "app/main.py"]
|
||||
|
@@ -3,7 +3,7 @@
|
||||
## Requirements
|
||||
|
||||
* [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
|
||||
|
||||
@@ -11,21 +11,21 @@ Start the local development environment with Docker Compose following the guide
|
||||
|
||||
## 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:
|
||||
|
||||
```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
|
||||
$ 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`.
|
||||
|
||||
|
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"
|
||||
version = "0.1.0"
|
||||
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]
|
||||
python = "^3.10"
|
||||
fastapi = {extras = ["standard"], version = "^0.114.2"}
|
||||
python-multipart = "^0.0.7"
|
||||
email-validator = "^2.1.0.post1"
|
||||
passlib = {extras = ["bcrypt"], version = "^1.7.4"}
|
||||
tenacity = "^8.2.3"
|
||||
pydantic = ">2.0"
|
||||
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"
|
||||
[tool.uv]
|
||||
dev-dependencies = [
|
||||
"pytest<8.0.0,>=7.4.3",
|
||||
"mypy<2.0.0,>=1.8.0",
|
||||
"ruff<1.0.0,>=0.2.2",
|
||||
"pre-commit<4.0.0,>=3.6.2",
|
||||
"types-passlib<2.0.0.0,>=1.7.7.20240106",
|
||||
"coverage<8.0.0,>=7.4.3",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry>=0.12"]
|
||||
build-backend = "poetry.masonry.api"
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.mypy]
|
||||
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
|
||||
- .vscode
|
||||
- .mypy_cache
|
||||
- poetry.lock
|
||||
# Python
|
||||
- __pycache__
|
||||
- app.egg-info
|
||||
@@ -71,7 +70,6 @@ _exclude:
|
||||
- .mypy_cache
|
||||
- .coverage
|
||||
- htmlcov
|
||||
- poetry.lock
|
||||
- .cache
|
||||
- .venv
|
||||
# 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.
|
||||
|
||||
Using Poetry, you could do it with:
|
||||
Using `uv`, you could do it with:
|
||||
|
||||
```bash
|
||||
❯ poetry run pre-commit install
|
||||
❯ uv run pre-commit install
|
||||
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
|
||||
|
||||
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
|
||||
❯ poetry run pre-commit run --all-files
|
||||
❯ uv run pre-commit run --all-files
|
||||
check for added large files..............................................Passed
|
||||
check toml...............................................................Passed
|
||||
check yaml...............................................................Passed
|
||||
|
Reference in New Issue
Block a user