DEV Community

Robert Roskam
Robert Roskam

Posted on

Python Tooling Review: pyproject.toml and flake8

I recently had an opportunity to review some tooling for Python, and I thought I'd share some of my learnings.

pyproject.toml

This fancy new file is the replacement for setup.py and setup.cfg originally specified in PEP 518 (https://www.python.org/dev/peps/pep-0518/).

Simple and clean explanation, right? Well, no, not really.

Since its release, it's now the exclusive way to configure black for a project. Additional tools like poetry (somewhat of a pipenv competitor) and flit (a tool to make packaging and publishing to PyPI easier) have come out to also exclusively use pyproject.toml as their configuration file.

It's clear from the PEP that this was the intended consequence for other tools to use pyproject.toml. However, it seems to only have really touched brand new projects. Older, mature packages seem to still primarily be using setup.cfg for their tooling configs in their CI process.

I generally tend to adopt new trends like these in my projects, but in my existing packages I admit not seeing a whole lot of value presently in ripping out my setup.py and setup.cfg just for fun.

flake8

I used pylint for a very long time while at Worthwhile and began using flake8 at Peerfit. I really had no opinion of one over the other.

However, I can say now that holy crap does flake8 have so much stuff.
It wraps pyflakes, pycodestyle, and mccabe. Additionally, it's just got so many plugins: flake8-bugbear, flake8-import-order, flake8-print, etc (https://github.com/DmytroLitvinov/awesome-flake8-extensions).This rich ecosystem simply doesn't seem to exist for pylint.

Finally, a lot of major projects seems to use flake8, so the user base is consistent and mature:

So this has sold me on using flake8 for the foreseeable future.

Top comments (5)

Collapse
 
sobolevn profile image
Nikita Sobolev

You might also like wemake-python-styleguide which is the strictest python linter ever.

GitHub logo wemake-services / wemake-python-styleguide

The strictest and most opinionated python linter ever!

wemake-python-styleguide

wemake.services Supporters Build Status Coverage Status Github Action Python Version wemake-python-styleguide

Welcome to the strictest and most opinionated python linter ever.

wemake-python-styleguide logo

wemake-python-styleguide is actually a flake8 plugin with some other plugins as dependencies.

Quickstart

pip install wemake-python-styleguide

You will also need to create a setup.cfg file with the configuration.

We highly recommend to also use:

  • flakehell for easy integration into a legacy codebase
  • nitpick for sharing and validating configuration across multiple projects

Running

flake8 your_module.py

This app is still just good old flake8 And it won't change your existing workflow.

invocation resuts

See "Usage" section in the docs for examples and integrations.

What we are about

The ultimate goal of this project is to make all people write exactly the same python code.

black mypy pylint flake8 wemake-python-styleguide
Formats code?
Finds style issues?
Finds bugs? 🤔
Finds complex code? 🤔
Has a
Collapse
 
raiderrobert profile image
Robert Roskam

@sobolevn , sweet! Always interested in tooling!

Collapse
 
laike9m profile image
laike9m

Sadly, flake8 does not support pyproject.toml yet

Collapse
 
bowmanjd profile image
Jonathan Bowman • Edited

I have recently grown familiar with FlakeHell, a wrapper around Flake8 that, among other things, allows configuration of Flake8 through pyproject.toml.

@raiderrobert , I love your article; it provided me a basic intro to flake8 when I needed it. Thank you!

Collapse
 
raiderrobert profile image
Robert Roskam

@laike9m , relevant to that point, here's the Gitlab ticket where that feature is being tracked: gitlab.com/pycqa/flake8/issues/428