setup-python icon indicating copy to clipboard operation
setup-python copied to clipboard

Support for caching an arbitrary path to a virtual environment

Open lijok opened this issue 4 years ago • 3 comments

Description: Would be great if an arbirary path to a virtual environment could be cached, instead of / in addition to the default pip and pipenv caching behaviours.

Justification: Using actions/cache@v2 and actions/setup-python@v1 we would cache our venvs like so:

      - name: setup python
        id: python_setup
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python_version }}

      - name: cache dependencies
        uses: actions/cache@v2
        with:
          path: ./.venv
          key: python-${{ steps.python_setup.outputs.python-version }}-${{ hashFiles('setup.cfg') }}

A major cause of irritation with this is having to figure out what the cache key should be, resulting in every repo having a different one. So, I was very glad when I saw that actions/setup-python@v2 supports caching out of the box, figuring out the cache key itself, and we can ditch the cache action altogether However, looking at the code it appears that the caching behaviour here is different

Using:

      - name: setup python
        id: python_setup
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python_version }}
          cache: pip
          cache-dependency-path: setup.cfg

my understanding is that the pip global cache is what's being cached Meaning, when we run python3 -m venv .venv && . .venv/bin/activate && python3 -m pip install ., although pip no longer has to download the dependencies, because they're cached, it still has to make api calls against upstream to check that local cached dependency hashes match upstream Overall, in our tests, for a small-ish repo with 75 dependencies total, totaling cache size of 30MB, our setup step with the old caching method would take 1-2s, whereas with v2 it takes about 50s

Are you willing to submit a PR?

Yes, if a design is proposed

lijok avatar Nov 19 '21 09:11 lijok

Hello @lijok! Thanks for your feature request. We will look at it.

nikita-bykov avatar Nov 22 '21 09:11 nikita-bykov

Any update @nikita-bykov

christian-steinmeyer avatar Oct 05 '22 12:10 christian-steinmeyer

+1

guilhermeferrari avatar Feb 20 '24 15:02 guilhermeferrari