Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.aspect.build/llms.txt

Use this file to discover all available pages before exploring further.

API for declaring a Ruff lint aspect that visits py_binary, library, test rules. Typical usage: Ruff is provided as a built-in tool by rules_lint. To use the built-in version, create the linter aspect, typically in tools/lint/linters.bzl:
load("@aspect_rules_lint//lint:ruff.bzl", "lint_ruff_aspect")

ruff = lint_ruff_aspect(
    binary = Label("@aspect_rules_lint//lint:ruff_bin",
    configs = [Label("//:.ruff.toml")],
)

Using a specific ruff version

In MODULE.bazel, fetch the desired version from https://github.com/astral-sh/ruff/releases. In tools/lint/BUILD.bazel, select the tool for the host platform:
# Note: this won't interact properly with the --platform flag, see
# https://github.com/aspect-build/rules_lint/issues/389
alias(
    name = "ruff",
    actual = select({
        "@bazel_tools//src/conditions:linux_x86_64": "@ruff_x86_64-unknown-linux-gnu//:ruff",
        "@bazel_tools//src/conditions:linux_aarch64": "@ruff_aarch64-unknown-linux-gnu//:ruff",
        "@bazel_tools//src/conditions:darwin_arm64": "@ruff_aarch64-apple-darwin//:ruff",
        "@bazel_tools//src/conditions:darwin_x86_64": "@ruff_x86_64-apple-darwin//:ruff",
        "@bazel_tools//src/conditions:windows_x64": "@ruff_x86_64-pc-windows-msvc//:ruff.exe",
    }),
)
Finally, reference this tool alias rather than the one from @multitool:
ruff = lint_ruff_aspect(
    binary = "@@//tools/lint:ruff",
    ...
)

Function: ruff_action

Run ruff as an action under Bazel. Ruff will select the configuration file to use for each source file, as documented here: https://docs.astral.sh/ruff/configuration/#config-file-discovery Note: all config files are passed to the action. This means that a change to any config file invalidates the action cache entries for ALL ruff actions. However, this is important because:
  1. ruff has an extend field, so it may need to read more than one config file
  2. ruff’s logic for selecting the appropriate config needs to read the file content to detect a [tool.ruff] section.

Parameters

ctx
unknown
required
Bazel Rule or Aspect evaluation context
executable
unknown
required
label of the the ruff program
srcs
unknown
required
python files to be linted
config
unknown
required
labels of ruff config files (pyproject.toml, ruff.toml, or .ruff.toml)
stdout
unknown
required
output file of linter results to generate
exit_code
unknown
default:"None"
output file to write the exit code. If None, then fail the build when ruff exits non-zero. See https://github.com/astral-sh/ruff/blob/dfe4291c0b7249ae892f5f1d513e6f1404436c13/docs/linter.md#exit-codes
env
unknown
default:"{}"
environment variaables for ruff
patch
unknown
default:"None"
output file for patch (optional). If provided, uses run_patcher instead of run_shell.

Function: lint_ruff_aspect

A factory function to create a linter aspect. Attrs: binary: a ruff executable configs: ruff config file(s) (pyproject.toml, ruff.toml, or .ruff.toml) rule_kinds: which kinds of rules should be visited by the aspect filegroup_tags: filegroups tagged with these tags will be visited by the aspect in addition to Python rule kinds

Parameters

binary
unknown
required
configs
unknown
required
rule_kinds
unknown
default:"[\"py_binary\", \"py_library\", \"py_test\"]"
filegroup_tags
unknown
default:"[\"python\", \"lint-with-ruff\"]"

Repository rule: ruff_workaround_20269

Workaround for https://github.com/bazelbuild/bazel/issues/20269

Attributes

name
name
required
A unique name for this repository.
repo_mapping
dictionary: String → String
In WORKSPACE context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.For example, an entry "@foo": "@bar" declares that, for any time this repository depends on @foo (such as a dependency on @foo//some:target, it should actually resolve that dependency within globally-declared @bar (@bar//some:target).This attribute is not supported in MODULE.bazel context (when invoking a repository rule inside a module extension’s implementation function).
build_file_content
string
default:"\"\""
sha256
string
default:"\"\""
strip_prefix
string
default:"\"\""
unlike http_archive, any value causes us to pass —strip-components=1 to tar
url
string
default:"\"\""