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

Enable caching Python installs also #135

Open
merlinz01 opened this issue Oct 25, 2024 · 6 comments
Open

Enable caching Python installs also #135

merlinz01 opened this issue Oct 25, 2024 · 6 comments

Comments

@merlinz01
Copy link
Contributor

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
Copy link
Collaborator

eifinger commented Nov 1, 2024

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

@eifinger
Copy link
Collaborator

eifinger commented Nov 2, 2024

@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
Copy link
Contributor Author

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

@merlinz01
Copy link
Contributor Author

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
Copy link
Collaborator

eifinger commented Nov 5, 2024

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
Copy link
Contributor Author

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' }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants