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

Best practices for using uv's cache in CI / Github Actions? #2231

Closed
strickvl opened this issue Mar 6, 2024 · 8 comments
Closed

Best practices for using uv's cache in CI / Github Actions? #2231

strickvl opened this issue Mar 6, 2024 · 8 comments
Labels
question Asking for clarification or support

Comments

@strickvl
Copy link

strickvl commented Mar 6, 2024

Wondering if there's any advice or best practices starting to develop around how to (re)use and share the uv cache across multiple Github Actions runners?

We repeat the same Python installations across multiple runners / OSes and Python versions. Previously we were taking advantage of Github Actions' caching to save us from redownloading packages, but not any more with uv as it it isn't clear how best to reuse the cache or to what extent that helps.

@jardarbo
Copy link

jardarbo commented Mar 6, 2024

There is an issue on GitHub Action setup-python discussing this: actions/setup-python#822. They argue that the benefit of caching uv .cache folder depends.

@zanieb zanieb added the question Asking for clarification or support label Mar 6, 2024
@zanieb
Copy link
Member

zanieb commented Mar 24, 2024

See also previous discussion at #1386

@jayqi
Copy link

jayqi commented Mar 27, 2024

I made a composite action that sets up uv with optional caching, after piecing together all of the information in the various places about how to get things to work.

https://github.com/drivendataorg/setup-python-uv-action

It supports:

  • no caching
  • caching the uv packages cache
  • caching the virtual environment directory itself

I'm reasonably confident all options should work across the different OS runners.

Your mileage may vary on what actually saves time, depending on what your dependencies are. uv resolution and installation is so fast, that I've found the network speed to be the limiting factor in a lot of cases. Downloading from PyPI is often just as fast as loading a cache. Windows runners seem to have particularly bad cache performance so sometimes the cache is actually slower on Windows than downloading from PyPI.

@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?

@strickvl
Copy link
Author

I recently just noticed that there's a 40GB uv cache sitting on my HD, too.

@charliermarsh
Copy link
Member

(Can always uv cache clean or uv cache prune.)

@153957
Copy link

153957 commented Sep 5, 2024

Perhaps the best practice is now to use https://github.com/astral-sh/setup-uv
and use its caching? https://github.com/astral-sh/setup-uv?tab=readme-ov-file#enable-caching

@zanieb
Copy link
Member

zanieb commented Sep 5, 2024

👍 yeah we also documented best practices a while ago https://docs.astral.sh/uv/guides/integration/github/#caching

@zanieb zanieb closed this as completed Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

7 participants