From 33907ce1a7bdb741034eb4b4ce4217f5bfb3f261 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Sun, 9 Jun 2024 12:58:27 +0100 Subject: [PATCH] Add aspect_rules_lint Python formatting with Ruff --- .github/workflows/licence-checker.yml | 2 ++ BUILD | 16 ++++++++++++++++ WORKSPACE | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/.github/workflows/licence-checker.yml b/.github/workflows/licence-checker.yml index dbccb93..04d5daf 100644 --- a/.github/workflows/licence-checker.yml +++ b/.github/workflows/licence-checker.yml @@ -22,5 +22,7 @@ jobs: with: # TODO: Check on Python 3.8 too python-version: 3.6 + - name: Check formatting with Ruff + run: bazel run :format.check - name: Run Licence Checker run: bazel run //:licence-check diff --git a/BUILD b/BUILD index 1d8990a..865bf5d 100644 --- a/BUILD +++ b/BUILD @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 load("//rules:rules.bzl", "licence_check") +load("@aspect_rules_lint//format:defs.bzl", "format_multirun") licence_check( name = "licence-check", @@ -13,3 +14,18 @@ licence_check( SPDX-License-Identifier: Apache-2.0 """, ) + +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", + }), +) + +format_multirun( + name = "format", + python = ":ruff", +) diff --git a/WORKSPACE b/WORKSPACE index 9ad898c..8780f08 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -12,3 +12,29 @@ lowrisc_misc_linters_dependencies() load("//rules:pip.bzl", "lowrisc_misc_linters_pip_dependencies") lowrisc_misc_linters_pip_dependencies() + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "aspect_rules_lint", + sha256 = "6da562afb6e328757eb29f3ad044e273317371139d245eac0a74b60173d36025", + strip_prefix = "rules_lint-1.0.0-rc3", + url = "https://github.com/aspect-build/rules_lint/releases/download/v1.0.0-rc3/rules_lint-v1.0.0-rc3.tar.gz", +) + +# aspect_rules_lint depends on aspect_bazel_lib. Either 1.x or 2.x works. +http_archive( + name = "aspect_bazel_lib", + sha256 = "6d758a8f646ecee7a3e294fbe4386daafbe0e5966723009c290d493f227c390b", + strip_prefix = "bazel-lib-2.7.7", + url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.7/bazel-lib-v2.7.7.tar.gz", +) +load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies") + +# aspect_bazel_lib depends on bazel_skylib +aspect_bazel_lib_dependencies() + +load("@aspect_rules_lint//format:repositories.bzl", "rules_lint_dependencies") +rules_lint_dependencies() + +load("@aspect_rules_lint//lint:ruff.bzl", "fetch_ruff") +fetch_ruff()