astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
21.31k stars 624 forks source link

Allow setting `site-packages` root for `uv sync` instead of using venv's #7659

Open Kamillaova opened 4 days ago

Kamillaova commented 4 days ago

It would be nice if uv sync (and similar commands) supported the setting site-packages root (for installation of the pep582 type), instead of using venv.

Previously (with rye), I used uv pip install --system --target pkgs

My old (with rye) `Dockerfile`s are like this: ```dockerfile # syntax=docker/dockerfile:labs ARG PYTHON=3.12 ARG DEBIAN_RELEASE=bullseye ARG BASE_IMAGE=docker.io/python:${PYTHON}-${DEBIAN_RELEASE} ARG UV=0.2.34 FROM ghcr.io/astral-sh/uv:${UV} AS uv FROM ${BASE_IMAGE} AS final ENV PYTHONUNBUFFERED=1 ENV PYTHONFAULTHANDLER=1 ENV PYTHONDONTWRITEBYTECODE=1 ENV HF_HUB_ENABLE_HF_TRANSFER=1 WORKDIR /app RUN --mount=from=uv,source=/uv,target=/uv \ --mount=target=/uv-cache,type=cache,mode=0777,sharing=shared \ --mount=source=requirements.lock,target=requirements.lock \ set -eux ;\ \ sed -e '/-e/d;' -e '/--index-url/d' requirements.lock | \ /uv pip install -v --link-mode=copy --cache-dir=/uv-cache --system --target pkgs -r /dev/stdin ENV PYTHONPATH=/app/pkgs COPY src/launch.sh /launch.sh COPY src/Censored ./censored ENTRYPOINT [ "/launch.sh" ] ```
My new (with uv as PM) `Dockerfile`s are like this: ```dockerfile # syntax=docker/dockerfile:labs ARG PYTHON=3.12 ARG DEBIAN_RELEASE=bullseye ARG BASE_IMAGE=docker.io/python:${PYTHON}-slim-${DEBIAN_RELEASE} ARG UV=0.4.15 FROM ghcr.io/astral-sh/uv:${UV} AS uv FROM ${BASE_IMAGE} AS final ENV PYTHONUNBUFFERED=1 ENV PYTHONFAULTHANDLER=1 ENV PYTHONDONTWRITEBYTECODE=1 WORKDIR /app RUN --mount=from=uv,source=/uv,target=/uv \ --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ --mount=type=cache,target=/uv-cache,mode=0777,sharing=shared \ \ /uv sync -v --link-mode=copy --cache-dir=/uv-cache --frozen --no-install-project COPY src/launch.sh /launch.sh RUN --mount=from=uv,source=/uv,target=/uv \ --mount=source=src,target=src \ --mount=source=uv.lock,target=uv.lock \ --mount=source=README.md,target=README.md \ --mount=source=pyproject.toml,target=pyproject.toml \ --mount=type=cache,target=/uv-cache,mode=0777,sharing=shared \ \ /uv sync -v --link-mode=copy --cache-dir=/uv-cache --frozen --no-editable ENTRYPOINT [ "/launch.sh" ] ```

So previously my images didn't have venv, just custom site-packages which is specified via the PYTHONPATH environment variable. Now they have venv. This is not great and I don't like it.

zanieb commented 4 days ago

Please see https://docs.astral.sh/uv/concepts/projects/#configuring-the-project-environment-path which allows you to change the target of uv sync.

Note that "not great and I don't like it" isn't enough detail for us to actually change things for you; you'd need to explain why a virtual environment is a problem.