uv icon indicating copy to clipboard operation
uv copied to clipboard

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

Open tiptenbrink opened this issue 1 year ago • 5 comments

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!

tiptenbrink avatar May 17 '24 11:05 tiptenbrink

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

charliermarsh avatar May 17 '24 13:05 charliermarsh

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

zanieb avatar May 17 '24 15:05 zanieb

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.

tiptenbrink avatar May 17 '24 19:05 tiptenbrink

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.

Jorricks avatar Jun 20 '24 10:06 Jorricks

Considering some options here...

  • --config-setting <package-name>__<key>=<val> e.g. --config-setting foo__editable_mode=strict
  • --config-setting <package>=<key=val> e.g. --config-setting foo=editable_mode=strict
  • --config-setting-includes <package> only pass config settings to the given packages
  • --config-setting-excludes <package pass config settings to all packages but the given packages
  • --config-setting-includes <package>=<key> only pass the given config setting to the given packages
  • --config-setting-excludes <package>=<key> do not pass the given config setting to the given packages

zanieb avatar Jun 20 '24 13:06 zanieb

Any chance this will get some attention soon? We have quite some editable installs which we now install one by one

ion-elgreco avatar Jul 16 '24 14:07 ion-elgreco

We need to settle on a design — we're prioritizing some other things right now but if someone wants to push the design forward I can review.

zanieb avatar Jul 16 '24 14:07 zanieb

I'm honestly +0 on this issue, but I thought it worth mentioning I hit this with using uv pip sync, at work we have some internal packages that are built with setuptools, and developed in a multi repo environment, to get IDEs to play nice I have to use --config-settings editable_mode=compat to install them.

Because I can't insert that straight into the requirements file I have to do this slightly awkard to of uv pip sync followed by uv pip install {my_editable_projects} --config-settings editable_mode=compat.

Maybe I'm missing something obvious though.

notatallshaw avatar Sep 20 '24 03:09 notatallshaw

Can package config-settings be specified in toml files? Or is this currently a cli exclusive feature?

s-rog avatar Feb 12 '25 19:02 s-rog

My use case is that I have 2 similar libraries in my [dependency-group], both take the exact same arguments via config_settings to the build backend, but I need to only give the arguments to one of the libraries, otherwise it fails to install the other one when I use uv sync --all-groups.

Best way to initially support this would be directly in the .toml, so I don't have to do a workaround like this:

[dependency-groups]
# Run `uv pip install rpi-libcamera -C setup-args="-Drepository=https://github.com/raspberrypi/libcamera.git" -C setup-args="-Dversion=v0.4.0+53-29156679"`
# if you are installing this and you have a version mismatch of rpi-libcamera and libcamera installed via apt.
camera = [
    "picamera2>=0.3.25",
    "rpi-libcamera>=0.1a8;",
    "rpi-kms>=0.1a1",
]

harshil21 avatar Feb 15 '25 08:02 harshil21

Also hit that: https://github.com/HandsOnLLM/Hands-On-Large-Language-Models/issues/62

raffaem avatar May 01 '25 11:05 raffaem