Skip to main content

flake8 plugin to call black as a code style validator

Project description

Released on the Python Package Index (PyPI) Testing with TravisCI Landscape Code Metrics

Introduction

This is an MIT licensed flake8 plugin for validating Python code style with the command line code formatting tool black. It is available to install from the Python Package Index (PyPI):

Black, “The Uncompromising Code Formatter”, is normally run to edit your Python code in place to match their coding style, a strict subset of the PEP 8 style guide.

The point of this plugin is to be able to run black --check ... from within the flake8 plugin ecosystem. You might use this via a git pre-commit hook, or as part of your continuous integration testing.

Flake8 Validation codes

Early versions of flake8 assumed a single character prefix for the validation codes, which became problematic with collisions in the plugin ecosystem. Since v3.0, flake8 has supported longer prefixes therefore this plugin uses BLK as its prefix.

Code

Description

BLK100

Black would make changes.

BLK9##

Internal error (various).

Installation and usage

Python 3.6 or later is required to run black, so that is recommanded but black can be used on Python code written for older versions of Python.

Install flake8-black using pip, which should install flake8 and black as well if not already present:

$ pip install flake8-black

The new validator should be automatically included when using flake8 which may now report additional validation codes starting with BLK (as defined above). For example:

$ flake8 example.py

You can request only the BLK codes be shown using:

$ flake8 --select BLK example.py

We recommend using the following settings in your flake8 configuration, for example in your .flake8 configuration:

[flake8]
# Recommend matching the black default line length of 88,
# rather than the flake8 default of 79:
max-line-length = 88
extend-ignore =
    # See https://github.com/PyCQA/pycodestyle/issues/373
    E203,

In order not to trigger flake8’s E501 line too long errors, the plugin passes the flake8 maximum line length when it calls black, equivalent to doing black -l 88 --check *.py at the command line.

Note currently pycodestyle gives false positives on the spaces black uses for slices, which flake8 reports as E203: whitespace before ':'. Until this is fixed, and flake8 is updated, we suggest disabling this style check.

Version History

Version

Released

Changes

v0.0.1

2019-01-10

  • Initial public release.

Developers

This plugin is on GitHub at https://github.com/peterjc/flake8-black

To make a new release once tested locally and on TravisCI:

$ git tag vX.Y.Z
$ python setup.py sdist --formats=gztar
$ twine upload dist/flake8-black-X.Y.Z.tar.gz
$ git push origin master --tags

TODO

  • Define different error codes based on what changes black would make?

  • Create a full test suite and use this for continuous integration.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-black-0.0.1.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file flake8-black-0.0.1.tar.gz.

File metadata

  • Download URL: flake8-black-0.0.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

File hashes

Hashes for flake8-black-0.0.1.tar.gz
Algorithm Hash digest
SHA256 23d206c02f71255c4f31aabab7cc2a9ed7f8aed32589b147d5497f334dfd65fa
MD5 e1bb38a296422c938e4528cd145a5290
BLAKE2b-256 35a4e5d92ab2074f1d15f5313b41d94198c8820d98ecc5acda2488894b499324

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page