astral-sh / uv

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

Empty `UV_TOOL_DIR` and `UV_TOOL_DIR_BIN` environment variables treated differently #8608

Open NathanVaughn opened 2 weeks ago

NathanVaughn commented 2 weeks ago

Hello,

I noticed that uv treats the environment variables UV_TOOL_DIR and UV_TOOL_BIN_DIR differently when they exist, but are set to blank values. I was trying to make a devcontainer with some tools pre-installed by uv in a different directory, so that the user's home directory could be cached separately as a mounted volume. Simplified Dockerfile:

FROM ghcr.io/astral-sh/uv:0.4.27-python3.12-bookworm

ENV UV_TOOL_DIR=/opt/uv/tools
ENV UV_TOOL_BIN_DIR=/opt/uv/tools/bin

ENV PATH="$PATH:/root/.local/bin:/opt/uv/tools/bin"

RUN uv tool install cowsay

ENV UV_TOOL_DIR=""
ENV UV_TOOL_BIN_DIR=""

Running unset UV_TOOL_DIR doesn't do anything in this context (see this thread), so I set the environment variables to a blank value instead.

Now, running the following commands get this output:

docker build -t test .

echo "Tool dir"
docker run --rm test uv tool dir
echo "Tool bin dir"
docker run --rm test uv tool dir --bin
$ ./test.sh 
Tool dir

Tool bin dir
/root/.local/bin

With uv tool dir returning a blank value, installing or running a tool now installs it in the current directory. However, uv tool dir --bin does what I would expect.

I believe this is a bug, and UV_TOOL_DIR set to a blank value should be treated as unset, and default to the fallback options like $HOME/.local/share/uv/tools on UNIX, as described at https://docs.astral.sh/uv/reference/cli/#uv-tool-dir

gaby commented 2 weeks ago

@NathanVaughn Do this instead:

ENV UV_TOOL_DIR=
ENV UV_TOOL_BIN_DIR=
NathanVaughn commented 2 weeks ago

I tried that as well and it has the same result. The easy fix is to just redefine it back to the default like

ENV UV_TOOL_DIR=/root/.local/share/uv/tools
ENV UV_TOOL_BIN_DIR=/root/.local/bin
gaby commented 2 weeks ago

Sounds like a bug to me then