uv
uv copied to clipboard
Respect XDG specification on Windows
Summary
Now uv for some reason ignores XDG variables when installing in windows and needs to manually set uv_* environment variables.
It would be nice if windows also used XDG_*_Home variables (for example as in mise).
But it is interesting that XDG_BIN_HOME - still works in windows, although with an error.
Related:
- https://docs.astral.sh/uv/reference/cli/#uv-tool-dir
- https://docs.astral.sh/uv/configuration/installer/#changing-the-install-path
- https://docs.astral.sh/uv/configuration/environment/#xdg_bin_home
- https://github.com/astral-sh/uv/issues/9985
- https://github.com/astral-sh/uv/issues/7008
- https://github.com/astral-sh/uv/issues/5746
XDG_DATA_HOME,XDG_CONFIG_HOME,XDG_CACHE_HOME
Example
uv uses the XDG specification just as in macos/linux
We probably shouldn't read XDG_BIN_HOME on Windows for consistency, CC @zanieb
https://github.com/astral-sh/uv/blob/797f1fbac0d5cc6820709d4703bbf3cd1569176c/crates/uv-dirs/src/lib.rs#L28-L33
I think it's more likely that we keep with the Windows native paths over using XDG, but either way we decide I think we should do it consistently.
There is no equivalent tool binary directory on Windows so we are using the XDG location as done in pipx. I think pipx just hard-codes %USERPROFILE%\.local\bin though, but I'd prefer to consistently respect XDG_BIN_HOME — I think it'd be more confusing not to.
If the XDG_* variables are set and map clearly to the Windows native path concepts, I don't really see a compelling reason to ignore them on Windows really. Though, of course, we should use the native paths by default.
Makes sense!
I agree that it would probably be good to just respect XDG if it happens to be set on windows -- it's pretty hard for those to be accidentally set!
There is no equivalent tool binary directory on Windows
Yes, there is: FOLDERID_UserProgramFiles. I also wrote about that here and mentioned you.
Source: https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid
Furthermore, for anyone's interest:
Applications should not create files or folders [in the user's profile folder]; they should put their data under the locations referred to by ApplicationData.
Source: https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-6.0
Yes, there is: FOLDERID_UserProgramFiles
Yes, I've seen your comment there and appreciate your suggestions. However, that's not a single directory shared across programs and expected to be present on the PATH. Rather the suggestion is to do something like %LOCALAPPDATA%\Programs\uv\scripts and add it to the PATH. We could do that, but it's not a direct equivalent to the XDG_BIN_HOME.
However, that's not a single directory shared across programs and expected to be present on the PATH.
Yes, you are right that there is no directory equivalent to ~/.local/bin on Windows. Reading the comment again, I think I did mistunderstand your intention a bit.