> ## 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:pylint.bzl

> Bazel rules_lint Pylint integration: lint_pylint_aspect to run the Pylint Python linter as a Bazel aspect across py_binary, py_library, and py_test.

<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/pylint.bzl)
</Callout>

API for declaring a pylint lint aspect that visits Python rules.

Typical usage:

First, fetch the pylint 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 = "pylint",
    pkg = "@pip//pylint:pkg",
)
```

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

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

pylint = lint_pylint_aspect(
    binary = Label("//tools/lint:pylint"),
    config = Label("//:.pylintrc"),
)
```

## Function: `pylint_action`

Run pylint as an action under Bazel.

Based on [https://pylint.readthedocs.io/en/stable/user\_guide/run.html](https://pylint.readthedocs.io/en/stable/user_guide/run.html)

### Parameters

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

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

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

<ParamField body="config" type="unknown" required>
  label of the pylint config file (pyproject.toml, .pylintrc, or setup.cfg)
</ParamField>

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

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

<ParamField body="options" type="unknown" default={`[]`}>
  additional command-line options
</ParamField>

## Function: `lint_pylint_aspect`

A factory function to create a linter aspect.

### Parameters

<ParamField body="binary" type="unknown" required>
  a pylint executable. Obtain 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 = "pylint",
  pkg = "@pip//pylint:pkg",
  )
</ParamField>

<ParamField body="config" type="unknown" required>
  the pylint config file (`pyproject.toml`, `pylintrc`, or `.pylintrc`)
</ParamField>

<ParamField body="rule_kinds" type="unknown" default={`["py_binary", "py_library", "py_test"]`}>
  which [kinds](https://bazel.build/query/language#kind) of rules should be visited by the aspect
</ParamField>

<ParamField body="filegroup_tags" type="unknown" default={`["python", "lint-with-pylint"]`}>
  filegroups tagged with these tags will also be visited by the aspect
</ParamField>
