Save Time by Caching in Travis for Python Projects

1 min read
Save Time by Caching in Travis for Python Projects

By caching files and directories on Travis, we can save time with re/installation because we do not need to re-download the same files over and over again. The recommended way to cache pip-installed packages on Travis CI is shown below:

cache:
  - pip: true

However, this only works for Linux environments. To support OSX and Windows, we can specify the cache directories for pip.

matrix:
  include:
    - name: "Python: 3.6"
      os: osx
      language: shell
      python: 3.6
      cache:
        - directories:
          - $HOME/Library/Caches/pip
    - name: "Python: 3.6"
      os: windows
      language: shell
      before_install:
        - choco install python --version=3.6.8
      cache:
        directories:
          - $LOCALAPPDATA/pip/Cache

If your project uses poetry, it is recommended to cache these directories for faster installation.

  • Linux: $HOME/.cache/pypoetry
  • OSX: $HOME/Library/Caches/pypoetry
  • Windows: $LOCALAPPDATA/pypoetry/cache

Read more articles like this in the future by buying me a coffee!

Buy me a coffeeBuy me a coffee