Skip to content

Commit

Permalink
feat: include ruff in multitool (#309)
Browse files Browse the repository at this point in the history
* feat: include ruff in multitool

Continue to mirror prior versions, and document how a user could fetch an older version and use that instead of what our multitool.lock.json contains.

Ref #279
Ref aspect-build/aspect-workflows-template#70

* chore: don't include windows binaries yet

They prevent testing rules_lint on Bazel 6, due to something in rules_multitool
  • Loading branch information
alexeagle authored Jul 5, 2024
1 parent 25fd21d commit 562b84b
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 27 deletions.
44 changes: 41 additions & 3 deletions docs/ruff.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions example/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ load("@aspect_rules_lint//lint:pmd.bzl", "fetch_pmd")

fetch_pmd()

load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")

fetch_ruff()

load("@aspect_rules_lint//lint:vale.bzl", "fetch_vale")

fetch_vale()
Expand Down
3 changes: 0 additions & 3 deletions example/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ load(
"fetch_ktfmt",
"fetch_swiftformat",
)
load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")

fetch_java_format()

fetch_ktfmt()

fetch_swiftformat()

fetch_ruff()

load("@aspect_rules_lint//lint:pmd.bzl", "fetch_pmd")

fetch_pmd()
Expand Down
4 changes: 2 additions & 2 deletions example/tools/format/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ format_multirun(
kotlin = ":ktfmt",
markdown = ":prettier",
protocol_buffer = "//tools/lint:buf",
python = "//tools/lint:ruff",
python = "@aspect_rules_lint//format:ruff",
rust = "@rules_rust//tools/rustfmt:upstream_rustfmt",
scala = ":scalafmt",
shell = "@aspect_rules_lint//format:shfmt",
Expand Down Expand Up @@ -96,7 +96,7 @@ format_test(
markdown = ":prettier",
no_sandbox = True, # Enables formatting the entire workspace, paired with 'workspace' attribute
protocol_buffer = "//tools/lint:buf",
python = "//tools/lint:ruff",
python = "@aspect_rules_lint//format:ruff",
scala = ":scalafmt",
sql = ":prettier",
starlark = "@buildifier_prebuilt//:buildifier",
Expand Down
11 changes: 0 additions & 11 deletions example/tools/lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_cons

package(default_visibility = ["//:__subpackages__"])

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",
}),
)

alias(
name = "buf",
actual = "@rules_buf_toolchains//:buf",
Expand Down
2 changes: 1 addition & 1 deletion example/tools/lint/linters.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pmd = lint_pmd_aspect(
pmd_test = lint_test(aspect = pmd)

ruff = lint_ruff_aspect(
binary = "@@//tools/lint:ruff",
binary = "@multitool//tools/ruff",
configs = [
"@@//:.ruff.toml",
"@@//src/subdir:ruff.toml",
Expand Down
1 change: 1 addition & 0 deletions format/private/formatter_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ BUILTIN_TOOL_LABELS = {
"Shell": "@multitool//tools/shfmt",
"Terraform": "@multitool//tools/terraform",
"YAML": "@multitool//tools/yamlfmt",
"ruff": "@multitool//tools/ruff",
}

# Flags to pass each tool's CLI when running in check mode
Expand Down
36 changes: 36 additions & 0 deletions lint/multitool.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,41 @@
"cpu": "x86_64"
}
]
},
"ruff": {
"binaries": [
{
"kind": "archive",
"url": "https://github.com/astral-sh/ruff/releases/download/0.5.0/ruff-aarch64-apple-darwin.tar.gz",
"file": "ruff-aarch64-apple-darwin/ruff",
"sha256": "a9203ee067703ef9589cae0d78e3def76e855650d721f77057a3b60638302b36",
"os": "macos",
"cpu": "arm64"
},
{
"kind": "archive",
"url": "https://github.com/astral-sh/ruff/releases/download/0.5.0/ruff-x86_64-unknown-linux-musl.tar.gz",
"file": "ruff-x86_64-unknown-linux-musl/ruff",
"sha256": "32f4dce258b73f350dd4aab46e7ab54ff74ffb31f3ab2c46e7168f2afd624c78",
"os": "linux",
"cpu": "x86_64"
},
{
"kind": "archive",
"url": "https://github.com/astral-sh/ruff/releases/download/0.5.0/ruff-aarch64-unknown-linux-musl.tar.gz",
"file": "ruff-aarch64-unknown-linux-musl/ruff",
"sha256": "bc47a3ecff865b38385774fd6191347ecebc201b3a5c0fb56b6e75bc67757ff0",
"os": "linux",
"cpu": "arm64"
},
{
"kind": "archive",
"url": "https://github.com/astral-sh/ruff/releases/download/0.5.0/ruff-x86_64-apple-darwin.tar.gz",
"file": "ruff-x86_64-apple-darwin/ruff",
"sha256": "283a2d23af7d3b05173e34aade53c4d04694e44ca240b61e5b95c887a379eaf1",
"os": "macos",
"cpu": "x86_64"
}
]
}
}
43 changes: 40 additions & 3 deletions lint/ruff.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,45 @@ Typical usage:
load("@aspect_rules_lint//lint:ruff.bzl", "ruff_aspect")
ruff = ruff_aspect(
binary = "@@//:ruff",
binary = "@multitool//tools/ruff",
configs = "@@//:.ruff.toml",
)
```
## Using a specific ruff version
In `WORKSPACE`, fetch the desired version from https://github.com/astral-sh/ruff/releases
```starlark
load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff")
# Specify a tag from the ruff repository
fetch_ruff("v0.4.10")
```
In `tools/lint/BUILD.bazel`, select the tool for the host platform:
```starlark
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`:
```starlark
ruff = lint_ruff_aspect(
binary = "@@//tools/lint:ruff",
...
)
```
"""

load("@bazel_skylib//lib:versions.bzl", "versions")
Expand Down Expand Up @@ -195,8 +230,10 @@ ruff_workaround_20269 = repository_rule(
},
)

def fetch_ruff(tag = RUFF_VERSIONS.keys()[0]):
"""A repository macro used from WORKSPACE to fetch ruff binaries
def fetch_ruff(tag):
"""A repository macro used from WORKSPACE to fetch ruff binaries.
Allows the user to select a particular ruff version, rather than get whatever is pinned in the `multitool.lock.json` file.
Args:
tag: a tag of ruff that we have mirrored, e.g. `v0.1.0`
Expand Down

0 comments on commit 562b84b

Please sign in to comment.