13
votes

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
1
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
@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 github.com/pypa/pipenv . Thanks.shacker
Even the official repo does not cache packages. This is a surprising. I was expecting to find the cache path there.tejasbubane
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 testingkert

1 Answers

5
votes

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