Skip to content

Comments

Cache python installs#621

Merged
eifinger merged 7 commits intoastral-sh:mainfrom
merlinz01:cache-python-install-dir
Oct 9, 2025
Merged

Cache python installs#621
eifinger merged 7 commits intoastral-sh:mainfrom
merlinz01:cache-python-install-dir

Conversation

@merlinz01
Copy link
Contributor

@merlinz01 merlinz01 commented Oct 8, 2025

This pull request introduces support for caching Python installs in the GitHub Action, allowing users to cache not only dependencies but also the Python interpreter itself.

This works by setting the UV_PYTHON_INSTALL_DIR to a subdirectory of the dependency cache path so that Python installs are directed there.

Fixes #135

@merlinz01 merlinz01 requested a review from eifinger as a code owner October 8, 2025 15:49
@merlinz01 merlinz01 force-pushed the cache-python-install-dir branch from d57dd8f to 215e68d Compare October 8, 2025 17:03
Copy link
Collaborator

@eifinger eifinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not spread this functionality over the code if not necessary and avoid setting env vars.

We can also solve this by making use of the fact that cache.restoreCache and cache.saveCache accept more than one path.

Before running the actions determine if cachePython is true and then determine the pythonDir by capturing the output of uv python dir.

Also add another segment to the cache key to show if cachePython is set.

Finally lets also test this with a test in test.yml. e.g. Setting up the cache, restoring the cache and check if the required files are in the expected dir.

@merlinz01 merlinz01 force-pushed the cache-python-install-dir branch 7 times, most recently from 92e3b5d to e4538f5 Compare October 9, 2025 14:40
@merlinz01
Copy link
Contributor Author

Almost ready, just need to figure out why the test is failing.

@merlinz01 merlinz01 force-pushed the cache-python-install-dir branch 2 times, most recently from a9a125f to a2f443f Compare October 9, 2025 15:52
Copy link
Collaborator

@eifinger eifinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you are iterating to get the test to pass. Some comments that might help.

@merlinz01 merlinz01 force-pushed the cache-python-install-dir branch from fe551dd to 08df9dc Compare October 9, 2025 20:17
@merlinz01 merlinz01 force-pushed the cache-python-install-dir branch from 3d68f99 to c8d10d1 Compare October 9, 2025 20:31
@merlinz01 merlinz01 requested a review from eifinger October 9, 2025 20:34
Copy link
Collaborator

@eifinger eifinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really nice. Great work. Thank you!

Small typo and we are good to go. But already leaving an approval. Will release this tomorrow.

Co-authored-by: Kevin Stillhammer <[email protected]>
@eifinger eifinger added the enhancement New feature or request label Oct 9, 2025
@eifinger eifinger merged commit 6d2eb15 into astral-sh:main Oct 9, 2025
82 checks passed
@merlinz01 merlinz01 deleted the cache-python-install-dir branch October 9, 2025 20:47
ulgens added a commit to ulgens/django-official-tutorial that referenced this pull request Oct 20, 2025
ulgens added a commit to ulgens/django-official-tutorial that referenced this pull request Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable caching Python installs also

2 participants