Skip to content

Commit

Permalink
Switch poetry for UV
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodiegoss committed Jan 26, 2025
1 parent 225275a commit bf0e5c1
Show file tree
Hide file tree
Showing 8 changed files with 1,023 additions and 1,791 deletions.
3 changes: 1 addition & 2 deletions .venv/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*
!.gitignore
*
22 changes: 7 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@

FROM python:3.13.0-slim-bookworm
FROM python:3.13.1-slim-bookworm
COPY --from=ghcr.io/astral-sh/uv:0.5.24 /uv /uvx /bin/

ENV PATH="$PATH:/home/jandig/.local/bin:/jandig/.venv/bin" \
TINI_VERSION=v0.19.0 \
# poetry:
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=true \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_VIRTUALENVS_OPTIONS_ALWAYS_COPY=true \
POETRY_VIRTUALENV_PATH="/jandig/.venv" \
POETRY_CACHE_DIR='/home/jandig/cache/pypoetry' \
POETRY_VERSION=1.8.4
UV_CACHE_DIR=/home/jandig/jandig/cache/uv

RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand All @@ -19,17 +13,18 @@ RUN apt-get update && \
curl \
wget


RUN dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
&& wget "https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${dpkgArch}" -O /usr/local/bin/tini \
&& chmod +x /usr/local/bin/tini && tini --version


RUN mkdir -p /jandig/src /jandig/locale /jandig/docs /jandig/.venv /jandig/static /jandig/build /home/jandig/cache/pypoetry
RUN mkdir -p /jandig/src /jandig/locale /jandig/docs /jandig/.venv /jandig/static /jandig/build /home/jandig/jandig/cache/uv

WORKDIR /jandig

COPY ./pyproject.toml /jandig/pyproject.toml
COPY ./poetry.lock /jandig/poetry.lock
COPY ./uv.lock /jandig/uv.lock

COPY ./src/ /jandig/src/
COPY ./docs/ /jandig/docs/
Expand All @@ -49,12 +44,9 @@ RUN chmod 2775 /jandig /home/jandig
# Switch to the new user
USER jandig

# Installing `poetry` package manager:
# https://github.com/python-poetry/poetry
RUN curl -sSL https://install.python-poetry.org | python3 -

RUN find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf

RUN uv sync --frozen --no-dev
ENTRYPOINT ["tini", "--"]

CMD [ "/jandig/run.sh" ]
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ RUNNING_CONTAINER := $(shell docker compose ps --services --filter "status=runni

test:
@if [[ -n "${RUNNING_CONTAINER}" ]]; then \
docker compose exec django poetry run pytest src/core src/users src/blog; \
docker compose exec django uv run pytest src/core src/users src/blog; \
else \
docker compose run --rm django poetry run pytest src/core src/users src/blog;\
docker compose run --rm django uv run pytest src/core src/users src/blog;\
fi

test-ui:
docker compose up -d
poetry run pytest src/tests
uv run pytest src/tests

lint:
poetry run ruff format src
poetry run ruff check --fix src
uv run ruff format src
uv run ruff check --fix src

check:
poetry run ruff check
uv run ruff check

migrations:
poetry run python src/manage.py makemigrations
uv run python src/manage.py makemigrations

migrate:
poetry run python src/manage.py migrate
uv run python src/manage.py migrate

gen:
poetry run playwright codegen -b chromium --target python-pytest localhost:8000
uv run playwright codegen -b chromium --target python-pytest localhost:8000

translate_es:
poetry run inv i18n -l es_ES
uv run inv i18n -l es_ES

translate_pt:
poetry run inv i18n -l pt_BR
uv run inv i18n -l pt_BR
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- 80:8000
volumes:
- ./:/jandig
- poetry_cache:/home/jandig/cache/pypoetry
- uv_cache:/home/jandig/cache/uv
env_file:
- .envs/.example
environment:
Expand Down Expand Up @@ -88,4 +88,4 @@ volumes:
postgres_data:
media_data:
mailpit_data:
poetry_cache:
uv_cache:
1,712 changes: 0 additions & 1,712 deletions poetry.lock

This file was deleted.

83 changes: 43 additions & 40 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
[tool.poetry]
package-mode = false
[project]
name = "Jandig"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"

[tool.poetry.dependencies]
python = "^3.13"
MarkupSafe = "^2.1.1"
Django = "^5.1.4"
Jinja2 = "^3.1.5"
gunicorn = "^20.1.0"
Pillow = "^11.0.0"
django-cors-headers = "^3.13.0"
django-environ = "^0.12.0"
psycopg2-binary = "^2.9.3"
Sphinx = "^8.1.3"
Babel = "^2.10.3"
django-debug-toolbar = "^4.4.6"
gevent = "^24.10.3"
pymarker = "^0.3.1"
django-extensions = "^3.1.5"
factory-boy = "^3.2.1"
boto3 = "^1.24.27"
django-storages = "^1.12.3"
sentry-sdk = "^2.8.0"
djangorestframework = "^3.13.1"
drf-nested-routers = "^0.93.4"
django-htmx = "^1.18.0"
dependencies = [
"babel~=2.16.0",
"boto3~=1.36.6",
"django-cors-headers~=3.14.0",
"django-environ~=0.12.0",
"django-extensions~=3.2.3",
"django-htmx~=1.21.0",
"django-storages~=1.14.4",
"django~=5.1.4",
"djangorestframework~=3.15.2",
"drf-nested-routers~=0.94.1",
"factory-boy~=3.3.1",
"gevent~=24.11.1",
"gunicorn~=23.0.0",
"jinja2~=3.1.5",
"markupsafe~=2.1.1",
"pillow~=11.1.0",
"psycopg2-binary~=2.9.3",
"pymarker~=0.3.1",
"sentry-sdk~=2.20.0",
"Sphinx~=8.1.3",
]

[tool.poetry.group.dev.dependencies]
invoke = "^2.2.0"
playwright = "^1.41.2"
pytest = "^7.2.0"
pytest-xdist = "^3.0.2"
Flake8-pyproject = "^1.2.3"
pytest-django = "^4.5.2"
dj-inmemorystorage = "^2.1.0"
pytest-playwright = "^0.4.4"
ruff = "^0.9.3"
[dependency-groups]
dev = [
"dj-inmemorystorage~=2.1.0",
"django-debug-toolbar~=4.4.6",
"invoke~=2.2.0",
"playwright~=1.49.1",
"pytest-django~=4.9.0",
"pytest-playwright~=0.4.4",
"pytest-xdist~=3.6.1",
"pytest~=7.4.4",
"ruff~=0.9.3",
]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "config.test_settings"
Expand All @@ -53,5 +55,6 @@ exclude = [
".venv",
]
line-length = 88
# Assume Python 3.12
target-version = "py312"
# Assume Python 3.13
target-version = "py313"

18 changes: 9 additions & 9 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ USE_GUNICORN=${USE_GUNICORN:-true}
INSTALL_DEV=$(echo "$INSTALL_DEV" | tr '[:upper:]' '[:lower:]')
USE_GUNICORN=$(echo "$USE_GUNICORN" | tr '[:upper:]' '[:lower:]')

poetry install --without dev
uv sync --frozen --no-dev

if [ "$INSTALL_DEV" = "true" ]; then
poetry install --only dev
uv sync --frozen
fi

poetry show
poetry run python src/manage.py collectstatic --no-input
poetry run python src/manage.py migrate
poetry run sphinx-build docs/ build/
poetry run python etc/scripts/compilemessages.py
uv pip list
uv run python src/manage.py collectstatic --no-input
uv run python src/manage.py migrate
uv run sphinx-build docs/ build/
uv run python etc/scripts/compilemessages.py

if [ "$USE_GUNICORN" = "true" ]; then
echo "Running Gunicorn Server"
bash -c "cd src && poetry run gunicorn --reload --worker-connections=10000 --workers=4 --log-level debug --bind 0.0.0.0:8000 config.wsgi"
bash -c "cd src && uv run gunicorn --reload --worker-connections=10000 --workers=4 --log-level debug --bind 0.0.0.0:8000 config.wsgi"
else
echo "Running Django development server"
poetry run python src/manage.py runserver 0.0.0.0:8000
uv run python src/manage.py runserver 0.0.0.0:8000
fi
Loading

0 comments on commit bf0e5c1

Please sign in to comment.