Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for uv Package Manager Caching #822

Open
mgaitan opened this issue Feb 21, 2024 · 5 comments
Open

Support for uv Package Manager Caching #822

mgaitan opened this issue Feb 21, 2024 · 5 comments
Labels
feature request New feature or request to improve the current logic

Comments

@mgaitan
Copy link

mgaitan commented Feb 21, 2024

Description
Hey there! I'm suggesting we add caching support for the uv package manager in setup-python. uv (uv pip command currently) is a drop-in replace for pip, using requirements.txt or any other input file that pip supports for dependencies definitions. The only difference is its cache directory: setup-python uses the output of pip cache dir to find the cache directory, but uv uses uv cache dir instead (see astral-sh/uv#1734). It should be a straightforward addition that could help projects using uv.

Justification
uv is 10-100x faster than pip. There is a lot of interest from the community to use this new tool in CI environments (e.g astral-sh/uv#1386)

Are you willing to submit a PR?
Yep! Happy to help out and get my hands dirty with a PR to make this happen. However, I'm far of being a Typescript expert.

@mgaitan mgaitan added feature request New feature or request to improve the current logic needs triage labels Feb 21, 2024
@nschloe
Copy link

nschloe commented Feb 23, 2024

You could also just cache the uv cache directory, e.g.,

      - uses: actions/cache@v4
        id: cache-uv
        with:
          path: ~/.cache/uv
          key: ${{ runner.os }}-python-${{ matrix.python-version }}-uv

@acostapazo
Copy link

You could also just cache the uv cache directory, e.g.,

      - uses: actions/cache@v4
        id: cache-uv
        with:
          path: ~/.cache/uv
          key: ${{ runner.os }}-python-${{ matrix.python-version }}-uv

I have just tested this solution and I think it is not worth using it when your requirements are large packages.

I've added the cache in my public playground with alice-biometrics/uv-playground@14871e8

And run a workflow to test what happens when run without cache: https://github.com/alice-biometrics/uv-playground/actions/runs/8046635708/job/21974
Screenshot 2024-02-26 at 10 35 38
241996

surprisingly, the size of the cache is very large, so it takes a long time to save in the post-cache.
Screenshot 2024-02-26 at 10 36 05

Then, I run it again to test how works with a saved cache: https://github.com/alice-biometrics/uv-playground/actions/runs/8046670133/job/21974345476
Screenshot 2024-02-26 at 10 37 23

The installation time is extremely fast, however, it takes the same amount of time to retrieve the cache as it does to install in a fresh environment with uv.

Example of a workflow without uv cache: https://github.com/alice-biometrics/uv-playground/actions/runs/7986874748/job/21808164311
Screenshot 2024-02-26 at 10 43 23

@akx
Copy link
Contributor

akx commented Mar 27, 2024

Heh, I actually wrote a PR that implements this (before this issue, to boot), but no actions/setup-python maintainer seems to have seen it: #818

zanieb pushed a commit to astral-sh/ruff-pre-commit that referenced this issue Apr 2, 2024
<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

`uv` is great. So we should use it where we can. 

The cache had to be removed because the workflow breaks currently.
actions/setup-python#822
When this is solved, caching can be brought back in.

## Test Plan

Ran workflow on my local repo.
@alechouse97
Copy link

I've been playing with replacing pip with uv in our Gitlab CI pipeline, and it massively speeds up installing packages when you've got the cache. However, I've noticed that the uv cache is notably larger than the pip one (along with significantly more files), and the increase in Gitlab's cache time almost outweighs the shift to uv. Anyone else run into this?

@edgarrmondragon
Copy link

I've been playing with replacing pip with uv in our Gitlab CI pipeline, and it massively speeds up installing packages when you've got the cache. However, I've noticed that the uv cache is notably larger than the pip one (along with significantly more files), and the increase in Gitlab's cache time almost outweighs the shift to uv. Anyone else run into this?

I think that's essentially the same that's reported in #822 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request to improve the current logic
Projects
None yet
Development

No branches or pull requests

7 participants