Cannot find Pipfile.lock file while restoring cache in python 3.7.1 image

Hi,

I am trying to cache Pipfile.lock so that it won’t install packages every time there is a new PR on GitHub.

I have following yml fie with ~/repo working directory where I expect Pipfile.lock is generated when it is run first time.

working_directory: ~/repo
steps:
      - checkout
      - run: sudo chown -R circleci:circleci /usr/local/bin
      - run: sudo chown -R circleci:circleci /usr/local/lib/python3.7/site-packages
      - restore_cache:
          keys:
            - pip-packages-v2-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
            - pip-packages-v2-{{ .Branch }}-
            - pip-packages-v2-
      - run:
          command: |
            sudo pip install pipenv
            pipenv install pylint==2.3.1
            pipenv install coverage==4.5.4
            pipenv install codecov
      - save_cache:
          paths:
            - "Pipfile.lock"
            - ".venv"
            - "/usr/local/bin"
            - "/usr/local/lib/python3.7/site-packages"
          key: pip-packages-v2-{{ .Branch }}-{{ checksum "Pipfile.lock" }}

I can observe that it can save the cache for Pipfile.lock on this run:

Creating cache archive...
Uploading cache archive...
Stored Cache to pip-packages-v2-trial_for_caching-fLO_sHc3LZMo6nllZ+D+MtbukInwzDlOgIfcHglCUS4=
  * /home/circleci/repo/Pipfile.lock
  * /home/circleci/repo/.venv
  * /usr/local/bin
  * /usr/local/lib/python3.7/site-packages

but when I run it again, it cannot find the Pipfile.lock file with the following error:

error computing cache key: template: cacheKey:1:33: executing "cacheKey" at <checksum "Pipfile.lo...>: error calling checksum: open /home/circleci/repo/Pipfile.lock: no such file or directory

I could never manage to cache and use it again and I have checked the following links:

How to overcome this issue?

The best way to debug these sorts of issues is to run the build via SSH and inspect the files to make sure that when the cache is being restored that the files are where you expect them to be.

Hi Levlaz,

Thank you for your suggestion, it did help me to figure out by running it with SSH as I realized that I completely misinterpreted the goal of the checksum while restoring the cache.

Cheers.

1 Like