Skip to content

Commit b0afbf5

Browse files
authored
tools: do not hardcode path to Ruff
Allows user to get Ruff from other source than Pip (e.g. Nix). Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #65681 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Richard Lau <richard.lau@ibm.com>
1 parent 26bd28c commit b0afbf5

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
BUILDTYPE ?= Release
44
PYTHON ?= python3
5+
RUFF ?= tools/pip/site-packages/bin/ruff
56
DESTDIR ?=
67
SIGN ?=
78
PREFIX ?= /usr/local
@@ -1694,15 +1695,15 @@ lint-py-build: ## Build resources needed to lint python files.
16941695
$(PYTHON) -m pip install --upgrade --system --target tools/pip/site-packages ruff==0.13.1
16951696

16961697
.PHONY: lint-py lint-py-fix lint-py-fix-unsafe
1697-
ifneq ("","$(wildcard tools/pip/site-packages/ruff)")
1698+
ifneq ("","$(wildcard $(RUFF))")
16981699
# Lint the Python code with ruff.
16991700
lint-py:
17001701
$(info Running Python linter...)
1701-
tools/pip/site-packages/bin/ruff check .
1702+
$(RUFF) check .
17021703
lint-py-fix:
1703-
tools/pip/site-packages/bin/ruff check . --fix
1704+
$(RUFF) check . --fix
17041705
lint-py-fix-unsafe:
1705-
tools/pip/site-packages/bin/ruff check . --fix --unsafe-fixes
1706+
$(RUFF) check . --fix --unsafe-fixes
17061707
else
17071708
lint-py lint-py-fix lint-py-fix-unsafe:
17081709
$(warning Python linting with ruff is not available)

shell.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ pkgs.mkShell {
141141
)
142142
);
143143
}
144+
// (
145+
let
146+
ruff = pkgs.lib.lists.findFirst (p: p.meta.mainProgram == "ruff") null devTools;
147+
in
148+
pkgs.lib.optionalAttrs (ruff != null) {
149+
RUFF = pkgs.lib.getExe ruff;
150+
}
151+
)
144152
// pkgs.lib.optionalAttrs (!withSQLite) {
145153
NOSQLITE = "1";
146154
}

tools/nix/devTools.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
pkgs.gh
88
pkgs.git
99
pkgs.jq
10+
pkgs.ruff
1011
pkgs.shellcheck
1112
]
1213
++ (

0 commit comments

Comments
 (0)