What if I need to cache both pip and pipenv, is that possible?
I would like to cache both pip and pipenv. Wondering how I would accomplish that.
Hello @nabheet, Thank you for creating this feature request. We will investigate it and provide feedback as soon as we have some updates.
Hi @nabheet š,
The setup-python action supports caching for a single package manager at a time, either pip or pipenv. To cache both pip and pipenv dependencies, you can use two separate steps to cache each package manager independently within the same workflow. Here's an example of how you can achieve this:
name: Cache pip and pipenv
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache pipenv packages
uses: actions/cache@v4
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pipenv-
- name: Install dependencies
run: |
pip install --upgrade pip
pip install pipenv
pipenv install --deploy --ignore-pipfile
In this example, theĀ actions/cacheĀ action is used to cache the pip dependencies located inĀ ~/.cache/pipĀ and the pipenv virtual environments located inĀ ~/.local/share/virtualenvs. Adjust the paths as necessary for your specific setup. The cache keys are generated based on the hash of theĀ requirements.txtĀ andĀ Pipfile.lockĀ files to ensure that the cache is updated when dependencies change.
I hope this helps! Let us know if you have any further questions.
Hi @nabheet,
Just a friendly reminder regarding the solution I provided for caching both pip and pipenv dependencies. Have you had a chance to try it out? If you have any questions or need further assistance, please let me know.
Thank you!
Sorry I just got back from vacation. I believe this should work for us. I will close this issue for now as it will take me a few days to confirm. Thank you!