Flake8 tests

This is essentially the same as #643 except that it uses flake8 for the checking and is not dependent on matplotlib.

Do not merge yet as this causes quite some errors!