Merge pull request #217 from Crocmagnon/uv

migrate to uv
This commit is contained in:
Gabriel Augendre 2025-01-05 11:56:42 +01:00 committed by GitHub
commit 2d1e222df6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1311 additions and 386 deletions

View file

@ -1,5 +1,5 @@
FROM mcr.microsoft.com/devcontainers/python:3.12-bullseye FROM mcr.microsoft.com/devcontainers/python:3.13-bookworm
RUN apt-get update && apt-get upgrade -y RUN apt-get update && apt-get upgrade -y
RUN pip install pip-tools invoke COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
COPY requirements.in requirements.txt requirements-dev.in requirements-dev.txt constraints.txt tasks.py ./ COPY pyproject.toml uv.lock tasks.py ./
RUN invoke sync-dependencies RUN uv sync --frozen

View file

@ -3,5 +3,5 @@
"dockerfile": "Dockerfile", "dockerfile": "Dockerfile",
"context": ".." "context": ".."
}, },
"postStartCommand": "inv sync-dependencies && pre-commit install --install-hooks" "postStartCommand": "uv sync && uv run pre-commit install --install-hooks"
} }

View file

@ -9,3 +9,5 @@ __pycache__/
.idea/ .idea/
*.mo *.mo
.kolo/ .kolo/
.venv
node_modules

View file

@ -17,15 +17,15 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.12' python-version-file: "pyproject.toml"
cache: pip - name: Install the project
- name: Install dependencies
run: | run: |
pip install pip-tools uv sync --all-extras --dev --frozen --no-install-project
pip-sync requirements.txt requirements-dev.txt
sudo apt-get update sudo apt-get update
sudo apt-get install -y --no-install-recommends gettext sudo apt-get install -y --no-install-recommends gettext
- name: Setup pre-commit cache - name: Setup pre-commit cache
@ -34,7 +34,7 @@ jobs:
path: ~/.cache/pre-commit path: ~/.cache/pre-commit
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Check pre-commit - name: Check pre-commit
run: pre-commit run --show-diff-on-failure --color=always --all-files run: uv run pre-commit run --show-diff-on-failure --color=always --all-files
- name: Test - name: Test
run: inv test-cov run: uv run inv test-cov
working-directory: ./src/ working-directory: ./src/

View file

@ -20,15 +20,15 @@ jobs:
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: master ref: master
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: '3.12' python-version-file: "pyproject.toml"
cache: pip
- name: Update dependencies - name: Update dependencies
run: | run: |
pip install pip-tools invoke uv lock --upgrade
invoke update-dependencies --no-sync
- name: Generate token - name: Generate token
uses: tibdex/github-app-token@v2 uses: tibdex/github-app-token@v2
id: generate-token id: generate-token

View file

@ -1,5 +1,2 @@
[tools]
python = {version="3.12", virtualenv=".venv"}
[env] [env]
ENV_FILE = "{{config_root}}/envs/local.env" ENV_FILE = "{{config_root}}/envs/local.env"

View file

@ -1,6 +1,4 @@
exclude: \.min\.(js|css)(\.map)?$|^\.idea/|/vendor/ exclude: \.min\.(js|css)(\.map)?$|^\.idea/|/vendor/
ci:
skip: [pip-compile]
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
@ -62,18 +60,7 @@ repos:
rev: v2.5.0 rev: v2.5.0
hooks: hooks:
- id: pyproject-fmt - id: pyproject-fmt
- repo: https://github.com/jazzband/pip-tools - repo: https://github.com/astral-sh/uv-pre-commit
rev: 7.4.1 rev: 0.5.13
hooks: hooks:
- id: pip-compile - id: uv-lock
name: pip-compile requirements.txt
args: [-q, --allow-unsafe, --no-strip-extras, requirements.in]
files: ^requirements\.(in|txt)$
- id: pip-compile
name: pip-compile constraints.txt
args: [-q, --allow-unsafe, --strip-extras, --output-file=constraints.txt, requirements.in]
files: ^requirements\.in|constraints\.txt$
- id: pip-compile
name: pip-compile requirements-dev.txt
args: [-q, --allow-unsafe, --no-strip-extras, --constraint=constraints.txt, requirements-dev.in]
files: ^requirements-dev\.(in|txt)$

View file

@ -11,10 +11,26 @@ RUN date +'%Y-%m-%d %H:%M %Z' > /build-date
##############################################
# install python dependencies
##############################################
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS builder
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
WORKDIR /app
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 --no-dev
ADD . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
############################################## ##############################################
# Main image # Main image
############################################## ##############################################
FROM python:3.13.0-slim-bullseye AS final FROM python:3.13.1-slim-bookworm AS final
ARG DEBIAN_FRONTEND=noninteractive ARG DEBIAN_FRONTEND=noninteractive
ARG PIP_DISABLE_PIP_VERSION_CHECK=1 ARG PIP_DISABLE_PIP_VERSION_CHECK=1
@ -38,10 +54,7 @@ COPY --chown=django:django --from=git /git-describe /git-commit /build-date /app
# Create directory structure # Create directory structure
############################################## ##############################################
WORKDIR /app COPY --from=builder --chown=django:django /app /app
COPY --chown=django:django pyproject.toml requirements.txt ./
ADD --chown=django:django ./src ./src
COPY --chown=django:django tasks.py ./tasks.py
RUN mkdir -p /app/data /app/db RUN mkdir -p /app/data /app/db
RUN chown django:django /app /app/data /app/db RUN chown django:django /app /app/data /app/db
@ -51,7 +64,8 @@ ENV SECRET_KEY "changeme"
ENV DEBUG "false" ENV DEBUG "false"
ENV DB_BASE_DIR "/app/db" ENV DB_BASE_DIR "/app/db"
RUN python -m pip install --no-cache-dir -r requirements.txt ENV PATH="/app/.venv/bin:$PATH"
WORKDIR /app/src WORKDIR /app/src
RUN python manage.py collectstatic --noinput --clear RUN python manage.py collectstatic --noinput --clear
RUN python manage.py compilemessages -l fr -l en RUN python manage.py compilemessages -l fr -l en

View file

@ -5,13 +5,12 @@ Simple interface to register baskets.
## Quick start ## Quick start
Clone, then Clone, then
```shell ```shell
pip install -U pip pip-tools invoke uv sync
inv sync-dependencies uv run pre-commit install --install-hooks
pre-commit install --install-hooks
inv test inv test
./src/manage.py migrate uv run ./src/manage.py migrate
./src/manage.py generate_dummy_baskets uv run ./src/manage.py generate_dummy_baskets
./src/manage.py createsuperuser uv run ./src/manage.py createsuperuser
``` ```
# Reuse # Reuse

View file

@ -1,4 +1,3 @@
version: '2.4'
services: services:
django: django:
extends: extends:

View file

@ -1,4 +1,3 @@
version: '2.4'
services: services:
django: django:
image: crocmagnon/checkout:dev image: crocmagnon/checkout:dev

View file

@ -1,9 +1,47 @@
############################################################################### [project]
# pytest name = "checkout"
############################################################################### version = "0.0.1"
requires-python = ">=3.13"
classifiers = [ "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.13" ]
dependencies = [
"crispy-bootstrap5>=0.6",
"django>=4.1",
"django-anymail[mailgun]>=8.6",
"django-cleanup>=6",
"django-crispy-forms>=1.14",
"django-csp>=3.7",
"django-environ>=0.9",
"django-extensions>=3.1.5",
"django-htmx>=1.12.2",
"django-solo>=2",
"freezegun>=1.2.1",
"gunicorn>=20.1",
"matplotlib>=3.5.1",
"pillow>=9.3",
"requests>=2.28.1",
"whitenoise>=6.2",
]
[dependency-groups]
dev = [
"black>=22.12",
"factory-boy>=3.2.1",
"invoke>=2",
"model-bakery>=1.1",
"pip-tools>=6",
"pre-commit>=2.7",
"pytest>=6",
"pytest-cov>=3",
"pytest-django>=4.5",
"pytest-rerunfailures>=13",
"pytest-selenium>=4",
"ruff>=0.0.237",
"selenium>=4.4.3",
]
[tool.ruff] [tool.ruff]
target-version = "py311" target-version = "py313"
src = [ src = [
"src", "src",
] ]
@ -64,6 +102,9 @@ markers = [
"flaky", "flaky",
] ]
[tool.uv]
package = false
############################################################################### ###############################################################################
# ruff # ruff
############################################################################### ###############################################################################

View file

@ -1,14 +0,0 @@
pre-commit>=2.7
pytest>=6.0
pytest-cov>=3.0.0
pytest-django>=4.5.0
pytest-selenium>=4.0.0
pytest-rerunfailures>=13.0
pre-commit>=2.7
model-bakery>=1.1
invoke>=2.0.0
factory-boy>=3.2.1
selenium>=4.4.3
black>=22.12.0
pip-tools>=6.0
ruff>=0.0.237

View file

@ -1,184 +0,0 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --allow-unsafe --constraint=constraints.txt requirements-dev.in
#
asgiref==3.8.1
# via
# -c constraints.txt
# django
attrs==24.3.0
# via
# outcome
# trio
black==24.10.0
# via -r requirements-dev.in
build==1.2.2.post1
# via pip-tools
certifi==2024.12.14
# via
# -c constraints.txt
# requests
# selenium
cfgv==3.4.0
# via pre-commit
charset-normalizer==3.4.1
# via
# -c constraints.txt
# requests
click==8.1.8
# via
# black
# pip-tools
coverage[toml]==7.6.10
# via pytest-cov
distlib==0.3.9
# via virtualenv
django==5.1.4
# via
# -c constraints.txt
# model-bakery
factory-boy==3.3.1
# via -r requirements-dev.in
faker==33.1.0
# via factory-boy
filelock==3.16.1
# via virtualenv
h11==0.14.0
# via wsproto
identify==2.6.4
# via pre-commit
idna==3.10
# via
# -c constraints.txt
# requests
# trio
iniconfig==2.0.0
# via pytest
invoke==2.2.0
# via -r requirements-dev.in
jinja2==3.1.5
# via pytest-html
markupsafe==3.0.2
# via jinja2
model-bakery==1.20.0
# via -r requirements-dev.in
mypy-extensions==1.0.0
# via black
nodeenv==1.9.1
# via pre-commit
outcome==1.3.0.post0
# via trio
packaging==24.2
# via
# -c constraints.txt
# black
# build
# pytest
# pytest-rerunfailures
pathspec==0.12.1
# via black
pip-tools==7.4.1
# via -r requirements-dev.in
platformdirs==4.3.6
# via
# black
# virtualenv
pluggy==1.5.0
# via pytest
pre-commit==4.0.1
# via -r requirements-dev.in
pyproject-hooks==1.2.0
# via
# build
# pip-tools
pysocks==1.7.1
# via urllib3
pytest==8.3.4
# via
# -r requirements-dev.in
# pytest-base-url
# pytest-cov
# pytest-django
# pytest-html
# pytest-metadata
# pytest-rerunfailures
# pytest-selenium
# pytest-variables
pytest-base-url==2.1.0
# via pytest-selenium
pytest-cov==6.0.0
# via -r requirements-dev.in
pytest-django==4.9.0
# via -r requirements-dev.in
pytest-html==4.1.1
# via pytest-selenium
pytest-metadata==3.1.1
# via pytest-html
pytest-rerunfailures==15.0
# via -r requirements-dev.in
pytest-selenium==4.1.0
# via -r requirements-dev.in
pytest-variables==3.1.0
# via pytest-selenium
python-dateutil==2.9.0.post0
# via
# -c constraints.txt
# faker
pyyaml==6.0.2
# via pre-commit
requests==2.32.3
# via
# -c constraints.txt
# pytest-base-url
# pytest-selenium
ruff==0.8.4
# via -r requirements-dev.in
selenium==4.27.1
# via
# -r requirements-dev.in
# pytest-selenium
six==1.17.0
# via
# -c constraints.txt
# python-dateutil
sniffio==1.3.1
# via trio
sortedcontainers==2.4.0
# via trio
sqlparse==0.5.3
# via
# -c constraints.txt
# django
tenacity==9.0.0
# via pytest-selenium
trio==0.28.0
# via
# selenium
# trio-websocket
trio-websocket==0.11.1
# via selenium
typing-extensions==4.12.2
# via
# faker
# selenium
urllib3[socks]==2.3.0
# via
# -c constraints.txt
# requests
# selenium
virtualenv==20.28.0
# via pre-commit
websocket-client==1.8.0
# via selenium
wheel==0.45.1
# via pip-tools
wsproto==1.2.0
# via trio-websocket
# The following packages are considered to be unsafe in a requirements file:
pip==24.3.1
# via pip-tools
setuptools==75.6.0
# via pip-tools

View file

@ -1,16 +0,0 @@
django>=4.1
django-anymail[mailgun]>=8.6
django-cleanup>=6.0
whitenoise>=6.2
django-csp>=3.7
django-environ>=0.9.0
requests>=2.28.1
django-extensions>=3.1.5
gunicorn>=20.1.0
Pillow>=9.3.0
django-crispy-forms>=1.14.0
crispy-bootstrap5>=0.6
matplotlib>=3.5.1
freezegun>=1.2.1
django-htmx>=1.12.2
django-solo>=2.0.0

View file

@ -1,92 +0,0 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --allow-unsafe requirements.in
#
asgiref==3.8.1
# via
# django
# django-htmx
certifi==2024.12.14
# via requests
charset-normalizer==3.4.1
# via requests
contourpy==1.3.1
# via matplotlib
crispy-bootstrap5==2024.10
# via -r requirements.in
cycler==0.12.1
# via matplotlib
django==5.1.4
# via
# -r requirements.in
# crispy-bootstrap5
# django-anymail
# django-crispy-forms
# django-csp
# django-extensions
# django-htmx
# django-solo
django-anymail[mailgun]==12.0
# via -r requirements.in
django-cleanup==9.0.0
# via -r requirements.in
django-crispy-forms==2.3
# via
# -r requirements.in
# crispy-bootstrap5
django-csp==3.8
# via -r requirements.in
django-environ==0.11.2
# via -r requirements.in
django-extensions==3.2.3
# via -r requirements.in
django-htmx==1.21.0
# via -r requirements.in
django-solo==2.4.0
# via -r requirements.in
fonttools==4.55.3
# via matplotlib
freezegun==1.5.1
# via -r requirements.in
gunicorn==23.0.0
# via -r requirements.in
idna==3.10
# via requests
kiwisolver==1.4.8
# via matplotlib
matplotlib==3.10.0
# via -r requirements.in
numpy==2.2.1
# via
# contourpy
# matplotlib
packaging==24.2
# via
# gunicorn
# matplotlib
pillow==11.0.0
# via
# -r requirements.in
# matplotlib
pyparsing==3.2.0
# via matplotlib
python-dateutil==2.9.0.post0
# via
# freezegun
# matplotlib
requests==2.32.3
# via
# -r requirements.in
# django-anymail
six==1.17.0
# via python-dateutil
sqlparse==0.5.3
# via django
urllib3==2.3.0
# via
# django-anymail
# requests
whitenoise==6.8.2
# via -r requirements.in

View file

@ -10,39 +10,15 @@ TEST_ENV = {"ENV_FILE": BASE_DIR / "envs" / "test-envs.env"}
@task @task
def update_dependencies(ctx: Context, *, sync: bool = True): def update_dependencies(ctx: Context):
return compile_dependencies(ctx, update=True, sync=sync)
@task
def compile_dependencies(ctx: Context, *, update: bool = False, sync: bool = False):
common_args = "-q --allow-unsafe"
if update:
common_args += " --upgrade"
with ctx.cd(BASE_DIR): with ctx.cd(BASE_DIR):
ctx.run( ctx.run("uv lock --upgrade", pty=True, echo=True)
f"pip-compile {common_args} --no-strip-extras requirements.in",
pty=True,
echo=True,
)
ctx.run(
f"pip-compile {common_args} --strip-extras -o constraints.txt requirements.in",
pty=True,
echo=True,
)
ctx.run(
f"pip-compile {common_args} --no-strip-extras -c constraints.txt requirements-dev.in",
pty=True,
echo=True,
)
if sync:
sync_dependencies(ctx)
@task @task
def sync_dependencies(ctx: Context): def sync_dependencies(ctx: Context):
with ctx.cd(BASE_DIR): with ctx.cd(BASE_DIR):
ctx.run("pip-sync requirements.txt requirements-dev.txt", pty=True, echo=True) ctx.run("uv sync", pty=True, echo=True)
@task @task

1217
uv.lock generated Normal file

File diff suppressed because it is too large Load diff