Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caching pipenv / Pipfile dependencies on TravisCI

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
like image 243
shacker Avatar asked Dec 15 '17 01:12

shacker


1 Answers

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
like image 141
Lucid Dan Avatar answered Nov 02 '22 12:11

Lucid Dan