Skip to main content
Version: 0.18.x

flake8

API for declaring a flake8 lint aspect that visits py_library rules.

Typical usage:

First, fetch the flake8 package via your standard requirements file and pip calls.

Then, declare a binary target for it, typically in tools/lint/BUILD.bazel:

load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")
py_console_script_binary(
name = "flake8",
pkg = "@pip//flake8:pkg",
)

Finally, create the linter aspect, typically in tools/lint/linters.bzl:

load("@aspect_rules_lint//lint:flake8.bzl", "flake8_aspect")

flake8 = flake8_aspect(
binary = "@@//tools/lint:flake8",
config = "@@//:.flake8",
)

Macros and Functions

flake8_action

Run flake8 as an action under Bazel.

Based on https://flake8.pycqa.org/en/latest/user/invocation.html

Example usage (generated):

load("@aspect_rules_lint//lint:flake8.bzl", "flake8_action")

flake8_action(
# Bazel Rule or Aspect evaluation context
ctx = None,
# label of the the flake8 program
executable = None,
# python files to be linted
srcs = [],
# label of the flake8 config file (setup.cfg, tox.ini, or .flake8)
config = None,
# output file to generate
report = None,
)

ctx

Required.

Bazel Rule or Aspect evaluation context

executable

Required.

label of the the flake8 program

srcs

Required.

python files to be linted

config

Required.

label of the flake8 config file (setup.cfg, tox.ini, or .flake8)

report

Required.

output file to generate

use_exit_code

Optional. Default: False

whether to fail the build when a lint violation is reported

lint_flake8_aspect

A factory function to create a linter aspect.

Attrs: binary: a flake8 executable. Can be obtained from rules_python like so:

    load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary")

py_console_script_binary(
name = "flake8",
pkg = "@pip//flake8:pkg",
)

config: the flake8 config file (`setup.cfg`, `tox.ini`, or `.flake8`)

Example usage (generated):

load("@aspect_rules_lint//lint:flake8.bzl", "lint_flake8_aspect")

lint_flake8_aspect(
binary = None,
config = None,
)

binary

Required.

config

Required.