astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
20.52k stars 606 forks source link

Configure pip compile via pyproject.toml or uv.toml #3883

Open inoa-jboliveira opened 3 months ago

inoa-jboliveira commented 3 months ago

Recently uv started supporting TOML config files and it has been very useful. I believe it could be greatly expanded. (BTW, there is no "discussions" page on this Github project. I would prefer posting it there instead of an issue).

Currently pip-tools is configurable via pyproject.toml , so I believe we could have very similar configs for the high level options like generate_hashes and annotate.

The reason I opened this discussion is to go even further and solve a problem I always had with pip-tools.

My project has multiple .in files and multiple .txt outputs. Each in file has windows and linux versions and we will start having them for multiple python versions to be able to support Python 3.12 and 3.13 where it is hard to find compatible libs that still support 3.9 simultaneously.

Our current approach is to have a script like this:

uv pip compile ./requirements/requirements.in ./requirements/requirements-dev.in -o ./requirements/requirements-dev-linux.txt --python-platform=linux
uv pip compile ./requirements/requirements.in -o ./requirements/requirements-linux.txt --python-platform=linux
uv pip compile ./requirements/requirements.in ./requirements/requirements-dev.in -o ./requirements/requirements-dev-win.txt --python-platform=windows
uv pip compile ./requirements/requirements.in -o ./requirements/requirements-win.txt --python-platform=windows

But if I want, lets say, upgrade a lib, I have to pass extra parameters to all these commands. So in fact I never use uv pip compile but a wrapper around it.

It would be way better if I had a pyproject.toml like this:

[tool.uv.pip.compile.outputs]
foo-win.txt = { in = foo.in, python-platform = windows }
foo-linux.txt = { in = foo.in, python-platform = linux }
bar-py39.txt = { in = bar.in, python-version = 3.9 }
bar-py312.txt = { in = bar.in, python-version = 3.12 }

Then I would just run uv pip compile and it would generate all files. Better yet, if I did uv pip compile --upgrade numpy it would also pass this parameter to all the files.

inoa-jboliveira commented 1 day ago

Hi everyone, I feel like uv lock is way more versatile and my worflow no longer contains pip compile but it does have multiple uv export which guarantee versions are the same across multiple txt files. Also I adopted the universal format long ago which greatly simplified the workflow even with pip compile.

From my end, this PR can be closed. I let the maintainer decide since there are some thumbs up emojis