uv
uv copied to clipboard
Allow updating sources with `uv add`
Follow up to https://github.com/astral-sh/uv/pull/4566, uv add git+https://..foo followed by uv add foo --branch foo should work as expected. Currently it errors. cargo add supports this.
can I try this one?
@marcvanheerden feel free!
@ibraheemdev , just want to clarify the task for this, is this the error we want to fix?
I tested a similar example on cargo stable and nightly and this doesn't appear to work on cargo.
Let me know if I misunderstood
Is this issue solved. Can I try?
I gave this a look and am not sure that this is actually an issue.
To test I:
- created a new project with
uv init - ran
uv add git+https://github.com/psf/requestswhich successfully addsrequestswith git source - ran
uv add git+https://github.com/psf/requests --branch consider_certswhich successfully updates the package's source info
See below for the diff of my pyproject.toml from the first and second commands.
diff --git a/pyproject.toml b/pyproject.toml
index 3f64dba..b180aa3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,11 +2,11 @@
name = "updating-git-branches"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"requests",
]
[tool.uv.sources]
-requests = { git = "https://github.com/psf/requests" }
+requests = { git = "https://github.com/psf/requests", branch = "consider_certs" }
The following does not work (and seems expected):
> uv add git+https://github.com/psf/requests
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
Running `/Users/sofubi/Projects/contributing/uv/target/debug/uv add 'git+https://github.com/psf/requests'`
Updated https://github.com/psf/requests (23540c93)
Resolved 6 packages in 14ms
Installed 5 packages in 10ms
+ certifi==2024.8.30
+ charset-normalizer==3.4.0
+ idna==3.10
+ requests==2.32.3 (from git+https://github.com/psf/requests@23540c93cac97c763fe59e843a08fa2825aa80fd)
+ urllib3==2.2.3
> uv add requests --branch consider_certs
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.44s
Running `/Users/sofubi/Projects/contributing/uv/target/debug/uv add requests --branch consider_certs`
error: `requests` did not resolve to a Git repository, but a Git reference (`--branch consider_certs`) was provided.
I looked at the uv add --help info and it specifically says that --branch is meant to be used when adding a package from git. The cargo functionality similarly appears to expect --branch to be used only when --git is used.
Options:
-r, --requirements <REQUIREMENTS> Add all packages listed in the given `requirements.txt` files
--dev Add the requirements to the development dependency group
--optional <OPTIONAL> Add the requirements to the package\'s optional dependencies for the specified extra
--group <GROUP> Add the requirements to the specified dependency group
--editable Add the requirements as editable
--raw-sources Add source requirements to `project.dependencies`, rather than `tool.uv.sources`
--rev <REV> Commit to use when adding a dependency from Git
--tag <TAG> Tag to use when adding a dependency from Git
--branch <BRANCH> Branch to use when adding a dependency from Git
--extra <EXTRA> Extras to enable for the dependency
--no-sync Avoid syncing the virtual environment [env: UV_NO_SYNC=]
--locked Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
--frozen Add dependencies without re-locking the project [env: UV_FROZEN=]
--package <PACKAGE> Add the dependency to a specific package in the workspace
--script <SCRIPT> Add the dependency to the specified Python script, rather than to a project
If it's expected that uv add requests --branch consider_certs should add the branch to the existing package source then I'd be a little confused as that would really prevent users from being able to move away from using a git source and go to using something like PyPI.
I understand the issue in the sense that we would like to support not using the full Git url but just the package name and if a git option (like --branch main) is provided we fallback onto an existing one (if it exists) instead of erroring.
I've proposed an implementation to achieve this in #12897