Git Product home page Git Product logo

Comments (6)

kurtmckee avatar kurtmckee commented on August 18, 2024 1

@hamirmahal I'm not a developer but want to respond to your ticket.

Diagnosis

The pip install -r requirements.txt step in your workflow benefits from caching. However, the setup-python action doesn't control pip's behavior, and cannot reduce the number of "Collecting" and "Using" lines that you're seeing.

However, "Collecting" and "Using" aren't actually consuming much time -- it's the installation itself that consumes the vast majority of time. You can verify this by reviewing the raw logs, which contain a timestamp for every output line:

image

Looking at those raw logs, pip spends ~6 seconds (from 2024-05-06T02:41:05.2881468Z to 2024-05-06T02:41:11.4118495Z) printing "Collecting" and "Using" lines. It then spends ~26 seconds (from 2024-05-06T02:41:11.4118495Z to 2024-05-06T02:41:37.9340734Z) actually installing your dependencies.

Best practice

My recommendation is to disable setup-python's pip caching entirely and focus exclusively on caching an entire virtual environment.

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        id: setup-python
        with:
          python-version: "3.11"

      # Write the exact Python version to a file for cache-busting.
      - run: |
          echo "${{ steps.setup-python.outputs.python-version }}" > ".installed-python"

      # THIS! This is where you'll save all your time!
      # Never cache pip dependencies! Cache virtual environments!
      - uses: "actions/cache@v4"
        id: "restore-cache"
        with:
          key: "venv-${{ hashFiles('.installed-python', 'requirements.txt') }}"
          path: |
            .venv/

      # If Python 3.11.x upgrades to 3.11.y, or if requirements.txt gets updated,
      # the cache lookup above will miss, and the venv needs to be recreated.
      - name: "Create a virtual environment"
        if: "steps.restore-cache.outputs.cache-hit == false"
        run: |
          python -m venv .venv
          .venv/bin/python -m pip install --upgrade pip setuptools wheel
          .venv/bin/python -m pip install -r requirements.txt

      - run: .venv/bin/python src/main.py

Caching an entire virtual environment is going to save you a ton of time. The only thing you need to watch out for is cache-busting. The example above busts the cache based on the exact Python version (like "3.11.7") and based on your requirements.txt file. If you're running this workflow on multiple platforms you'll need to include that in the cache key, too.

@HarithaVattikuti I think that this ticket can be closed; the report is referring to pip behavior, not setup-python behavior.

from setup-python.

hamirmahal avatar hamirmahal commented on August 18, 2024

https://github.com/hamirmahal/cache-pip-install/commits/continue-caching-with-setup-python/

from setup-python.

hamirmahal avatar hamirmahal commented on August 18, 2024

Initial Run

Run / python-program (push) Successful in 1m Details

Cached Run

Run / python-program (push) Successful in 54s Details

from setup-python.

HarithaVattikuti avatar HarithaVattikuti commented on August 18, 2024

Hello @hamirmahal
Thank you for creating this issue. We will investigate it and get back to you as soon as we have some feedback.

from setup-python.

hamirmahal avatar hamirmahal commented on August 18, 2024

You're welcome @HarithaVattikuti.

from setup-python.

priya-kinthali avatar priya-kinthali commented on August 18, 2024

Hello @hamirmahal 👋,
Regarding pip caching, it works by storing downloaded packages in a directory so that they don't need to be re-downloaded when they're needed in the future. This indeed saves time by skipping the downloading step.
Thanks to @kurtmckee for the insightful explanation. As rightly pointed out, the "Collecting" and "Using" stages in pip's process are essential and cannot be bypassed entirely, even when caching is employed. The "Collecting" stage is where pip identifies the necessary packages for installation (including dependencies), and the "Using" stage is where pip indicates that it's utilising a cached package, thus avoiding the need for a new download.
Hope this clarifies and I am proceeding to close this issue. Thank you for your patience and cooperation:)
Please feel free to reach us out incase of any further concerns!

from setup-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.