Pylint
Bazel rules for the Python linter Pylint.
Setup
First ensure rules_venv
is setup by referring to rules_venv setup.
Next, the pylint
rules work mostly off of toolchains which are used to provide the necessary python targets (aka pylint
)
for the process wrappers. Users will want to make sure they have a way to get the necessary python dependencies. Tools such as
req-compile can provide these.
With the appropriate dependencies available, a py_pylint_toolchain will need to be configured:
load("@rules_venv//python/pylint:defs.bzl", "py_pylint_toolchain")
py_pylint_toolchain(
name = "toolchain_impl",
pylint = "@pip_deps//:pylint",
visibility = ["//visibility:public"]
)
toolchain(
name = "toolchain",
toolchain = ":toolchain_impl",
toolchain_type = "@rules_venv//python/pylint:toolchain_type",
visibility = ["//visibility:public"]
)
This toolchain then needs to be registered in the MODULE.bazel
file.
register_toolchains("//tools/python/pylint:toolchain")
From here, py_pylint_test and the py_pylint_aspect
should now be usable. Both of these rules use a global flag to determine which pylint configuration
file to use with in actions. The following snippet can be added to the .bazelrc
file to chose the
desired configuration file
build --@rules_pylint//python/pylint:config=//:.pylintrc.toml
Note that these files will need to be available via exports_files
Rules
Aspects
py_pylint_test
load("@rules_venv//python/pylint:defs.bzl", "py_pylint_test") py_pylint_test(name, config, target)
A rule for running pylint on a Python target.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
config | The config file (pylintrc) containing pylint settings. | Label | optional | "@rules_venv//python/pylint:config" |
target | The target to run pylint on. | Label | required |
py_pylint_toolchain
load("@rules_venv//python/pylint:defs.bzl", "py_pylint_toolchain") py_pylint_toolchain(name, pylint)
A toolchain for the pylint formatter rules.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
pylint | The pylint py_library to use with the rules. | Label | required |
py_pylint_aspect
load("@rules_venv//python/pylint:defs.bzl", "py_pylint_aspect") py_pylint_aspect()
An aspect for running pylint on targets with Python sources.
This aspect can be configured by adding the following snippet to a workspace's .bazelrc
file:
build --aspects=@rules_venv//python/pylint:defs.bzl%py_pylint_aspect
build --output_groups=+py_pylint_checks
ASPECT ATTRIBUTES
ATTRIBUTES