astral-sh / uv

An extremely fast Python package installer and resolver, written in Rust.
https://astral.sh/
Apache License 2.0
11.75k stars 322 forks source link

Setting UV_CACHE_DIR on Windows causes "error: The system cannot find the path specified. (os error 3)" #3280

Closed gozdal closed 2 weeks ago

gozdal commented 2 weeks ago

I am trying to work around another issue in concurrently using the same cache directory by setting UV_CACHE_DIR. If I do

set UV_CACHE_DIR=%LOCALAPPDATA%\uv\cache-foo && uv venv --help

I correctly see

      --cache-dir <CACHE_DIR>
          Path to the cache directory.

          Defaults to `$HOME/Library/Caches/uv` on macOS, `$XDG_CACHE_HOME/uv` or `$HOME/.cache/uv` on Linux, and
          `$HOME/.cache/<project_path> {FOLDERID_LocalAppData}/<project_path>/cache/uv` on Windows.

          [env: UV_CACHE_DIR=C:\Users\foo\AppData\Local\uv\cache-foo ]

However, if I want to create a venv I get: set UV_CACHE_DIR=%LOCALAPPDATA%\uv\cache-foo && uv venv venv

error: The system cannot find the path specified. (os error 3)

uv 0.1.33 (2cee7525c 2024-04-17), on Windows Server 2016 and 2022

konstin commented 2 weeks ago

You've hit an interesting edge case: The path contains a trailing space, where we can create the directory, but writing a file joined to that directory fails.

3304 should make this clearer in the error message:

error: failed to open file `C:\Users\Konstantin\AppData\Local\uv\cache-foo \CACHEDIR.TAG`
  Caused by: The system cannot find the path specified. (os error 3)
gozdal commented 2 weeks ago

That's interesting, wouldn't think that set foo=bar && cmd would set foo=bar with a space at the end?