uv
uv copied to clipboard
Cache issue when installing from git urls with once missing refs
I have an issue where the cache seem to get "corrupt". I have a project with git references. If the install was attempted once when the target SHA had not landed in the upstream URL, the cache is broken for this sha and does not recover with a "--refresh" once the sha does exist in the upstream repo.
I don't have a repro case just yet will see if i can figure out how to make one. But suspicion is that the git reset that fails below is performed before a new fetch has been performed from the upstream git repo.
Platform: Ubuntu 22.04.2 LTS Uv: uv 0.2.12
<package> @ git+ssh://<url>@<sha>#subdirectory=<dir>
uv pip install --verbose --refresh -r tests/requirements.txt
DEBUG Searching for Python interpreter in virtual environments
DEBUG Found CPython 3.10.12 at `/home/rtljopl/tecu/application/.venv/bin/python3` (active virtual environment)
DEBUG Using Python 3.10.12 environment at .venv/bin/python3
DEBUG Acquired lock for `.venv`
DEBUG At least one requirement is not satisfied: <package> @ git+ssh://<url>@<sha>#subdirectory=<dir>
DEBUG Using request timeout of 30s
DEBUG Fetching source distribution from Git: ssh://<url>
DEBUG Acquired lock for `ssh://<url>`
DEBUG reset /home/rtljopl/.cache/uv/git-v0/checkouts/f5528ce19486c11e/<sha> to <sha>
error: Failed to download and build: `<package> @ git+ssh://<url>@<sha>#subdirectory=<package>`
Caused by: Git operation failed
Caused by: process didn't exit successfully: `git reset --hard <sha>` (exit status: 128)
--- stderr
fatal: Could not parse object '<sha>'.
Interesting, if the local repository is corrupted we do a fresh clone and it looks like we assume the previous locked revision is correct, even if we may not have fetched that refspec correctly. However, I'm not sure why we would have a locked revision in your case because the checkout would have failed. A reproduction would be helpful.
I just encountered the same problem in a project using rye with uv enabled.
- Have a project using a dependency in
pyproject.tomlin the form of<PACKAGE_NAME> @ git+ssh://[email protected]/<ORG>/<PACKAGE_NAME>.git@<GIT_HASH> - run
rye syncwith uv enabled - Push a new commit to
<ORG>/<PACKAGE_NAME> - change <GIT_HASH> in
pyproject.toml - run
rye sync - Encounter the error above
Temporary workaround for me is UV_NO_CACHE=true rye sync. I have not yet used uv directly but for the initial problem @elupus reported this should work UV_NO_CACHE=true uv pip install --verbose --refresh -r tests/requirements.txt
Just as a minor note, using --no-cache with --refresh doesn't make sense, I'd use one or the other. Generally --refresh-package <name> is the best option.
Beautiful! Thanks!