uv
uv copied to clipboard
Suggesting `uv add --sync-constraints [URL or file path]` to simply update pyproject.toml constraints
Summary
I'd like to suggest adding a flag to uv add such as:
uv add --sync-constraints https://example.com/my-constraints.txt
or
uv add --sync-constraints path/to/file/requirements.txt
This would only fetch and update the constraints file section in the pyproject.toml, making the constraints explicit/static and reproducible for future operations (i.e. uv lock/sync).
Example:
Remote constraints file at https://example.com/my-constraints.txt
boto3==1.40.61
pyproject.toml BEFORE syncing:
[project]
dependencies = ["boto3"]
[tool.uv]
constraint-dependencies = ["boto3==1.40.00"]
Run proposed command:
uv add --sync-constraints https://example.com/my-constraints.txt
pyproject.toml AFTER syncing:
[project]
dependencies = ["boto3"]
[tool.uv]
constraint-dependencies = ["boto3==1.40.61"] # <--- updated
Context
- There was some discussion on this previously so this is an idea forked from this discussion: https://github.com/astral-sh/uv/issues/6518
- https://docs.astral.sh/uv/reference/cli/#uv-add
- https://docs.astral.sh/uv/reference/settings/#constraint-dependencies
- https://packaging.python.org/en/latest/guides/writing-pyproject-toml/
Another possible approach could be to allow setting the constraints file as a parameter in pyproject.toml - the goal of either one of these is to prevent having to always pass in the --constraints <> flag on a uv add command because that's kind of error prone, especially if you have some projects that need constraints and others that don't.
Our current use case is that we're using uv for writing Apache Airflow DAGs and code - and that is a LONG constraint file (which I manually converted to constraints in our project and do not want to do again when we update)
Another possible approach could be to allow setting the constraints file as a parameter in pyproject.toml - the goal of either one of these is to prevent having to always pass in the
--constraints <>flag on auv addcommand because that's kind of error prone, especially if you have some projects that need constraints and others that don't.
From #6518 it seemed like they want static pyproject.toml dependencies
What about something like:
uv add --init-constraints example.com Or uv add --init-constraints path-to-file
And then the pyproject.toml will fill in the constraints and save the source. Any future uv sync could check the source and update if there is a diff?
Idk brainstorming to iron this out and could use some input
I have a similar use case but feel like I could be satisfied in the meantime by something like:
uv add --sync-constraints example.com && uv sync
I wonder if uv add --constraints ... without any package name should just import the constraints as described?
I wonder if
uv add --constraints ...without any package name should just import the constraints as described?
Yeah I think this syntax is nice and the scope is decent
uv add --constraints constraints.txt Or uv add --constraints example.com
And then we could pair with a:
uv sync
seamlessly without the crazy manual wrangling of constraints 👍
uv add --constraints constraints.txt Or uv add --constraints example.com
@zanieb Should I start trying to work through this? I don't think there are more requirements than what we've discussed already.
Feel free to put up a pull request.
Feel free to put up a pull request.
Will do!