Open wimglenn opened 2 months ago
Hmm, I think it's arguably unclear what we should use here. I would find it more dangerous that the environment variable (which is presumedly set by the user) is ignored, and the one in a requirements.txt
in a file was picked up (which could be from another project or similar). But I can see an argument either way. I'd rather document this as an incompatibility than change it though, I think.
Below, I'm intending to convince you that retaining compatibility with pip is a better choice than documenting as an incompatibility.
Consider when there is a custom default index set. This is pretty common in corporate environments, where PyPI packages may need to be cached, whitelisted or shadowed with patched versions, e.g. by using an internal devpi-server.
The custom index is set as the default index (for all users) by /etc/pip.conf
file, owned by root and placed by sysadmin or config mgmt. Now, uv doesn't look at /etc/pip.conf
, ~nor allow a global default configuration~ (no longer true since uv 0.4.26 #7851), only considers the user's ~/.config/uv/uv.toml
- so this is only an option to set a default index for pip.
The next-best option for the sysadmin to put a sensible default index for uv would probably be setting UV_INDEX_URL
(perhaps in /etc/environment
, or by wrapping the uv executable).
However, if the UV_INDEX_URL
takes precedence over the index specified by requirements files, that's an unfortunate situation - users would have to unset the env var (which they might not even know about) to allow using the index which the requirements file was attempting to provide.
As I mentioned earlier, the simple failure mode is that packages are not found, but the more confusing and hard-to-debug failure mode is if the installation succeeds but uses the wrong packages (because it was using the wrong index). Switching from pip
to uv pip
should not be so error-prone.
The failure mode I describe might sound like a weird edge-case, but could actually be quite common especially with devpi-server, where "team-specific" indices could inherit and mirror a default index, to host a mix of their own/patched local versions layered over the default versions.
... and the one in a
requirements.txt
in a file was picked up (which could be from another project or similar).
I'm not sure what you mean here? Unless I'm mistaken, it is part of the requirements file format that the file can control the index-url. This is not dangerous, because requirements files and their custom indices can not be used during dependency resolving from some other top-level installation candidate. The requirements file would have been installed directly with -r
. At least, it's not any more dangerous than a direct url requirement, as specified in PEP 508.
If an index url has been specified directly in the requirements file using
-i
or--index-url
, this should have precedence over env var.Currently uv will use UV_INDEX_URL if it's set, and ignore the one in the requirements file. Reproducer:
This is in contrast to pip, where the index url from environment is lower priority to the cmd:
This makes
uv
+ UV_INDEX_URL somewhat dangerous to use as a drop-in replacement forpip
+ PIP_INDEX_URL. A failure to install is not the worst scenario, the worst is that you succeed to install potentially totally different packages from a totally different index (note: checksums in the reqs file could protect you from that).