astral-sh / uv

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

Add support for config_settings in requirements.txt / requirements.in #3636

Open tiptenbrink opened 1 month ago

tiptenbrink commented 1 month ago

In #1460, the CLI gained support for passing config_settings to the build backend. However, sometimes you want to pass these settings only for specific requirements (or simply you don't want to have to write it in the CLI each time).

If you use pip install -r requirements.txt, this is a valid line inside a requirements.txt:

--config-settings editable_mode=strict -e ../lib 

However, uv will fail with:

error: Unexpected '-', expected '-c', '-e', '-r' or the start of a requirement at requirements.txt:3:1

Now, I can still get things to work if I pass the --config-settings editable_mode=strict to the CLI, but it's quite tedious to always have to do that. Furthermore, maybe I'd not want to pass it for a different requirement, but now it applies to all of them.

Note that the same also doesn't work with uv pip compile (when putting the --config-settings editable_mode=strict inside a requirements.in) and also not with uv pip sync.

It would be awesome if uv could parse the --config-settings inside a requirements.txt file.

Why is this useful?

If you use an editable install of a package built with setuptools, you need to pass either editable_mode=compat or editable_mode=strict in order for pyright/pylance typing to work for the package (see this StackOverflow question). Supporting this means that it becomes a lot simpler to depend on other local packages without requiring them to be fully factored out as PyPI or Git repository packages (all you need is a very basic pyproject.toml with setuptools as the build backend).

My example setup looks like this:

lib/
├─ lib.py
├─ pyproject.toml
app/
├─ requirements.in
├─ app.py

Also, thanks for this great project! Using it has been a blast so far!

charliermarsh commented 1 month ago

Interesting, I've never seen this -- thanks for raising. Looks like it's https://github.com/pypa/pip/issues/11325 in pip.

zanieb commented 1 month ago

Interesting. I wonder if there should be a way to express this in the CLI as well.

tiptenbrink commented 1 month ago

Small note: If anyone is running into my specific use case: if you use hatchling instead of setuptools as your build backend, pyright will work by default.

Jorricks commented 3 weeks ago

Also faced with this issue unfortunately; https://github.com/microsoft/LightGBM/pull/6493 TLDR; LightGBM throws errors on build arguments it doesn't understand. Hence it fails to uv sync when I have both editable installations (requiring editable_mode=strict) and LightGBM.

Arguably, LightGBM should ignore the arguments. However, there is also a case to be made that we should not pass the editable build args to each individual item.

zanieb commented 3 weeks ago

Considering some options here...