Cache pip GitHub Actions installs, and Poetry, with numbers
To cache pip GitHub Actions installs you add cache: pip to actions/setup-python , and on a fast runner that is worth well under a second, because it caches downloads and not the install. The number that moves is elsewhere: a package with no wheel for your platform took 10.9 seconds to build against 0.5 seconds to install, and that build lands in the same cache. Measured on a latchkey-small runner…
Caching pip and Poetry installations in GitHub Actions can save significant time, but it depends on the specific dependencies being used. When caching with pip, it only caches the downloads and not the install, which can move the time saved from just under a second to a few seconds in the case of a package without a wheel for the runner's platform. The Poetry option, on the other hand, caches the virtualenv directories, restoring the finished virtualenv and saving tens of seconds.
The setup-python action in GitHub Actions defaults to finding a dependency file such as requirements.txt or pyproject.toml and caches the global cache directory, while Poetry caches the virtualenv directories for each project. This distinction is crucial when dependencies lack wheels for the runner's platform. The pip option allows for the network to be used again, while Poetry allows for the install to be reinstated.
The cache-dependency-path option allows for customization of the cache key, useful when dependency files reside in subdirectories. Measuring the caching effect, the download cache moved 0.8 seconds, while a package without a wheel took 10.4 seconds to build. Python dependency caching has a reputation it only half deserves, as the setup action's cache option primarily caches the download, while the actual installation time is usually the bottleneck.
The difference between pip and Poetry caching becomes evident when one of the dependencies has no wheel for the runner's platform, where pip has to compile it. This is where a cached directory stops saving time and starts saving tens of seconds. The Poetry path, which can restore the finished virtualenv, behaves differently from the pip path. The setup-python action defaults to caching the global cache directory, while Poetry caches virtualenv directories for each project.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
This story
This is one outlet's version. Read the fullest account.
- No space left on device in GitHub Actions dev.to
- GitHub Incident with Webhooks, Actions, etc. githubstatus.com