Skip to content

Commit b8b02e2

Browse files
committed
Working uv + Ubuntu24 setup
- Tox config in pyproject.toml (run with tox-uv) - In docker, uv has its own isolated environment (at /.venv) - Remove old requirements files (use uv.lock)
1 parent b40c4c1 commit b8b02e2

File tree

27 files changed

+170
-3249
lines changed

27 files changed

+170
-3249
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ jobs:
1919
python-version: "3.12"
2020

2121
- name: Install dependencies
22-
run: uv sync --frozen --all-extras
22+
run: |
23+
uv sync --frozen --all-extras
24+
uv tool install tox --with tox-uv
2325
2426
- name: Run CI
2527
run: |

.github/workflows/pip-tools.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
Dependencies: all packages updated via uv lock
4545
body: |
4646
Dependencies: all packages updated via uv lock
47-
47+
4848
This PR updates the `uv.lock` file with the latest compatible versions
4949
of all dependencies specified in `pyproject.toml`.
5050
commit-message: |

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repos:
77
- id: trailing-whitespace
88
exclude: '.*/dnt-policy.txt$'
99
- repo: https://github.com/adamchainz/django-upgrade
10-
rev: "1.14.1"
10+
rev: "1.29.1"
1111
hooks:
1212
- id: django-upgrade
1313
args: [--target-version, "5.2"]

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ help:
1818
@echo " geoip Download the GeoIP databases"
1919
@echo " ipproxy Download proxy databases"
2020

21+
# Run the full test suite
22+
# Run a specific test with tox -e py3 -- adserver/auth/tests.py
2123
test:
2224
tox
2325

@@ -46,11 +48,11 @@ dockerstop:
4648
# Use this command to inspect the container, run management commands,
4749
# or run anything else on the Django container
4850
dockershell:
49-
docker compose -f $(DOCKER_CONFIG) run --rm django /bin/bash
51+
docker compose -f $(DOCKER_CONFIG) run --rm django /shell
5052

5153
# Get the GeoIP databases from DB-IP or Maxmind
5254
geoip:
53-
python $(GEOIP_DOWNLOADER) --geoip-only --outdir=$(GEOIP_DIR)
55+
uv run python $(GEOIP_DOWNLOADER) --geoip-only --outdir=$(GEOIP_DIR)
5456

5557
ipproxy:
56-
python $(GEOIP_DOWNLOADER) --ipproxy-only --outdir=$(GEOIP_DIR)
58+
uv run python $(GEOIP_DOWNLOADER) --ipproxy-only --outdir=$(GEOIP_DIR)

docker-compose/django/Dockerfile

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ ENV LANGUAGE en_US:en
66
ENV LC_ALL en_US.UTF-8
77
ENV PYTHONUNBUFFERED 1
88

9+
# uv environment variables
10+
# Copy (don't hardlink) files into /.venv. Avoid issues with Docker's FS
11+
# https://docs.astral.sh/uv/reference/environment/
12+
ENV UV_LINK_MODE=copy
13+
ENV UV_PYTHON_DOWNLOADS=never
14+
ENV UV_PROJECT_ENVIRONMENT=/.venv
15+
16+
# Pep668 prevents pip from modifying system packages
17+
# https://peps.python.org/pep-0668/
18+
ENV PIP_BREAK_SYSTEM_PACKAGES=1
19+
920
RUN apt-get -y update
1021
RUN apt-get -y install \
1122
curl \
@@ -23,45 +34,47 @@ RUN apt-get -y install \
2334
libmysqlclient-dev \
2435
libfreetype6 \
2536
libjpeg-dev \
26-
sqlite \
37+
sqlite3 \
2738
netcat-openbsd \
2839
telnet \
2940
lsb-release
3041

3142
# Install uv for fast package management
32-
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
33-
ENV PATH="/root/.cargo/bin:${PATH}"
43+
# https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
44+
ADD https://astral.sh/uv/install.sh /uv-installer.sh
45+
RUN sh /uv-installer.sh && rm /uv-installer.sh
46+
ENV PATH="/root/.local/bin/:$PATH"
3447

3548
# Copy project files for dependency resolution
3649
# uv.lock ensures reproducible builds
3750
COPY pyproject.toml uv.lock ./
3851

3952
# Install dependencies using uv sync
53+
# This creates a virtual environment at /.venv (not in /app)
4054
# This installs all dependencies from uv.lock, ensuring consistency
4155
# --frozen: Don't update the lockfile
42-
# --no-install-project: Don't install the project itself (we'll copy source later)
43-
# By default, installs base dependencies + dev group (for development container)
56+
# --no-install-project: Don't install the project itself
57+
# If you do not want the analyzer dependencies (which are LARGE), you can use:
58+
# RUN --mount=type=cache,target=/root/.cache/uv \
59+
# uv sync --frozen --no-install-project --extra dev --extra production
4460
RUN --mount=type=cache,target=/root/.cache/uv \
4561
uv sync --frozen --no-install-project --all-extras
4662

47-
# For production builds, you can use:
48-
# RUN --mount=type=cache,target=/root/.cache/uv \
49-
# uv sync --frozen --no-install-project --no-dev --extra production --extra analyzer
50-
5163
COPY ./docker-compose/django/start /start
5264
RUN chmod +x /start
5365

66+
# Launch a shell within the container with this script
67+
COPY ./docker-compose/django/shell /shell
68+
RUN chmod +x /shell
69+
5470
COPY ./docker-compose/django/celery/worker/start /start-celeryworker
5571
RUN chmod +x /start-celeryworker
5672

5773
COPY ./docker-compose/django/celery/beat/start /start-celerybeat
5874
RUN chmod +x /start-celerybeat
5975

60-
# Ensure that ``python`` is in the PATH so that ``./manage.py`` works
61-
RUN ln -s /usr/bin/python3 /usr/bin/python
62-
6376
# Load model
64-
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('multi-qa-MiniLM-L6-cos-v1', cache_folder='/tmp/sentence_transformers')"
77+
RUN uv run python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('multi-qa-MiniLM-L6-cos-v1', cache_folder='/tmp/sentence_transformers')"
6578

6679
# Setup the locale
6780
RUN locale-gen en_US.UTF-8

docker-compose/django/celery/beat/start

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -o nounset
55

66

77
rm -f './celerybeat.pid'
8-
celery -A config.celery_app beat -l INFO
8+
uv run celery -A config.celery_app beat -l INFO

docker-compose/django/celery/worker/start

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -o errexit
44
set -o nounset
55

66

7-
celery -A config.celery_app worker -l INFO -Q celery,analyzer,priority -c 1
7+
uv run celery -A config.celery_app worker -l INFO -Q celery,analyzer,priority -c 1

docker-compose/django/shell

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
8+
# Use the venv created by `uv sync` in the Dockerfile
9+
source /.venv/bin/activate
10+
11+
# Start shell with the venv activated
12+
/bin/bash

docker-compose/django/start

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ set -o errexit
44
set -o pipefail
55
set -o nounset
66

7+
78
# Reinstall dependencies without rebuilding docker image
89
# pip install -r /app/requirements/development.txt
910

1011
# Don't auto-migrate locally because this can cause weird issues when testing migrations
1112
# python manage.py migrate
12-
python manage.py runserver 0.0.0.0:5000
13+
uv run ./manage.py runserver 0.0.0.0:5000
1314

1415
# In production, we use gunicorn
1516
# This gets us close to that setting for development and testing

docs/developer/quickstart.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Requirements
4444
~~~~~~~~~~~~
4545

4646
- Python 3.12
47-
- Nodejs (tested with v14)
47+
- Nodejs (tested with v20)
4848

4949
Front-end assets
5050
~~~~~~~~~~~~~~~~
@@ -67,8 +67,8 @@ Then install dependencies:
6767

6868
.. code-block:: bash
6969
70-
$ uv sync --all-extras # Install all dependencies including dev tools
71-
$ pre-commit install # Install a code style pre-commit hook
70+
$ uv sync --all-extras # Install all dependencies including dev tools
71+
$ uv run pre-commit install # Install a code style pre-commit hook
7272
7373
Run the server
7474
~~~~~~~~~~~~~~
@@ -77,19 +77,19 @@ Run migrations:
7777

7878
.. code-block:: bash
7979
80-
$ uv run python manage.py migrate
80+
$ uv run ./manage.py migrate
8181
8282
Create a superuser:
8383

8484
.. code-block:: bash
8585
86-
$ uv run python manage.py createsuperuser
86+
$ uv run ./manage.py createsuperuser
8787
8888
Run the server:
8989

9090
.. code-block:: bash
9191
92-
$ uv run python manage.py runserver
92+
$ uv run ./manage.py runserver
9393
9494
Running the tests
9595
-----------------
@@ -98,8 +98,8 @@ To run the unit tests:
9898

9999
.. code-block:: bash
100100
101-
$ uv sync --all-extras # If not already installed
102-
$ make test
101+
$ uv tool install tox --with tox-uv
102+
$ tox
103103
104104
Run a specific test:
105105

0 commit comments

Comments
 (0)