Skip to content

Commit a231418

Browse files
authored
chore: replace poetry with uv (#99)
1 parent 8e52610 commit a231418

File tree

8 files changed

+795
-1274
lines changed

8 files changed

+795
-1274
lines changed

.github/workflows/main.yml

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,60 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18-
- uses: actions/setup-python@v4
18+
- uses: astral-sh/setup-uv@v3
1919
with:
20-
python-version: '3.12'
21-
# because pre-commit uses external mypy
22-
- name: install mypy
23-
run: |
24-
pip install poetry
25-
poetry config virtualenvs.create false
26-
poetry install --only main,typecheck
20+
version: "0.4.24"
21+
enable-cache: true
22+
23+
- name: pre-commit cache key
24+
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
25+
26+
- uses: actions/cache@v4
27+
with:
28+
path: ~/.cache/pre-commit
29+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
30+
31+
- name: Install Python
32+
run: uv python install
33+
34+
- name: install dependencies
35+
run: uv sync
36+
2737
# https://github.com/typeddjango/django-stubs/issues/458
2838
- name: create .env file
2939
run: cp example.env .env
30-
- uses: pre-commit/[email protected]
40+
41+
- name: pre-commit
42+
run: uv run pre-commit run --all-files
3143

3244
unit_test:
3345
needs: [ lint ]
3446
runs-on: ubuntu-latest
3547
steps:
3648
- uses: actions/checkout@v4
37-
- uses: actions/setup-python@v4
49+
- uses: astral-sh/setup-uv@v3
3850
with:
39-
python-version: '3.12'
40-
- name: Install dependencies
41-
run: |
42-
pip install poetry
43-
poetry config virtualenvs.create false
44-
poetry install --only main
51+
version: "0.4.24"
52+
enable-cache: true
53+
54+
- name: Set up Python
55+
run: uv python install
56+
57+
- name: install dependencies
58+
run: uv sync
59+
4560
- name: create .env file
4661
run: cp example.env .env
62+
4763
- name: Run tests
4864
env:
4965
SECRET_KEY: secret
5066
DB_ENGINE: django.db.backends.sqlite3
5167
run: |
5268
cd src
53-
python manage.py makemigrations --check
54-
python manage.py migrate
55-
python manage.py test tests/
69+
uv run manage.py makemigrations --check
70+
uv run manage.py migrate
71+
uv run manage.py test tests/
5672
5773
docker:
5874
needs: [ lint, unit_test ]

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
^.*.md$
1818
1919
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
rev: v0.6.9
20+
rev: v0.7.0
2121
hooks:
2222
- id: ruff
2323
args: [ --fix ]

Dockerfile

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
FROM python:3.12-alpine3.20
22

3-
# in order:
4-
# proper stdout flushing for alpine
5-
# no .pyc files
6-
# do not store pip cache
7-
# do not check pip version
8-
# do not yell about root user
93
ENV PYTHONUNBUFFERED=yes \
104
PYTHONDONTWRITEBYTECODE=yes \
11-
PIP_NO_CACHE_DIR=1 \
12-
PIP_DISABLE_PIP_VERSION_CHECK=1 \
13-
PIP_ROOT_USER_ACTION=ignore
5+
UV_LINK_MODE=copy
146

157
WORKDIR /src
168

17-
COPY poetry.lock pyproject.toml ./
18-
19-
RUN : \
9+
RUN --mount=from=ghcr.io/astral-sh/uv:0.4.24,source=/uv,target=/bin/uv \
10+
--mount=type=cache,target=/root/.cache/uv \
11+
--mount=type=bind,source=uv.lock,target=uv.lock \
12+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
2013
# psycopg runtime dep
21-
&& apk add --no-cache libpq \
22-
&& pip install poetry \
23-
&& poetry config virtualenvs.create false \
24-
&& poetry install --only main
14+
apk add --no-cache libpq \
15+
# export requirements from uv.lock since uv does not support sync withour venv
16+
&& uv export --frozen --format requirements-txt --no-dev --quiet | uv pip install --system -r -
2517

2618
COPY src .
2719

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Copy `example.env` to `.env` and customize it. You can then start development by
2424
You will need python 3.12+
2525

2626
<details>
27-
<summary>Extra steps if don't want to install poetry globally for some reason</summary>
27+
<summary>Extra steps if don't want to install uv globally for some reason</summary>
2828

2929
#### Install venv (only first time or after updating sytem python version)
3030

@@ -48,21 +48,22 @@ python -m venv .venv
4848

4949
#### Dependency installation
5050

51-
Install poetry to manage dependencies and update pip
51+
Install uv to manage dependencies
5252

5353
```sh
54-
pip install -U pip poetry
54+
pip install -U pip uv
5555
```
5656

5757
Install dev dependencies
5858

5959
```sh
60-
poetry install
60+
uv sync
6161
```
6262

6363
#### Start the server
6464

6565
from the src folder run
66+
6667
```sh
6768
python manage.py runserver
6869
```

0 commit comments

Comments
 (0)