Skip to content

Commit

Permalink
chore: replace poetry with uv
Browse files Browse the repository at this point in the history
  • Loading branch information
Fogapod committed Oct 19, 2024
1 parent 8e52610 commit 42c4b25
Show file tree
Hide file tree
Showing 8 changed files with 797 additions and 1,274 deletions.
55 changes: 36 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,67 @@ on:

env:
IMAGE_NAME: unitystation/central-command
UV_VERSION: "0.4.24"

jobs:
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'
# 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
25 changes: 9 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
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_NO_CACHE=true \
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

0 comments on commit 42c4b25

Please sign in to comment.