Skip to content
Open
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
68 changes: 29 additions & 39 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: monthly
time: "11:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: elasticsearch
versions:
- ">= 7.a, < 8"
- dependency-name: gevent
versions:
- ">= 21.a, < 22"
- dependency-name: greenlet
versions:
- 1.0.0
- dependency-name: django
versions:
- 2.2.18
- 2.2.19
- dependency-name: pygments
versions:
- 2.7.4
- 2.8.0
- dependency-name: bleach
versions:
- 3.2.3
- dependency-name: urllib3
versions:
- 1.26.3
- dependency-name: pillow
versions:
- 8.1.0
- dependency-name: gevent
versions:
- 20.12.1
- dependency-name: django-contrib-comments
versions:
- 2.0.0

- package-ecosystem: "uv"
directory: "/"
schedule:
interval: "weekly"
groups:
python-dependencies:
patterns:
- "*"

- package-ecosystem: "npm"
directory: "theme/static_src/"
schedule:
interval: "weekly"
groups:
npm-dependencies:
patterns:
- "*"

# Update GitHub actions in workflows
- package-ecosystem: "github-actions"
directory: "/"
# Every week
schedule:
interval: "weekly"
groups:
github-actions:
patterns:
- "*"
18 changes: 7 additions & 11 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/production.txt
- name: Install Linter
run: |
pip install ruff
ruff check .
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Install the project
run: uv sync --locked --only-group dev
- name: Run migrations
run: python manage.py migrate
run: uv run python manage.py migrate
- name: Collect static files
run: python manage.py collectstatic --no-input
run: uv run python manage.py collectstatic --no-input
- name: Run Tests
run: python manage.py test --settings=djangosnippets.settings.testing
run: uv run python manage.py test --settings=djangosnippets.settings.testing
39 changes: 16 additions & 23 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Prerequisites

- Python version 3.11
- PostgreSQL
- [uv](https://docs.astral.sh/uv/) - An extremely fast Python package and project manager

Installation
------------
Expand All @@ -24,23 +25,15 @@ Basic Installation

https://github.com/django/djangosnippets.org.git

2. Create your virtual environment:

.. code-block:: console

python -m venv venv

Activate in Linux:

.. code-block:: console

source venv/bin/activate

Activate in Windows:

2. Install uv if you haven't already:
.. code-block:: console
# macOS
curl -LsSf https://astral.sh/uv/install.sh | sh
# Window
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'Window' to 'Windows'.

Suggested change
# Window
# Windows

Copilot uses AI. Check for mistakes.
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

venv\Scripts\activate
.. [!NOTE]::
For detailed instructions on installing uv, please refer to this [document](https://docs.astral.sh/uv/getting-started/installation/).
Comment on lines +35 to +36
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses Markdown syntax within a reStructuredText file. The [!NOTE]:: directive and [document](URL) link syntax are invalid in RST. Use proper RST directives like .. note:: and `link text <URL>`_ instead.

Suggested change
.. [!NOTE]::
For detailed instructions on installing uv, please refer to this [document](https://docs.astral.sh/uv/getting-started/installation/).
.. note::
For detailed instructions on installing uv, please refer to this `document <https://docs.astral.sh/uv/getting-started/installation/>`_.

Copilot uses AI. Check for mistakes.

3. Connect to PostgreSQL

Expand Down Expand Up @@ -70,11 +63,11 @@ Basic Installation

postgres=# exit

5. Install requirements:
5. Install dependencies:

.. code-block:: console

pip install -r requirements/development.txt
uv sync --only-group dev

6. Copy `.env.template.local` file, rename to `.env` and configure variables for your local postgres database.

Expand All @@ -96,37 +89,37 @@ Basic Installation

.. code-block:: console

python manage.py migrate
uv run python manage.py migrate

Optionally load data first:

.. code-block:: console

python manage.py loaddata fixtures/cab.json
uv run python manage.py loaddata fixtures/cab.json

Create superuser:

.. code-block:: console

python manage.py createsuperuser
uv run python manage.py createsuperuser

8. Install tailwind (npm is required):

.. code-block:: console

python manage.py tailwind install
uv run python manage.py tailwind install

9. Run server locally:

.. code-block:: console

python manage.py runserver_plus
uv run python manage.py runserver_plus

10. Run tailwind in another terminal locally:

.. code-block:: console

python manage.py tailwind start
uv run python manage.py tailwind start

With Docker
~~~~~~~~~~~~~~~~~~~
Expand Down
85 changes: 28 additions & 57 deletions compose/local/django/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
# define an alias for the specific python version used in this file.
FROM docker.io/python:3.11-slim-bookworm AS python

# Python build stage
FROM python AS python-build-stage

# Install apt packages
RUN apt-get update && apt-get install --no-install-recommends -y \
# dependencies for building Python packages
build-essential \
# psycopg dependencies
libpq-dev

# Requirements are installed here to ensure they will be cached.
COPY ./requirements .

# Create Python Dependency and Sub-Dependency Wheels.
RUN pip wheel --wheel-dir /usr/src/app/wheels \
-r development.txt

# Python 'run' stage
FROM python AS python-run-stage
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim

ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
Expand All @@ -29,46 +8,38 @@ WORKDIR /app
ARG NODE_MAJOR=20

RUN apt-get update \
&& apt-get install -y ca-certificates curl gnupg \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update \
&& apt-get install nodejs -y \
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
&& apt-get clean

# devcontainer dependencies and utils
RUN apt-get update && apt-get install --no-install-recommends -y \
sudo git bash-completion nano ssh

# Create devcontainer user and add it to sudoers
&& apt-get install -y --no-install-recommends \
# Node.js dependencies
ca-certificates curl gnupg \
# devcontainer dependencies
sudo git bash-completion nano ssh \
# psycopg dependencies
libpq-dev \
wait-for-it \
# Translations dependencies
gettext \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends nodejs \
# Cleanup
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
&& apt-get clean

# Create devcontainer user
RUN groupadd --gid 1000 dev-user \
&& useradd --uid 1000 --gid dev-user --shell /bin/bash --create-home dev-user \
&& echo dev-user ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/dev-user \
&& chmod 0440 /etc/sudoers.d/dev-user

# Install required system dependencies
RUN apt-get update && apt-get install --no-install-recommends -y \
# psycopg dependencies
libpq-dev \
wait-for-it \
# Translations dependencies
gettext \
# cleaning up unused files
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/*
&& useradd --uid 1000 --gid dev-user --shell /bin/bash --create-home dev-user \
&& echo dev-user ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/dev-user \
&& chmod 0440 /etc/sudoers.d/dev-user

# All absolute dir copies ignore workdir instruction. All relative dir copies are wrt to the workdir instruction
# copy python dependency wheels from python-build-stage
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
COPY . .

# use wheels to install python dependencies
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
&& rm -rf /wheels/
# Install dependencies
RUN uv sync --locked --only-group dev

COPY ./compose/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

CMD ["/start"]
6 changes: 3 additions & 3 deletions compose/local/django/start
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ set -o errexit
set -o pipefail
set -o nounset

python manage.py migrate
python manage.py tailwind install
python manage.py runserver_plus 0.0.0.0:8000
uv run python manage.py migrate
uv run python manage.py tailwind install
uv run python manage.py runserver_plus 0.0.0.0:8000
4 changes: 2 additions & 2 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ x-app: &default-app
dockerfile: ./compose/local/django/Dockerfile
restart: unless-stopped
volumes:
- .:/app:z
- .:/app

services:
web:
Expand All @@ -22,7 +22,7 @@ services:
tailwind:
<<: *default-app
container_name: djangosnippets-tailwind-local
command: "python manage.py tailwind start"
command: "uv run python manage.py tailwind start"
# Without tty, no stdin, and tailwind watcher aborts
# https://github.com/tailwindlabs/tailwindcss/issues/5324
tty: true
Expand Down
61 changes: 61 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
[project]
name = "djangosnippets.org"
version = "1.0.0"
urls = {homepage = "https://github.com/django/djangosnippets.org"}
requires-python = ">=3.11"

[dependency-groups]
django = [
"dj-database-url",
"django",
"django-allauth",
"django-components",
"django-contrib-comments",
"django-generic-aggregation",
"django-htmx",
"django-ratelimit-backend",
"django-recaptcha",
"django-taggit",
"django-tailwind",
"djangorestframework",
]

base = [
{include-group = "django"},
"bleach",
"markdown",
"pillow",
"psycopg2-binary",
"pydantic",
"pygments",
"python-akismet",
"python-dotenv",
"requests",
"requests-oauthlib",
"six",
"urllib3",
"whitenoise",
]

dev = [
{include-group = "base"},
"werkzeug[watchdog]",
"ipython",
"django-extensions",
"ruff",
"pre-commit",
]

prod = [
{include-group = "base"},
"certifi",
"django-redis-cache",
"raven",
"redis",
"gunicorn",
"hiredis",
"sentry-sdk",
"gevent",
"greenlet",
]

[tool.ruff]
target-version = "py311"
line-length = 100
Expand Down
Loading