Skip to content

Commit d2d7c7e

Browse files
adisbladisGaetanLepage
authored andcommitted
ruff: Build as a standalone without Python
Using `buildPythonPackage` make `ruff` propagate the Python used for the build, which might not be the same Python as you want in your development shell. #350654 changed the ruff top-level attribute to be built with Python modules. This doesn't actually make much sense, we have versioned Python sets, and including just the one Python in the top-level package isn't helpful, and causes issues downstream related to PATH & PYTHONPATH. See my related [uv PR](#357113 (comment)).
1 parent 6815b62 commit d2d7c7e

File tree

4 files changed

+54
-44
lines changed

4 files changed

+54
-44
lines changed

pkgs/by-name/ru/ruff-lsp/package.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ python3Packages.buildPythonApplication rec {
3636
pytestCheckHook
3737
pytest-asyncio
3838
python-lsp-jsonrpc
39-
ruff.bin
39+
ruff
4040
versionCheckHook
4141
];
4242
versionCheckProgramArg = [ "--version" ];

pkgs/by-name/ru/ruff/package.nix

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
lib,
33
stdenv,
4-
python3Packages,
5-
fetchFromGitHub,
64
rustPlatform,
5+
fetchFromGitHub,
76
installShellFiles,
7+
88
rust-jemalloc-sys,
9+
buildPackages,
910
versionCheckHook,
1011

1112
# passthru
@@ -14,15 +15,9 @@
1415
nix-update-script,
1516
}:
1617

17-
python3Packages.buildPythonPackage rec {
18+
rustPlatform.buildRustPackage rec {
1819
pname = "ruff";
1920
version = "0.8.4";
20-
pyproject = true;
21-
22-
outputs = [
23-
"bin"
24-
"out"
25-
];
2621

2722
src = fetchFromGitHub {
2823
owner = "astral-sh";
@@ -31,46 +26,29 @@ python3Packages.buildPythonPackage rec {
3126
hash = "sha256-c5d2XaoEjCHWMdjTLD6CnwP8rpSXTUrmKSs0QWQ6UG0=";
3227
};
3328

34-
# Do not rely on path lookup at runtime to find the ruff binary
35-
postPatch = ''
36-
substituteInPlace python/ruff/__main__.py \
37-
--replace-fail \
38-
'ruff_exe = "ruff" + sysconfig.get_config_var("EXE")' \
39-
'return "${placeholder "bin"}/bin/ruff"'
40-
'';
29+
useFetchCargoVendor = true;
30+
cargoHash = "sha256-jbUjsIJRpkKYc+qHN8tkcZrcjPTFJfdCsatezzdX4Ss=";
4131

42-
cargoDeps = rustPlatform.fetchCargoVendor {
43-
inherit pname version src;
44-
hash = "sha256-jbUjsIJRpkKYc+qHN8tkcZrcjPTFJfdCsatezzdX4Ss=";
45-
};
46-
47-
nativeBuildInputs =
48-
[ installShellFiles ]
49-
++ (with rustPlatform; [
50-
cargoSetupHook
51-
maturinBuildHook
52-
cargoCheckHook
53-
]);
32+
nativeBuildInputs = [ installShellFiles ];
5433

5534
buildInputs = [
5635
rust-jemalloc-sys
5736
];
5837

5938
postInstall =
39+
let
40+
emulator = stdenv.hostPlatform.emulator buildPackages;
41+
in
6042
''
61-
mkdir -p $bin/bin
62-
mv $out/bin/ruff $bin/bin/
63-
rmdir $out/bin
64-
''
65-
+ lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
6643
installShellCompletion --cmd ruff \
67-
--bash <($bin/bin/ruff generate-shell-completion bash) \
68-
--fish <($bin/bin/ruff generate-shell-completion fish) \
69-
--zsh <($bin/bin/ruff generate-shell-completion zsh)
44+
--bash <(${emulator} $out/bin/ruff generate-shell-completion bash) \
45+
--fish <(${emulator} $out/bin/ruff generate-shell-completion fish) \
46+
--zsh <(${emulator} $out/bin/ruff generate-shell-completion zsh)
7047
'';
7148

7249
# Run cargo tests
73-
cargoCheckType = "debug";
50+
checkType = "debug";
51+
7452
# tests do not appear to respect linker options on doctests
7553
# Upstream issue: https://github.com/rust-lang/cargo/issues/14189
7654
# This causes errors like "error: linker `cc` not found" on static builds
@@ -106,12 +84,11 @@ python3Packages.buildPythonPackage rec {
10684
"--skip=unix::symlink_inside_workspace"
10785
];
10886

109-
nativeCheckInputs = [
87+
nativeInstallCheckInputs = [
11088
versionCheckHook
11189
];
11290
versionCheckProgramArg = [ "--version" ];
113-
114-
pythonImportsCheck = [ "ruff" ];
91+
doInstallCheck = true;
11592

11693
passthru = {
11794
tests =
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
buildPythonPackage,
3+
pkgs,
4+
rustPlatform,
5+
installShellFiles,
6+
}:
7+
8+
buildPythonPackage {
9+
inherit (pkgs.ruff)
10+
pname
11+
version
12+
src
13+
cargoDeps
14+
postInstall
15+
meta
16+
;
17+
18+
# Do not rely on path lookup at runtime to find the ruff binary
19+
postPatch = ''
20+
substituteInPlace python/ruff/__main__.py \
21+
--replace-fail \
22+
'ruff_exe = "ruff" + sysconfig.get_config_var("EXE")' \
23+
'return "${placeholder "out"}/bin/ruff"'
24+
'';
25+
26+
pyproject = true;
27+
28+
nativeBuildInputs = [
29+
installShellFiles
30+
rustPlatform.cargoSetupHook
31+
rustPlatform.maturinBuildHook
32+
];
33+
34+
pythonImportsCheck = [ "ruff" ];
35+
}

pkgs/top-level/python-packages.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14282,9 +14282,7 @@ self: super: with self; {
1428214282

1428314283
rubymarshal = callPackage ../development/python-modules/rubymarshal { };
1428414284

14285-
ruff = toPythonModule (pkgs.ruff.override {
14286-
python3Packages = self;
14287-
});
14285+
ruff = callPackage ../development/python-modules/ruff { };
1428814286

1428914287
ruff-api = callPackage ../development/python-modules/ruff-api { };
1429014288

0 commit comments

Comments
 (0)