uv icon indicating copy to clipboard operation
uv copied to clipboard

Support `UV_ONLY_BINARY` and `UV_NO_BINARY` environment variables

Open njzjz opened this issue 1 year ago • 2 comments

This is useful with cibuildwheel or some other complicated tools in the CI environment.

pip has similiar PIP_NO_BINARY and PIP_ONLY_BINARY: https://pip.pypa.io/en/latest/cli/pip_install/#cmdoption-no-binary

njzjz avatar Jun 12 '24 22:06 njzjz

I think we've avoided this because we're not interested in supporting the pip syntax outside of the pip interface. Maybe we could namespace them e.g. UV_PIP_NO_BINARY in the meantime?

zanieb avatar Jun 13 '24 00:06 zanieb

Some of them are available, though, like UV_CONSTRAINT, UV_INDEX_URL, UV_EXTRA_INDEX_URL, and UV_BREAK_SYSTEM_PACKAGES. I don't really care what it's called, but it would be nice to have, as you can't pass flags through inside cibuildwheel to every command.

henryiii avatar Aug 13 '24 03:08 henryiii

@zanieb Please consider that other package managers also support this, since it's a genuinely useful feature for containerized builds, and not just a Pip feature.

  • PDM
  • Poetry (no env var, but functionally somewhat equivalent persistent config).

sanmai-NL avatar Sep 24 '24 09:09 sanmai-NL

@sanmai-NL we do support this via persistent configuration, e.g.,

  • https://docs.astral.sh/uv/reference/settings/#no-binary
  • https://docs.astral.sh/uv/reference/settings/#no-binary-package
  • https://docs.astral.sh/uv/reference/settings/#no-build
  • https://docs.astral.sh/uv/reference/settings/#no-build-package

Since our top-level settings differ from pip (we don't use :all:, we have a dedicated flag instead), I'm not sure how best to introduce environment variables for this.

I guess:

UV_NO_BINARY=1
UV_NO_BINARY_PACKAGE="foo bar"

And uv pip users would need to use the new syntax too?

zanieb avatar Sep 24 '24 13:09 zanieb

Yeah, having environment variables available for this would be very useful for us. We have two different build environments we use, and neither of them make it particularly easy to add the --no-binary argument in the cases where we need it, but both make it really easy to add environment variables. I like @zanieb 's most recent suggestion for how to do it.

lengau avatar Feb 06 '25 15:02 lengau

I'm happy to review a contribution adding the variables described.

zanieb avatar Feb 06 '25 16:02 zanieb

I've added a version that handles build commands at https://github.com/astral-sh/uv/pull/11399.

Unfortunately, when doing so I noticed that the build commands and uv pip work somewhat differently, so I wanted to run my potential implementation up the flagpole before doing it.

The problem is that uv pip, like pip, has order-dependent instances of --no-binary and similar, and it does accept the special values of :all: and :none. My proposal therefore is to use a similar behaviour to how pip itself handles the environment variables, but to also handle the way uv pip handles them.

  1. If UV_NO_BINARY is true, uv pip commands treat that as equivalent to uv pip <cmd> --no-binary=:all: [...].
  2. If UV_NO_BINARY_PACKAGE is set, uv pip commands treat that as equivalent to uv pip <cmd> --no-binary=<package> [repeated for each unpacked package name] [...]

This is a special case only needed for pip commands because of how they work.

lengau avatar Feb 10 '25 20:02 lengau

Yeah we'd reuse the top-level uv semantics in uv pip, that sounds correct.

zanieb avatar Feb 10 '25 21:02 zanieb

Done in #11399

zanieb avatar Mar 05 '25 00:03 zanieb

Oops, not done — not handled in uv pip yet.

zanieb avatar Mar 05 '25 00:03 zanieb