Quirks of Pipenv on Travis CI and AppVeyor
My initial impressions of using Pipenv with continuous integration tools Travis CI and AppVeyor are basically good. However, there are a few quirks.
Travis CI
If you’re using a Python build, Travis CI is kind enough to have already plopped you in a virtual environment (using virtualenv) straight out of the box. Fortunately, Pipenv uses virtualenv under the covers so this is not a problem.
If you start using Pipenv, you’ll just be working within the existing virtualenv. As such, you don’t need to start a Pipenv shell or, in other words, activate a virtualenv— you’re already in one! Pipenv is smart enough to latch on to the virtualenv you’re already in.
If you’ve already added a Pipfile
or Pipfile.lock
to your project, using Pipenv to install all of your project’s dependencies from a Travis CI YAML file is easy:
language: python
matrix:
include:
- python: 3.5
- python: 3.6
- python: 3.7
dist: xenial
sudo: trueinstall:
- pip install pipenv
- pipenv install
At this point, you do not need to run pipenv shell
or pipenv run <command>
, and can simply go on with your bad self:
install:
- pip install pipenv pytest
- pipenv install
- pytest # <== This runs in Pipenv (a/k/a virtualenv)
AppVeyor
On the other hand, AppVeyor does not put you in a virtual environment by default so you’ll need to create one.
Also, you might think that putting pipenv shell
in your AppVeyor YAML would activate a Pipenv and any commands that follow would run in the Pipenv/virtualenv. Unfortunately, you’d be dead wrong.
Once you issue your pipenv shell
command, AppVeyor completely stops doing anything. I imagine a tiny CPU man clocking out early to hit the bar.
To avoid the specter of CPU drunkenness, use pipenv run <command>
instead. You can still use the virtual environment, stay in control, and save the liver and, quite possibly, the life of a tiny CPU guy called Clive.
For example, you could use this YAML to install all your project’s dependencies, and run PyTest on your project using Python 3 (AppVeyor defaults to Python 2):
version: '{branch}-{build}'
build: "off"
image: Visual Studio 2015install:
- pip install pipenv pytest
- pipenv --python 3
- pipenv installtest_script:
- pipenv run pytest
(Personally, I find the “Visual Studio 2015” build to be faster than AppVeyor’s other options.)