14

The Travis documentation on caching does not specifically mention how to cache python dependencies installed from pipenv's Pipfile, rather than from pip's usual requirements.txt. I tried setting up pip caching per documentation anyway, but build times are not improved at all, and I see pipenv installing its deps on every run.

This is the syntax I'm currently using - what is the correct syntax? (or is it even supported?)

language: python
python:
  - "3.6"

cache: pip

cache:
    directories:
        - proj/static/node_modules
        - $HOME/.cache/pip
Cœur
  • 37,241
  • 25
  • 195
  • 267
shacker
  • 14,712
  • 8
  • 89
  • 89
  • The syntax is correct, but I'm not sure that `pip` is installing it's packages in `$HOME/.cache/pip`. Could you link to the github project for reference? – StephenG Dec 21 '17 at 21:06
  • @StephenG pipenv is the newish unified virtualenv+pip tool becoming endorsed by python.org as the officially recommended dependency management toolchain. The master repo is at https://github.com/pypa/pipenv . Thanks. – shacker Dec 23 '17 at 06:07
  • Even the official repo does not cache packages. This is a surprising. I was expecting to find the cache path there. – tejasbubane Jan 17 '18 at 17:39
  • 2
    I've noticed $HOME/.cache/pip is entirely useless, and triggers cache file update every time, even in a skeleton empty project/repo which just installs some random python packages for testing – kert Oct 26 '18 at 17:58

1 Answers1

7

Check the documentation at https://pipenv.readthedocs.io/en/latest/advanced/

You can use the environment variable PIPENV_CACHE_DIR to tell pipenv where to cache files, then include that in the cache.directories array.

I do this on my gitlab-ci.yml configuration (very similar in syntax to travis-ci). I also cache the virtualenv as well, which speeds build time up quite a bit.

My gitlab-ci.yml actually looks like this:

# WORKON_HOME sets where pipenv will place the virtualenv. We do this so that we can capture
#  the environment in the cache for gitlab-ci.
#  PIP_CACHE_DIR tells pip to cache our pip packages in the same path, so that we also
#  cache the downloads.
variables:
  WORKON_HOME: .pipenv/venvs
  PIP_CACHE_DIR: .pipenv/pipcache

# Make sure gitlab-ci knows to always cache the .pipenv path
cache:
  key: pipenv
  paths:
    - .pipenv
Lucid Dan
  • 104
  • 1
  • 4
  • You mention `PIPENV_CACHE_DIR` but don't specify it in your code. I've added it to the list of variables, that seemed to help. – Christopher Dec 02 '21 at 18:52