Scrawls from Preston...

Powered by Pelican.

Wed 24 July 2013

Can you "Wheel the love"?

So pip 1.4 has been released and one of the most exciting features is integration of Wheel support. I'm going to run through how to make wheels a default part of your workflow that can be a huge timesaver.

I'm assuming you are already using virtualenv and virtualenvwrapper , if not, well you need to check those out. What we want to do is provide a setup that lets us use wheels on our machine a little like we use the pip download cache (another thing you should check out if you don't have it configured).

First lets set up a place to keep wheels:

mkdir ~/.pip/wheels

In order to use wheels, we are going to need the wheel package in any virtualenv we use, it is a relatively small package. I do this by adding pip install wheel to the postmkvirtualenv hook.

Now we need to tell pip to always make use of our trove of wheels by adding the following to ~/.pip/pip.conf:

[global]
use-wheel = true
wheel-dir = /Users/preston/.pip/wheels
find-links = /Users/preston/.pip/wheels

Note that pip's config isn't smart enough to do ~ expansion, so you'll need to put in the whole path (and unless you are named 'Preston' and on a Mac, it will look different than the above...).

Now, to add packages in wheel format to your wheel cache folder, you can just run:

pip wheel -r requirements.txt

on any requirements file - you don't need to have those requirements installed in your current virtualenv - but obviously you need wheel itself installed from the context where you run this (so you might choose to install wheel globally alongside your global pip).

Because you have the wheel configuration in your pip.conf, when you want to build out a new virtualenv and take advantage of any wheels you have installed, you can use pip exactly like you normally do:

pip install -r requirements.txt

This will use a wheel if you have it, and download it otherwise (and download a wheel if that is posted to the index). If you know you have all the wheels you already need, you can add --no-index to the pip command for some truly blazing speed.

Because you have use-wheel set globally, adding additional wheels will check for an existing wheel before building them.

Now go forth and Wheel!


https://ptone.com/dablog