Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace poetry with uv #99

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,60 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v3
with:
python-version: '3.12'
# because pre-commit uses external mypy
- name: install mypy
run: |
pip install poetry
poetry config virtualenvs.create false
poetry install --only main,typecheck
version: "0.4.24"
enable-cache: true

- name: pre-commit cache key
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV

- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}

- name: Install Python
run: uv python install

- name: install dependencies
run: uv sync

# https://github.com/typeddjango/django-stubs/issues/458
- name: create .env file
run: cp example.env .env
- uses: pre-commit/action@v3.0.0

- name: pre-commit
run: uv run pre-commit run --all-files

unit_test:
needs: [ lint ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v3
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install poetry
poetry config virtualenvs.create false
poetry install --only main
version: "0.4.24"
enable-cache: true

- name: Set up Python
run: uv python install

- name: install dependencies
run: uv sync

- name: create .env file
run: cp example.env .env

- name: Run tests
env:
SECRET_KEY: secret
DB_ENGINE: django.db.backends.sqlite3
run: |
cd src
python manage.py makemigrations --check
python manage.py migrate
python manage.py test tests/
uv run manage.py makemigrations --check
uv run manage.py migrate
uv run manage.py test tests/

docker:
needs: [ lint, unit_test ]
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
^.*.md$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.7.0
hooks:
- id: ruff
args: [ --fix ]
Expand Down
24 changes: 8 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
FROM python:3.12-alpine3.20

# in order:
# proper stdout flushing for alpine
# no .pyc files
# do not store pip cache
# do not check pip version
# do not yell about root user
ENV PYTHONUNBUFFERED=yes \
PYTHONDONTWRITEBYTECODE=yes \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_ROOT_USER_ACTION=ignore
UV_LINK_MODE=copy

WORKDIR /src

COPY poetry.lock pyproject.toml ./

RUN : \
RUN --mount=from=ghcr.io/astral-sh/uv:0.4.24,source=/uv,target=/bin/uv \
--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 \
# psycopg runtime dep
&& apk add --no-cache libpq \
&& pip install poetry \
&& poetry config virtualenvs.create false \
&& poetry install --only main
apk add --no-cache libpq \
# export requirements from uv.lock since uv does not support sync withour venv
&& uv export --frozen --format requirements-txt --no-dev --quiet | uv pip install --system -r -

COPY src .

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Copy `example.env` to `.env` and customize it. You can then start development by
You will need python 3.12+

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

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

Expand All @@ -48,21 +48,22 @@ python -m venv .venv

#### Dependency installation

Install poetry to manage dependencies and update pip
Install uv to manage dependencies

```sh
pip install -U pip poetry
pip install -U pip uv
```

Install dev dependencies

```sh
poetry install
uv sync
```

#### Start the server

from the src folder run

```sh
python manage.py runserver
```
Expand Down
Loading