feat: migrate to UV

This commit is contained in:
Tobias Effner 2026-01-23 22:45:37 +01:00
parent 8521df94ad
commit c698916a60
8 changed files with 2190 additions and 52 deletions

View file

@ -6,13 +6,13 @@ on:
paths:
- 'docker/DispatcharrBase'
- '.github/workflows/base-image.yml'
- 'requirements.txt'
- 'pyproject.toml'
pull_request:
branches: [main, dev]
paths:
- 'docker/DispatcharrBase'
- '.github/workflows/base-image.yml'
- 'requirements.txt'
- 'pyproject.toml'
workflow_dispatch: # Allow manual triggering
permissions:

1
.python-version Normal file
View file

@ -0,0 +1 @@
3.13

View file

@ -160,15 +160,28 @@ EOSU
# 6) Setup Python Environment
##############################################################################
install_uv() {
echo ">>> Installing UV package manager..."
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
}
setup_python_env() {
echo ">>> Setting up Python virtual environment..."
echo ">>> Setting up Python virtual environment with UV..."
# Install UV globally first
install_uv
su - "$DISPATCH_USER" <<EOSU
cd "$APP_DIR"
$PYTHON_BIN -m venv env
source env/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install gunicorn
export PATH="\$HOME/.local/bin:\$PATH"
# Install UV for the dispatch user if not already available
if ! command -v uv &> /dev/null; then
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="\$HOME/.local/bin:\$PATH"
fi
# Create venv and install dependencies using UV
uv venv env --python $PYTHON_BIN
uv sync --python env/bin/python --no-install-project --no-dev
EOSU
ln -sf /usr/bin/ffmpeg "$APP_DIR/env/bin/ffmpeg"
}

View file

@ -3,6 +3,8 @@ FROM lscr.io/linuxserver/ffmpeg:latest
ENV DEBIAN_FRONTEND=noninteractive
ENV VIRTUAL_ENV=/dispatcharrpy
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
# --- Install Python 3.13 and build dependencies ---
# Note: Hardware acceleration (VA-API, VDPAU, NVENC) already included in base ffmpeg image
@ -18,24 +20,27 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
vlc-bin vlc-plugin-base \
build-essential gcc g++ gfortran libopenblas-dev libopenblas0 ninja-build
# --- Create Python virtual environment ---
RUN python3.13 -m venv $VIRTUAL_ENV && $VIRTUAL_ENV/bin/pip install --upgrade pip
# --- Install UV ---
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# --- Install Python dependencies ---
COPY requirements.txt /tmp/requirements.txt
RUN $VIRTUAL_ENV/bin/pip install --no-cache-dir -r /tmp/requirements.txt && \
rm /tmp/requirements.txt
# --- Create Python virtual environment and install dependencies ---
WORKDIR /tmp/build
COPY pyproject.toml /tmp/build/
RUN uv venv $VIRTUAL_ENV --python 3.13 && \
uv sync --python $VIRTUAL_ENV/bin/python --no-cache --no-install-project --no-dev && \
rm -rf /tmp/build
WORKDIR /
# --- Build legacy NumPy wheel for old hardware (store for runtime switching) ---
RUN $VIRTUAL_ENV/bin/pip install --no-cache-dir build && \
RUN uv pip install --python $VIRTUAL_ENV/bin/python --no-cache build && \
cd /tmp && \
$VIRTUAL_ENV/bin/pip download --no-binary numpy --no-deps numpy && \
uv pip download --python $VIRTUAL_ENV/bin/python --no-binary numpy --no-deps numpy && \
tar -xzf numpy-*.tar.gz && \
cd numpy-*/ && \
$VIRTUAL_ENV/bin/python -m build --wheel -Csetup-args=-Dcpu-baseline="none" -Csetup-args=-Dcpu-dispatch="none" && \
mv dist/*.whl /opt/ && \
cd / && rm -rf /tmp/numpy-* /tmp/*.tar.gz && \
$VIRTUAL_ENV/bin/pip uninstall -y build
uv pip uninstall --python $VIRTUAL_ENV/bin/python build
# --- Clean up build dependencies to reduce image size ---
RUN apt-get remove -y build-essential gcc g++ gfortran libopenblas-dev libpcre3-dev python3.13-dev ninja-build && \

View file

@ -15,11 +15,11 @@ fi
# Install frontend dependencies
cd /app/frontend && npm install
# Install pip dependencies
cd /app && pip install -r requirements.txt
# Install Python dependencies using UV
cd /app && uv sync --python $VIRTUAL_ENV/bin/python --no-install-project --no-dev
# Install debugpy for remote debugging
if [ "$DISPATCHARR_DEBUG" = "true" ]; then
echo "=== setting up debugpy ==="
pip install debugpy
uv pip install --python $VIRTUAL_ENV/bin/python debugpy
fi

53
pyproject.toml Normal file
View file

@ -0,0 +1,53 @@
[project]
name = "dispatcharr"
version = "0.17.0"
description = "Dispatcharr - Stream dispatching and management"
readme = "README.md"
license = "MIT"
requires-python = ">=3.13"
dependencies = [
"Django==5.2.9",
"psycopg2-binary==2.9.11",
"celery[redis]==5.6.0",
"djangorestframework==3.16.1",
"requests==2.32.5",
"psutil==7.1.3",
"pillow",
"drf-yasg>=1.21.11",
"streamlink",
"python-vlc",
"yt-dlp",
"gevent==25.9.1",
"daphne",
"uwsgi",
"django-cors-headers",
"djangorestframework-simplejwt",
"m3u8",
"rapidfuzz==3.14.3",
"regex",
"tzlocal",
"torch==2.9.1+cpu",
"sentence-transformers==5.2.0",
"channels",
"channels-redis==4.3.0",
"django-filter",
"django-celery-beat",
"lxml==6.0.2",
"gunicorn",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
# PyTorch CPU-only wheels index
[[tool.uv.index]]
url = "https://download.pytorch.org/whl/cpu"
name = "pytorch-cpu"
explicit = true
[tool.uv.sources]
torch = { index = "pytorch-cpu" }
[tool.hatch.build.targets.wheel]
packages = ["dispatcharr", "apps", "core"]

View file

@ -1,32 +0,0 @@
Django==5.2.9
psycopg2-binary==2.9.11
celery[redis]==5.6.0
djangorestframework==3.16.1
requests==2.32.5
psutil==7.1.3
pillow
drf-yasg>=1.21.11
streamlink
python-vlc
yt-dlp
gevent==25.9.1
daphne
uwsgi
django-cors-headers
djangorestframework-simplejwt
m3u8
rapidfuzz==3.14.3
regex # Required by transformers but also used for advanced regex features
tzlocal
# PyTorch dependencies (CPU only)
--extra-index-url https://download.pytorch.org/whl/cpu/
torch==2.9.1+cpu
# ML/NLP dependencies
sentence-transformers==5.2.0
channels
channels-redis==4.3.0
django-filter
django-celery-beat
lxml==6.0.2

2098
uv.lock generated Normal file

File diff suppressed because it is too large Load diff