Skip to content

Commit

Permalink
Switch to uv
Browse files Browse the repository at this point in the history
fixes #30
  • Loading branch information
ipmb committed Oct 18, 2024
1 parent c4a3b3e commit 61091b2
Show file tree
Hide file tree
Showing 10 changed files with 516 additions and 709 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/upgrade-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
python-version: '3.12'
- name: upgrade deps
run: |
pip install -U pip pip-tools
pip install -U uv
make upgrade-requirements
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Update Python dependencies
file_pattern: requirements*.txt
file_pattern: uv.lock
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ RUN npm run build
# STAGE 2: BUILD PYTHON
FROM python:3.12-bullseye AS build-python
WORKDIR /app
RUN --mount=type=cache,target=/root/.cache \
set -ex && \
python -m venv --prompt . --upgrade-deps /app/.venv && \
/app/.venv/bin/pip install --disable-pip-version-check --root-user-action=ignore --no-cache-dir --upgrade setuptools wheel
RUN set -ex && pip install --root-user-action --no-cache-dir uv && uv venv

ENV LC_ALL=C.UTF-8 LANG=C.UTF-8 \
PATH=/app/.venv/bin:${PATH}

ARG PY_REQUIREMENTS_FILE=requirements.txt
COPY requirements.txt requirements-dev.txt ./
# A blank string installs all extras. A non-existent extra will be ignored.
ARG UV_EXTRA_DEPENDENCIES="null"
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache \
pip install --disable-pip-version-check --root-user-action=ignore --no-cache-dir -r "$PY_REQUIREMENTS_FILE"
uv sync --frozen --extra "${UV_EXTRA_DEPENDENCIES}"

COPY . ./
COPY --from=build-node /home/node/app/client/dist ./client/dist
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

SHELL=/bin/bash -eu -o pipefail

requirements.txt: pyproject.toml ## Generate requirements.txt (and requirements-dev.txt) from pyproject.toml
./bin/lock-requirements.sh

.PHONY: upgrade-requirements
upgrade-requirements: ## Upgrade all dependencies in requirements.txt and requirements-dev.txt
./bin/lock-requirements.sh --upgrade
uv lock --upgrade

README.md: {{ project_name }}/config.py Makefile ## Update dynamic blocks in README.md
cog -r README.md
Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

# Django Layout

`django-layout` provides sane defaults for new Django projects based on
[established best
practices](http://lincolnloop.com/django-best-practices/) and some
configuration setups frequently used in Lincoln Loop\'s projects, like
[using `pip-tools` for dependency
locking](https://lincolnloop.com/blog/python-dependency-locking-pip-tools/),
[using
`pyproject.toml`](https://lincolnloop.com/insights/using-pyprojecttoml-in-your-django-project/).
`django-layout` provides sane defaults for new Django projects based on established best
practices and some configuration setups frequently used in Lincoln Loop\'s projects. It includes:

To use `django-layout`:
* `uv` for fast dependency management
* `ruff` for formatting and linting
* `goodconf` for structured & documented environment variable configuration
* structured logging in deployment and pretty logging in development
* `gunicorn` and `whitenoise` for production deployments
* production-hardened settings

## Usage

### With `pip`

1. create and activate a virtualenv:

Expand All @@ -28,6 +31,17 @@ To use `django-layout`:
--exclude=.github \
YOUR_PROJECT_NAME

### With `uv`

If you're using `uv`, you can run the following command (replace `YOUR_PROJECT_NAME` with your preferred name):

uv run --with django django-admin startproject \
--template=https://github.com/lincolnloop/django-layout/zipball/main \
--extension=py,md,gitignore,yaml,json,toml \
--name=Makefile,Dockerfile \
--exclude=.github \
YOUR_PROJECT_NAME

## Development

To update `README.md` after making changes to the config, run:
Expand Down
28 changes: 0 additions & 28 deletions bin/lock-requirements.sh

This file was deleted.

2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:
context: .
target: build-python
args:
PY_REQUIREMENTS_FILE: requirements-dev.txt
UV_EXTRA_DEPENDENCIES: "dev"
environment:
- DEBUG=true
- DJANGO_ENV=development
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "django-layout"
version = "4.0"
requires-python = ">=3.12"
dependencies = [
"django==5.0.*",
"dj-database-url",
Expand All @@ -24,7 +25,6 @@ dev = [
"cogapp",
"django-stubs",
"mypy",
"pip-tools",
"readable-log-formatter",
"ruff",
]
Expand Down
Loading

0 comments on commit 61091b2

Please sign in to comment.