Open sbidoul opened 2 months ago
Well, we should support this with uv add -r requirements.txt
but that doesn't propagate tool.uv.sources
like it should — we'll fix that and document it.
e.g.
❯ uv init
Initialized project `example`
❯ echo "uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage" > requirements.txt
❯ uv add -r requirements.txt
Using Python 3.12.1
Creating virtualenv at: .venv
Updated https://github.com/astral-test/uv-public-pypackage (b270df1)
Resolved 9 packages in 673ms
Building example @ file:///Users/zb/workspace/example
Building example @ file:///Users/zb/workspace/example
Building example @ file:///Users/zb/workspace/example
Building example @ file:///Users/zb/workspace/example
Built uv-public-pypackage @ git+https://github.com/astral-test/uv-public-pypackage@b270df1a2fb5d012294e9aaf05e7e0bab1e6a389[1merror: Failed to prepare distributions
Caused by: Failed to fetch wheel: example @ file:///Users/zb/workspace/example
Caused by: Build backend failed to build wheel through `build_editable()` with exit status: 1
Needs documentation still.
Just an idea, can we instead add a new flag -c/--constraint
to uv add
, so that you can pass in constraint files directly? Instead of needing to add them to a requirements.txt
.
My specific use case is using Apache Airflow which only supports pip
(not Poetry etc) because it basically requires constraint files, see https://github.com/apache/airflow/blob/main/README.md#installing-from-pypi
That way, I can do (copying from their example):
uv add 'apache-airflow==2.10.0' \
--constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.10.0/constraints-3.8.txt"
Or, thinking aloud, more broadly are there any other flags that exist in uv pip install
that can be also added to uv add
?
@yehoshuadimarsky can you please open a dedicated issue for that request?
You need to add that constraint file to tool.uv.constraint_dependencies
? It needs to be tracked in the project. uv add --constraint
could perhaps do that for you, but it's going to apply to all of your dependencies.
@zanieb sure, created https://github.com/astral-sh/uv/issues/6518
The problem with uv add -r requirements.txt
is it adds all of those dependencies to project.dependencies
.
If a requirements.txt
file is used for pinning transient dependencies, how do you migrate to uv.lock
?
Basically need this, without saving any constraints to pyproject.toml
or anything, just the one time migration and keep the same pinned versions:
uv lock --constraints requirements.txt
rm requirements.txt
Doesn't have to be --constraints
of course, since that may mean I'd want to save them in pyproject.toml
or something.
The typically workaround (which isn't very nice) is:
tool.uv.constraint-dependencies
.uv lock
.tool.uv.constraint-dependencies
.uv will then avoid upgrading past the pinned versions in the future by default.
\cc @zanieb since we've discussed this in-person before.
Thanks for the tip, but do you plan on handling this automatically? Just considering what to put in our docs.
With pip I use constraints files containing a bunch of git URLs to achieve the equivalent of
tool.uv.sources
.Is there a convenient way to convert such a requirements file to a
tool.uv.sources
section?