Bazel vs. Pants for a Python project

14 Apr 2017

As of now (14 April 2017), please use Pants instead of Bazel.

So, in the past few days, I was exploring a build system for our Python project.

The main reason is that we want to package our Python code and ship as a single binary. Pex and Subpar can achieve that.

We eventually choose Pex over Subpar because it supports extracting the archive before executing our Python code. We need this capability because one of our resource file is a bash script that will be executed. A bug is filed for Subpar here.

We wanted to use Bazel because I currently work at Google and want to use our products as much as possible. Plus, its number of forks and stars are much higher than Pants.

However, for a Python project, there are 3 deal breakers:

  1. Bazel doesn't support Pip: There's a feature request from 2015 here.
  2. Bazel doesn't support Pex: Nevertheless, somebody makes the Pex extension for Bazel here. – I prefer not to use a project from a random person…
  3. Bazel doesn't support test coverage: There's a feature request from 2016 here.

I hacked together a code that makes Pip and Pex work with Bazel here – The code feels rather hacky, and I don't really want to maintain it on a longer term.

Not supporting test coverage is the last nail in the coffin. I can't even hack my way out of this.

So, I've decided to use Pants instead. Pants supports all of these out-of-the-box.

The good news is that, in the past 2 days, I integrated Pants and Bazel into our project multiple times. Once Bazel supports these 3 deal breakers, it'll take around 1 day to switch over.