pythongitflake8

Per-project flake8 max line length?


I'm using a Flake8 git hook in my project and I want to relax the line length limit, but only for one project. Given that it looks like there's no clear API for that, how do I modify this hook to do that? Alternatively, is there a git-config setting or an environment variable that would let me set that? Here's the hook source code:

#!/usr/bin/env python
import os
import sys
import logging
import os.path as P

from flake8.main import git


if __name__ == '__main__':
    ret = git.hook(
        strict=git.config_for('strict'),
        lazy=git.config_for('lazy'),
    )
    if ret:
        sys.exit(ret)

Solution

  • Use the setup.cfg file in each project. This file is read by various Python-related tools, including pep8 (see pep8's documentation) and flake8.

    The documentation for setup.cfg with flake8 is in the Configuring Flake8 chapter. In short, you want a setup.cfg file with this content (obviously, adjust the 99 to your needs):

    [flake8]
    max-line-length = 99
    

    If you don't want to create a setup.cfg file, you can also specify this as an argument to the command:

    flake8 --max-line-length 99