Announcing flake8-diff


This utility allows you to run flake8 over a set of changed files and filter out violations that would be introduced by merging those changes.

We use this as part of our build / CI infrastructure to alert developers opening pull requests to new violations their pull request will introduce, if it were merged.

Forking background processes in Python

This post attempts to explain how to fork child processes in Python, or at least how to use forking on an existing Python script. For some strange reason I’ve had to explain this a few times recently, so I decided an easy to reference blog post would probably make life a little easier.

Natural order sorting strings with numbers

The following python code makes natural sorting sequences of lexical and numerical values a little easier. It supports any iterable containing strings which have embedded numbers. In short it would give you this:

foo1 < foo2 < foo10

instead of this:

foo1 < foo10 < foo2

Generating a dependency graph for Postgres DB

This post was mostly inspired by this one, which shows how to generate a dependency graph for a MySQL database. Here we do something similar for PostgreSQL.

This script will generate the required digraph data to pipe into graphviz dot which will generate a visual representation of dependencies in a database schema, based on foreign key constraints.

Extending Python with modules written in C

Using C (or C++) to create Python modules is really quite simple, providing you know a little C of course. I recently had to do some work around getting a bunch of legacy C code talking to a newer system and thought I’d post a nice simple example of how the Python extensions work.

This code gives you a single method “do()” that will print the output of a command, passed to it as a string, to stdout and return the exit code as a python int.