Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert requirements.txt to tool.uv.sources ? #6275

Open
sbidoul opened this issue Aug 20, 2024 · 9 comments · Fixed by #6287
Open

How to convert requirements.txt to tool.uv.sources ? #6275

sbidoul opened this issue Aug 20, 2024 · 9 comments · Fixed by #6287
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@sbidoul
Copy link

sbidoul commented Aug 20, 2024

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?

@zanieb
Copy link
Member

zanieb commented Aug 20, 2024

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

@zanieb
Copy link
Member

zanieb commented Aug 21, 2024

Needs documentation still.

@yehoshuadimarsky
Copy link

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"

@yehoshuadimarsky
Copy link

Or, thinking aloud, more broadly are there any other flags that exist in uv pip install that can be also added to uv add?

@zanieb
Copy link
Member

zanieb commented Aug 23, 2024

@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.

@yehoshuadimarsky
Copy link

@zanieb sure, created #6518

@helderco
Copy link

helderco commented Sep 11, 2024

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.

@charliermarsh
Copy link
Member

The typically workaround (which isn't very nice) is:

  • Add all the constraints to tool.uv.constraint-dependencies.
  • Run uv lock.
  • Remove the constraints from 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.

@helderco
Copy link

Thanks for the tip, but do you plan on handling this automatically? Just considering what to put in our docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants