actions / setup-python

Set up your GitHub Actions workflow with a specific version of Python
MIT License
1.59k stars 507 forks source link

Support for `uv` Package Manager Caching #822

Open mgaitan opened 4 months ago

mgaitan commented 4 months ago

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 https://github.com/astral-sh/uv/pull/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 https://github.com/astral-sh/uv/issues/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.

nschloe commented 4 months ago

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 commented 4 months ago

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 https://github.com/alice-biometrics/uv-playground/commit/14871e815ad18382fa238a89d8b896a19e67f080

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 commented 3 months ago

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: https://github.com/actions/setup-python/pull/818

alechouse97 commented 2 months ago

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 commented 2 months ago

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 https://github.com/actions/setup-python/issues/822#issuecomment-1963717925