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

What if I need to cache both pip and pipenv, is that possible? #934

Open
nabheet opened this issue Aug 29, 2024 · 2 comments
Open

What if I need to cache both pip and pipenv, is that possible? #934

nabheet opened this issue Aug 29, 2024 · 2 comments
Assignees
Labels
feature request New feature or request to improve the current logic

Comments

@nabheet
Copy link

nabheet commented Aug 29, 2024

I would like to cache both pip and pipenv. Wondering how I would accomplish that.

@nabheet nabheet added feature request New feature or request to improve the current logic needs triage labels Aug 29, 2024
@mahabaleshwars
Copy link

Hello @nabheet,
Thank you for creating this feature request. We will investigate it and provide feedback as soon as we have some updates.

@priyagupta108
Copy link
Contributor

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.

@priyagupta108 priyagupta108 self-assigned this Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request to improve the current logic
Projects
None yet
Development

No branches or pull requests

3 participants