astral-sh / uv

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

`uv add --branch` is broken solely on a particular repo #7433

Closed Xmaster6y closed 1 month ago

Xmaster6y commented 1 month ago

Problem

uv doesn't resolve the good commit when using --branch <branch> but @<branch> does (the repo: https://github.com/Xmaster6y/vec_noise)

When I use:

uv add git+https://github.com/Xmaster6y/vec_noise@refacto 

I get (good rev):

Updated https://github.com/Xmaster6y/vec_noise (1e281ec)
Updated https://github.com/Xmaster6y/vec_noise (1e281ec)

But when I use:

uv add git+https://github.com/Xmaster6y/vec_noise --branch refacto

I get:

Updated https://github.com/Xmaster6y/vec_noise (7c3865d)
...

Same for --rev

Using

uv add git+https://github.com/Xmaster6y/vec_noise --rev 1e281ec

gives :

Updated https://github.com/Xmaster6y/vec_noise (7c3865d)
...

Specificities

What didn't work

Details

zanieb commented 1 month ago

Thank you for the well-written report!

zanieb commented 1 month ago

As a note, 7c3865d is the head commit on main and the upstream fork (but not the original repository)

Xmaster6y commented 1 month ago

Puzzling edit:

I previously add:

uv add git+https://github.com/astral-sh/ruff --branch sys-version-info

giving:

 Updated https://github.com/astral-sh/ruff (bb12fe9d0)
 Updated https://github.com/astral-sh/ruff (61a5a86a7)
 ...

But now:

uv add git+https://github.com/astral-sh/ruff --branch sys-version-info

giving:

 Updated https://github.com/astral-sh/ruff (bb12fe9d0)
 ...
zanieb commented 1 month ago

The difference in behavior appears to be because of https://github.com/astral-sh/uv/blob/cafc1f986a6efda0c2f384e63930333a812c9ea4/crates/uv/src/commands/project/add.rs#L241-L242

We only pass the requirements in here and when you use the --branch syntax the source is tracked separately from the package requirement.

[crates/uv/src/commands/project/add.rs:240:5] &requirements = [
    Package(
        "git+https://github.com/Xmaster6y/vec_noise",
    ),
]
Xmaster6y commented 1 month ago

Is this wanted/expected?

Xmaster6y commented 1 month ago

My later observation seems unrelated to my first issue

This happen when my uv.lock is not sync.

To reproduce:

Run (should break, otherwise interupt it mid-course):

uv add git+https://github.com/astral-sh/ruff --branch sys-version-info 

Run the command again (not calling uv sync/lock):

uv add git+https://github.com/astral-sh/ruff --branch sys-version-info 

Does it deserve another issue?

zanieb commented 1 month ago

We later fail at

https://github.com/astral-sh/uv/blob/cafc1f986a6efda0c2f384e63930333a812c9ea4/crates/uv/src/commands/project/add.rs#L316-L324

If you name the dependency, the correct revision is resolved

❯ uv add vec_noise@git+https://github.com/Xmaster6y/vec_noise --branch refacto
 Updated https://github.com/Xmaster6y/vec_noise (1e281ec)

Is this wanted/expected?

No, I don't think the behavior we're seeing is wanted or expected. I'm just debugging and sharing some notes.