hynek / setup-cached-uv

Use uv in GitHub Actions by adding one line to the workflow.
MIT License
55 stars 2 forks source link

Question: caching venv vs caching uv? #7

Open tekumara opened 2 months ago

tekumara commented 2 months ago

Given a venv can be cached directly, what are the advantages of caching the uv cache instead?

hynek commented 1 month ago

This is an excellent and pertinent question, especially since Adam's https://adamj.eu/tech/2023/11/02/github-actions-faster-python-virtual-environments/ just popped up again with an update.

The question is especially interesting because at least for uv, the caching is actually slower than just creating/installing, except for cases like PyPy which led to #6. This is also why this project is still labelled "semi-experimental" and as such I welcome experiments from users like you!

I'm gonna say that the uv cache as used here is nicer for cases where you don't pin your in-dev dependencies (because, say, you don't have enough churn on your project and don't want your history consist solely of Dependabot updates) and still want a certain control over the cache handling.

albertotb commented 1 month ago

There are some reports in this issue and associated PR, that you probably are already aware of: https://github.com/actions/setup-python/issues/822 They suggest little to no improvement caching the uv folder. I've just wanted to link this here since I'm following this topic closely. Maybe caching the whole venv as Adam suggest is better, but I have not seen any example of that yet.

henryiii commented 1 month ago

FYI, the latest release of uv (4 hours ago) has a really interesting cache-related option:

uv cache prune --ci

That removes the unpacked files, but leaves the compressed downloads. It's supposed to be good for CI caching. The venv as well as the raw uv cache have a lot of small files, which are much slower to cache.

hynek commented 1 month ago

Unfortunately this is where the composite action approach hits a wall: https://github.com/orgs/community/discussions/26743#discussioncomment-3253195

Not sure it's worth learning TypeScript for now, but I'll try adding it to baipp: https://github.com/hynek/build-and-inspect-python-package/pull/135

henryiii commented 1 month ago

What about https://github.com/marketplace/actions/run-and-post-run-action ? That’s the suggestion at the end of that thread.

hynek commented 1 month ago

What about https://github.com/marketplace/actions/run-and-post-run-action ? That’s the suggestion at the end of that thread.

nice! Add in #9