> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# @aspect_rules_lint//lint:flake8.bzl

> Bazel rules_lint flake8 integration: lint_flake8_aspect to run the flake8 Python linter as a Bazel aspect over py_library and other Python rules.

<Callout icon="book">
  Documentation for [@aspect\_rules\_lint@v2.3.0](https://registry.bazel.build/modules/aspect_rules_lint/2.3.0) -- <Icon icon="github" iconType="brands" /> [View source](https://github.com/aspect-build/rules_lint/blob/v2.3.0/lint/flake8.bzl)
</Callout>

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`:

```python theme={null}
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`:

```python theme={null}
load("@aspect_rules_lint//lint:flake8.bzl", "lint_flake8_aspect")

flake8 = lint_flake8_aspect(
    binary = Label("//tools/lint:flake8"),
    config = Label("//:.flake8"),
)
```

## Function: `flake8_action`

Run flake8 as an action under Bazel.

Based on [https://flake8.pycqa.org/en/latest/user/invocation.html](https://flake8.pycqa.org/en/latest/user/invocation.html)

### Parameters

<ParamField body="ctx" type="unknown" required>
  Bazel Rule or Aspect evaluation context
</ParamField>

<ParamField body="executable" type="unknown" required>
  label of the flake8 program
</ParamField>

<ParamField body="srcs" type="unknown" required>
  python files to be linted
</ParamField>

<ParamField body="config" type="unknown" required>
  label of the flake8 config file (setup.cfg, tox.ini, or .flake8)
</ParamField>

<ParamField body="stdout" type="unknown" required>
  output file containing stdout of flake8
</ParamField>

<ParamField body="exit_code" type="unknown" default={`None`}>
  output file containing exit code of flake8
  If None, then fail the build when flake8 exits non-zero.
</ParamField>

<ParamField body="options" type="unknown" default={`[]`}>
  additional command-line options, see [https://flake8.pycqa.org/en/latest/user/options.html](https://flake8.pycqa.org/en/latest/user/options.html)
</ParamField>

## Function: `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`)

### Parameters

<ParamField body="binary" type="unknown" required />

<ParamField body="config" type="unknown" required />

<ParamField body="rule_kinds" type="unknown" default={`["py_binary", "py_library"]`} />
