From a3ed1d96283b2bb95edb8928967ddb7c2ea5df43 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Fri, 30 Jan 2026 12:12:42 -0600 Subject: [PATCH] Refactor for uv transition. --- .dockerignore | 1 - docker/DispatcharrBase | 14 ++++++++------ docker/entrypoint.sh | 6 +++--- docker/init/99-init-dev.sh | 4 ++-- pyproject.toml | 7 +++++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.dockerignore b/.dockerignore index 296537de..002f1c63 100755 --- a/.dockerignore +++ b/.dockerignore @@ -29,6 +29,5 @@ **/secrets.dev.yaml **/values.dev.yaml LICENSE -README.md data/ docker/data/ diff --git a/docker/DispatcharrBase b/docker/DispatcharrBase index d89f334f..d2e8ceaa 100644 --- a/docker/DispatcharrBase +++ b/docker/DispatcharrBase @@ -1,6 +1,7 @@ FROM lscr.io/linuxserver/ffmpeg:latest ENV DEBIAN_FRONTEND=noninteractive +ENV UV_PROJECT_ENVIRONMENT=/dispatcharrpy ENV VIRTUAL_ENV=/dispatcharrpy ENV PATH="$VIRTUAL_ENV/bin:$PATH" ENV UV_COMPILE_BYTECODE=1 @@ -26,21 +27,22 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ # --- Create Python virtual environment and install dependencies --- WORKDIR /tmp/build COPY pyproject.toml /tmp/build/ -RUN uv venv $VIRTUAL_ENV --python 3.13 --seed && \ - uv sync --python $VIRTUAL_ENV/bin/python --no-cache --no-install-project --no-dev && \ +COPY version.py /tmp/build/ +COPY README.md /tmp/build/ +RUN uv sync --python 3.13 --no-cache --no-install-project --no-dev && \ rm -rf /tmp/build WORKDIR / # --- Build legacy NumPy wheel for old hardware (store for runtime switching) --- -RUN uv pip install --python $VIRTUAL_ENV/bin/python --no-cache build && \ +RUN uv pip install --python $UV_PROJECT_ENVIRONMENT/bin/python --no-cache build pip && \ cd /tmp && \ - $VIRTUAL_ENV/bin/pip download --no-binary numpy --no-deps numpy && \ + $UV_PROJECT_ENVIRONMENT/bin/python -m pip download --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" && \ + $UV_PROJECT_ENVIRONMENT/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 && \ - uv pip uninstall --python $VIRTUAL_ENV/bin/python build + uv pip uninstall --python $UV_PROJECT_ENVIRONMENT/bin/python build pip # --- 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 && \ diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index a50f2f49..ff8a193f 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -30,9 +30,9 @@ echo_with_timestamp() { # --- NumPy version switching for legacy hardware --- if [ "$USE_LEGACY_NUMPY" = "true" ]; then # Check if NumPy was compiled with baseline support - if /dispatcharrpy/bin/python -c "import numpy; numpy.show_config()" 2>&1 | grep -qi "baseline"; then + if $VIRTUAL_ENV/bin/python -c "import numpy; numpy.show_config()" 2>&1 | grep -qi "baseline"; then echo_with_timestamp "🔧 Switching to legacy NumPy (no CPU baseline)..." - /dispatcharrpy/bin/pip install --no-cache-dir --force-reinstall --no-deps /opt/numpy-*.whl + uv pip install --python $VIRTUAL_ENV/bin/python --no-cache --force-reinstall --no-deps /opt/numpy-*.whl echo_with_timestamp "✅ Legacy NumPy installed" else echo_with_timestamp "✅ Legacy NumPy (no baseline) already installed, skipping reinstallation" @@ -214,7 +214,7 @@ fi # Users can override via UWSGI_NICE_LEVEL environment variable in docker-compose # Start with nice as root, then use setpriv to drop privileges to dispatch user # This preserves both the nice value and environment variables -nice -n $UWSGI_NICE_LEVEL su - "$POSTGRES_USER" -c "cd /app && exec /dispatcharrpy/bin/uwsgi $uwsgi_args" & uwsgi_pid=$! +nice -n $UWSGI_NICE_LEVEL su - "$POSTGRES_USER" -c "cd /app && exec $VIRTUAL_ENV/bin/uwsgi $uwsgi_args" & uwsgi_pid=$! echo "✅ uwsgi started with PID $uwsgi_pid (nice $UWSGI_NICE_LEVEL)" pids+=("$uwsgi_pid") diff --git a/docker/init/99-init-dev.sh b/docker/init/99-init-dev.sh index c89f1e44..5afbc96d 100644 --- a/docker/init/99-init-dev.sh +++ b/docker/init/99-init-dev.sh @@ -16,10 +16,10 @@ fi # Install frontend dependencies cd /app/frontend && npm install # Install Python dependencies using UV -cd /app && uv sync --python $VIRTUAL_ENV/bin/python --no-install-project --no-dev +cd /app && uv sync --python $UV_PROJECT_ENVIRONMENT/bin/python --no-install-project --no-dev # Install debugpy for remote debugging if [ "$DISPATCHARR_DEBUG" = "true" ]; then echo "=== setting up debugpy ===" - uv pip install --python $VIRTUAL_ENV/bin/python debugpy + uv pip install --python $UV_PROJECT_ENVIRONMENT/bin/python debugpy fi diff --git a/pyproject.toml b/pyproject.toml index bdd056cc..9400a55d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [project] name = "dispatcharr" -version = "0.17.0" description = "Dispatcharr - Stream dispatching and management" readme = "README.md" -license = "MIT" +license = "CC-BY-NC-SA-4.0" requires-python = ">=3.13" +dynamic = ["version"] dependencies = [ "Django==5.2.9", "psycopg2-binary==2.9.11", @@ -51,3 +51,6 @@ torch = { index = "pytorch-cpu" } [tool.hatch.build.targets.wheel] packages = ["dispatcharr", "apps", "core"] + +[tool.hatch.version] +path = "version.py"