astral-sh / uv

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

Allow `uv add --git <url>` #5383

Open zanieb opened 4 months ago

zanieb commented 4 months ago

e.g. uv add [<package>] --git <url>

Unlike uv add <git-url> the user should not have to include a git+ prefix.

Part of https://github.com/astral-sh/uv/issues/5381

eth3lbert commented 4 months ago

I'd like to request some clarification on the following:

  1. What is the expected outcome of this operation?

  2. Would the result of uv add "httpx>0.2.0" --git https://github.com/encode/httpx differ from uv add "httpx>0.2.0" git+https://github.com/encode/httpx?

  3. Should we consider issues #4604 or #5341 during implementation?

zanieb commented 4 months ago
  1. The same as uv add git+https://github.com/encode/httpx

  2. This drops the version specifiers from the project.dependencies entry for httpx, they need to be respected.

❯ uv init
warning: `uv init` is experimental and may change without warning
Initialized project `example`
❯ uv add "httpx>0.2.0" git+https://github.com/encode/httpx
warning: `uv add` is experimental and may change without warning
 Updated https://github.com/encode/httpx (beb501f)
⠙ Resolving dependencies...                                                                                                                                                                                                                                                    warning: `uv.sources` is experimental and may change without warning
 Updated https://github.com/encode/httpx (beb501f)
Resolved 8 packages in 379ms
   Built example @ file:///Users/zb/workspace/example
Prepared 1 package in 388ms
Uninstalled 1 package in 0.36ms
Installed 1 package in 0.85ms
 - example==0.1.0 (from file:///Users/zb/workspace/example)
 + example==0.1.0 (from file:///Users/zb/workspace/example)
❯ cat pyproject.toml
[project]
name = "example"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "httpx",
]

[tool.uv]
dev-dependencies = []

[tool.uv.sources]
httpx = { git = "https://github.com/encode/httpx" }
  1. I think we can keep this separate from:
    • 4604,

    • 4603

    • 5341

eth3lbert commented 4 months ago

2. This drops the version specifiers from the project.dependencies entry for httpx, they need to be respected.

Since issue #5339 has been resolved, is this statement still valid?


Let me summarize a bit. Please correct me if I'm wrong.


Unclear Part


Based on my understanding, if the --git flag is used, we simply rewrite the requirements from --git and the [package] as needed (similar to how cargo add works, although cargo add doesn't currently allow specifying a git URL with a version).