Skip to content

Commit d6a494b

Browse files
committed
Migrate from pip to uv for dependency management.
1 parent 8c21daa commit d6a494b

File tree

11 files changed

+1760
-176
lines changed

11 files changed

+1760
-176
lines changed

.github/dependabot.yml

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,31 @@
11
version: 2
22
updates:
3-
- package-ecosystem: pip
4-
directory: "/"
5-
schedule:
6-
interval: monthly
7-
time: "11:00"
8-
open-pull-requests-limit: 10
9-
ignore:
10-
- dependency-name: elasticsearch
11-
versions:
12-
- ">= 7.a, < 8"
13-
- dependency-name: gevent
14-
versions:
15-
- ">= 21.a, < 22"
16-
- dependency-name: greenlet
17-
versions:
18-
- 1.0.0
19-
- dependency-name: django
20-
versions:
21-
- 2.2.18
22-
- 2.2.19
23-
- dependency-name: pygments
24-
versions:
25-
- 2.7.4
26-
- 2.8.0
27-
- dependency-name: bleach
28-
versions:
29-
- 3.2.3
30-
- dependency-name: urllib3
31-
versions:
32-
- 1.26.3
33-
- dependency-name: pillow
34-
versions:
35-
- 8.1.0
36-
- dependency-name: gevent
37-
versions:
38-
- 20.12.1
39-
- dependency-name: django-contrib-comments
40-
versions:
41-
- 2.0.0
3+
4+
- package-ecosystem: "uv"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
groups:
9+
python-dependencies:
10+
patterns:
11+
- "*"
12+
13+
- package-ecosystem: "npm"
14+
directory: "theme/static_src/"
15+
schedule:
16+
interval: "weekly"
17+
groups:
18+
npm-dependencies:
19+
patterns:
20+
- "*"
21+
22+
# Update GitHub actions in workflows
23+
- package-ecosystem: "github-actions"
24+
directory: "/"
25+
# Every week
26+
schedule:
27+
interval: "weekly"
28+
groups:
29+
github-actions:
30+
patterns:
31+
- "*"

.github/workflows/pythonpackage.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,13 @@ jobs:
3535
uses: actions/setup-python@v1
3636
with:
3737
python-version: ${{ matrix.python-version }}
38-
- name: Install dependencies
39-
run: |
40-
python -m pip install --upgrade pip
41-
pip install -r requirements/production.txt
42-
- name: Install Linter
43-
run: |
44-
pip install ruff
45-
ruff check .
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v6
40+
- name: Install the project
41+
run: uv sync --locked --only-group dev
4642
- name: Run migrations
47-
run: python manage.py migrate
43+
run: uv run python manage.py migrate
4844
- name: Collect static files
49-
run: python manage.py collectstatic --no-input
45+
run: uv run python manage.py collectstatic --no-input
5046
- name: Run Tests
51-
run: python manage.py test --settings=djangosnippets.settings.testing
47+
run: uv run python manage.py test --settings=djangosnippets.settings.testing

README.rst

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Prerequisites
1111

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

1516
Installation
1617
------------
@@ -24,23 +25,15 @@ Basic Installation
2425
2526
https://github.com/django/djangosnippets.org.git
2627
27-
2. Create your virtual environment:
28-
29-
.. code-block:: console
30-
31-
python -m venv venv
32-
33-
Activate in Linux:
34-
35-
.. code-block:: console
36-
37-
source venv/bin/activate
38-
39-
Activate in Windows:
40-
28+
2. Install uv if you haven't already:
4129
.. code-block:: console
30+
# macOS
31+
curl -LsSf https://astral.sh/uv/install.sh | sh
32+
# Window
33+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
4234
43-
venv\Scripts\activate
35+
.. [!NOTE]::
36+
For detailed instructions on installing uv, please refer to this [document](https://docs.astral.sh/uv/getting-started/installation/).
4437

4538
3. Connect to PostgreSQL
4639

@@ -70,11 +63,11 @@ Basic Installation
7063
7164
postgres=# exit
7265
73-
5. Install requirements:
66+
5. Install dependencies:
7467

7568
.. code-block:: console
7669
77-
pip install -r requirements/development.txt
70+
uv sync --only-group dev
7871
7972
6. Copy `.env.template.local` file, rename to `.env` and configure variables for your local postgres database.
8073

@@ -96,37 +89,37 @@ Basic Installation
9689

9790
.. code-block:: console
9891
99-
python manage.py migrate
92+
uv run python manage.py migrate
10093
10194
Optionally load data first:
10295

10396
.. code-block:: console
10497
105-
python manage.py loaddata fixtures/cab.json
98+
uv run python manage.py loaddata fixtures/cab.json
10699
107100
Create superuser:
108101

109102
.. code-block:: console
110103
111-
python manage.py createsuperuser
104+
uv run python manage.py createsuperuser
112105
113106
8. Install tailwind (npm is required):
114107

115108
.. code-block:: console
116109
117-
python manage.py tailwind install
110+
uv run python manage.py tailwind install
118111
119112
9. Run server locally:
120113

121114
.. code-block:: console
122115
123-
python manage.py runserver_plus
116+
uv run python manage.py runserver_plus
124117
125118
10. Run tailwind in another terminal locally:
126119

127120
.. code-block:: console
128121
129-
python manage.py tailwind start
122+
uv run python manage.py tailwind start
130123
131124
With Docker
132125
~~~~~~~~~~~~~~~~~~~

compose/local/django/Dockerfile

Lines changed: 28 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,4 @@
1-
# define an alias for the specific python version used in this file.
2-
FROM docker.io/python:3.11-slim-bookworm AS python
3-
4-
# Python build stage
5-
FROM python AS python-build-stage
6-
7-
# Install apt packages
8-
RUN apt-get update && apt-get install --no-install-recommends -y \
9-
# dependencies for building Python packages
10-
build-essential \
11-
# psycopg dependencies
12-
libpq-dev
13-
14-
# Requirements are installed here to ensure they will be cached.
15-
COPY ./requirements .
16-
17-
# Create Python Dependency and Sub-Dependency Wheels.
18-
RUN pip wheel --wheel-dir /usr/src/app/wheels \
19-
-r development.txt
20-
21-
# Python 'run' stage
22-
FROM python AS python-run-stage
1+
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim
232

243
ENV PYTHONUNBUFFERED=1
254
ENV PYTHONDONTWRITEBYTECODE=1
@@ -29,46 +8,38 @@ WORKDIR /app
298
ARG NODE_MAJOR=20
309

3110
RUN apt-get update \
32-
&& apt-get install -y ca-certificates curl gnupg \
33-
&& mkdir -p /etc/apt/keyrings \
34-
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
35-
&& 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 \
36-
&& apt-get update \
37-
&& apt-get install nodejs -y \
38-
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
39-
&& apt-get clean
40-
41-
# devcontainer dependencies and utils
42-
RUN apt-get update && apt-get install --no-install-recommends -y \
43-
sudo git bash-completion nano ssh
44-
45-
# Create devcontainer user and add it to sudoers
11+
&& apt-get install -y --no-install-recommends \
12+
# Node.js dependencies
13+
ca-certificates curl gnupg \
14+
# devcontainer dependencies
15+
sudo git bash-completion nano ssh \
16+
# psycopg dependencies
17+
libpq-dev \
18+
wait-for-it \
19+
# Translations dependencies
20+
gettext \
21+
&& mkdir -p /etc/apt/keyrings \
22+
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
23+
&& 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 \
24+
&& apt-get update \
25+
&& apt-get install -y --no-install-recommends nodejs \
26+
# Cleanup
27+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
28+
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man \
29+
&& apt-get clean
30+
31+
# Create devcontainer user
4632
RUN groupadd --gid 1000 dev-user \
47-
&& useradd --uid 1000 --gid dev-user --shell /bin/bash --create-home dev-user \
48-
&& echo dev-user ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/dev-user \
49-
&& chmod 0440 /etc/sudoers.d/dev-user
50-
51-
# Install required system dependencies
52-
RUN apt-get update && apt-get install --no-install-recommends -y \
53-
# psycopg dependencies
54-
libpq-dev \
55-
wait-for-it \
56-
# Translations dependencies
57-
gettext \
58-
# cleaning up unused files
59-
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
60-
&& rm -rf /var/lib/apt/lists/*
33+
&& useradd --uid 1000 --gid dev-user --shell /bin/bash --create-home dev-user \
34+
&& echo dev-user ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/dev-user \
35+
&& chmod 0440 /etc/sudoers.d/dev-user
6136

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

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

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

7445
CMD ["/start"]

compose/local/django/start

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ set -o errexit
44
set -o pipefail
55
set -o nounset
66

7-
python manage.py migrate
8-
python manage.py tailwind install
9-
python manage.py runserver_plus 0.0.0.0:8000
7+
uv run python manage.py migrate
8+
uv run python manage.py tailwind install
9+
uv run python manage.py runserver_plus 0.0.0.0:8000

docker-compose.local.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ x-app: &default-app
66
dockerfile: ./compose/local/django/Dockerfile
77
restart: unless-stopped
88
volumes:
9-
- .:/app:z
9+
- .:/app
1010

1111
services:
1212
web:
@@ -22,7 +22,7 @@ services:
2222
tailwind:
2323
<<: *default-app
2424
container_name: djangosnippets-tailwind-local
25-
command: "python manage.py tailwind start"
25+
command: "uv run python manage.py tailwind start"
2626
# Without tty, no stdin, and tailwind watcher aborts
2727
# https://github.com/tailwindlabs/tailwindcss/issues/5324
2828
tty: true

pyproject.toml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,64 @@
1+
[project]
2+
name = "djangosnippets.org"
3+
version = "1.0.0"
4+
urls = {homepage = "https://github.com/django/djangosnippets.org"}
5+
requires-python = ">=3.11"
6+
7+
[dependency-groups]
8+
django = [
9+
"dj-database-url",
10+
"django",
11+
"django-allauth",
12+
"django-components",
13+
"django-contrib-comments",
14+
"django-generic-aggregation",
15+
"django-htmx",
16+
"django-ratelimit-backend",
17+
"django-recaptcha",
18+
"django-taggit",
19+
"django-tailwind",
20+
"djangorestframework",
21+
]
22+
23+
base = [
24+
{include-group = "django"},
25+
"bleach",
26+
"markdown",
27+
"pillow",
28+
"psycopg2-binary",
29+
"pydantic",
30+
"pygments",
31+
"python-akismet",
32+
"python-dotenv",
33+
"requests",
34+
"requests-oauthlib",
35+
"six",
36+
"urllib3",
37+
"whitenoise",
38+
]
39+
40+
dev = [
41+
{include-group = "base"},
42+
"werkzeug[watchdog]",
43+
"ipython",
44+
"django-extensions",
45+
"ruff",
46+
"pre-commit",
47+
]
48+
49+
prod = [
50+
{include-group = "base"},
51+
"certifi",
52+
"django-redis-cache",
53+
"raven",
54+
"redis",
55+
"gunicorn",
56+
"hiredis",
57+
"sentry-sdk",
58+
"gevent",
59+
"greenlet",
60+
]
61+
162
[tool.ruff]
263
target-version = "py311"
364
line-length = 100

0 commit comments

Comments
 (0)