astral-sh / setup-uv

Set up your GitHub Actions workflow with a specific version of https://docs.astral.sh/uv/
MIT License
190 stars 14 forks source link

Enable caching Python installs also #135

Open merlinz01 opened 2 weeks ago

merlinz01 commented 2 weeks ago

This cache action works to cache the Python installs:

      - name: Cache UV python installs
        uses: actions/cache@v2
        with:
          path: ~/.local/share/uv/python
          key: ${{ runner.os }}-uv-python-${{ hashFiles('.python-version', 'pyproject.toml') }}

but are you in favor of adding another input to do put the Python installs in the same cache as the dependencies?

E.g.:

function setPythonInstallDirToCacheDir(cacheLocalPath: string): void {
  core.exportVariable("UV_PYTHON_INSTALL_DIR", `${cacheLocalPath}/_python_installs`);
  core.info(`Set UV_PYTHON_INSTALL_DIR to ${cacheLocalPath}/_python_installs`);
}
      - name: Cache UV python installs
        uses: astral-sh/setup-uv@v3
        with:
          enable-cache: true
          cache-python-with-dependencies: true
eifinger commented 1 week ago

Thank you for suggesting this. I am looking into it.

eifinger commented 6 days ago

@merlinz01 if you are already using that in an existing workflow. Can you share some statistics how much time is saved by also caching the python interpreters vs. always downloading them again?

merlinz01 commented 6 days ago

Sure, once I'm done pulling the 209MB updated docker image for act over my <1MB/s connection :).

merlinz01 commented 6 days ago

This is using act on my local machine. I realize that on a hosted actions runner it might be more efficient not to cache.

When I cache all the dependencies but not the Python install, and the cache exists, my test suite takes 50 seconds. When I cache both the dependencies and the Python install, and the cache exists, my test suite takes 18 seconds.

eifinger commented 3 days ago

I'm always in favor for adding new functionalities if it helps users but otherwise want to keep the codebase as small as possible. So can you help me to understand the usecase a bit better?

On self-hosted runners the python interpreter should be "cached" anyways. On GitHub hosted (ephemeral) runners the question is if caching is more efficient than downloading it fresh every time.

Did I miss a usecase?

merlinz01 commented 3 days ago

On self-hosted runners the python interpreter should be "cached" anyways. On GitHub hosted (ephemeral) runners the question is if caching is more efficient than downloading it fresh every time.

Correct. The use case this would be targeted at is running jobs locally via the act tool on one's development machine.

To confine this caching to that context, you can specify it like this:

 cache-python-with-dependencies: ${{ env.ACT == 'true' }}