44 fetchFromGitHub ,
55 installShellFiles ,
66 stdenv ,
7+ python3Packages ,
78 darwin ,
89 rust-jemalloc-sys ,
910 ruff-lsp ,
1011 nix-update-script ,
1112 versionCheckHook ,
13+ libiconv ,
1214} :
1315
14- rustPlatform . buildRustPackage rec {
16+ python3Packages . buildPythonPackage rec {
1517 pname = "ruff" ;
1618 version = "0.7.0" ;
19+ pyproject = true ;
20+
21+ outputs = [
22+ "bin"
23+ "out"
24+ ] ;
1725
1826 src = fetchFromGitHub {
1927 owner = "astral-sh" ;
@@ -22,26 +30,51 @@ rustPlatform.buildRustPackage rec {
2230 hash = "sha256-//ayB5ayYM5FqiSXDDns2tIL+PJ0Osvkp8+MEEL0L+8=" ;
2331 } ;
2432
25- cargoLock = {
33+ # Do not rely on path lookup at runtime to find the ruff binary
34+ postPatch = ''
35+ substituteInPlace python/ruff/__main__.py \
36+ --replace-fail \
37+ 'ruff_exe = "ruff" + sysconfig.get_config_var("EXE")' \
38+ 'return "${ placeholder "bin" } /bin/ruff"'
39+ '' ;
40+
41+ cargoDeps = rustPlatform . importCargoLock {
2642 lockFile = ./Cargo.lock ;
2743 outputHashes = {
2844 "lsp-types-0.95.1" = "sha256-8Oh299exWXVi6A39pALOISNfp8XBya8z+KT/Z7suRxQ=" ;
2945 "salsa-0.18.0" = "sha256-vuLgeaqIL8U+5PUHJaGdovHFapAMGGQ9nPAMJJnxz/o=" ;
3046 } ;
3147 } ;
3248
33- nativeBuildInputs = [ installShellFiles ] ;
49+ nativeBuildInputs =
50+ [ installShellFiles ]
51+ ++ ( with rustPlatform ; [
52+ cargoSetupHook
53+ maturinBuildHook
54+ cargoCheckHook
55+ ] ) ;
3456
35- buildInputs = [
36- rust-jemalloc-sys
37- ] ++ lib . optionals stdenv . hostPlatform . isDarwin [ darwin . apple_sdk . frameworks . CoreServices ] ;
57+ buildInputs =
58+ [
59+ rust-jemalloc-sys
60+ ]
61+ ++ lib . optionals stdenv . hostPlatform . isDarwin [
62+ darwin . apple_sdk . frameworks . CoreServices
63+ libiconv
64+ ] ;
3865
39- postInstall = lib . optionalString ( stdenv . buildPlatform . canExecute stdenv . hostPlatform ) ''
40- installShellCompletion --cmd ruff \
41- --bash <($out/bin/ruff generate-shell-completion bash) \
42- --fish <($out/bin/ruff generate-shell-completion fish) \
43- --zsh <($out/bin/ruff generate-shell-completion zsh)
44- '' ;
66+ postInstall =
67+ ''
68+ mkdir -p $bin/bin
69+ mv $out/bin/ruff $bin/bin/
70+ rmdir $out/bin
71+ ''
72+ + lib . optionalString ( stdenv . buildPlatform . canExecute stdenv . hostPlatform ) ''
73+ installShellCompletion --cmd ruff \
74+ --bash <($bin/bin/ruff generate-shell-completion bash) \
75+ --fish <($bin/bin/ruff generate-shell-completion fish) \
76+ --zsh <($bin/bin/ruff generate-shell-completion zsh)
77+ '' ;
4578
4679 passthru = {
4780 tests = {
@@ -50,6 +83,12 @@ rustPlatform.buildRustPackage rec {
5083 updateScript = nix-update-script { } ;
5184 } ;
5285
86+ # Run cargo tests
87+ cargoCheckType = "debug" ;
88+ postInstallCheck = ''
89+ cargoCheckHook
90+ '' ;
91+
5392 # Failing on darwin for an unclear reason.
5493 # According to the maintainers, those tests are from an experimental crate that isn't actually
5594 # used by ruff currently and can thus be safely skipped.
@@ -73,11 +112,12 @@ rustPlatform.buildRustPackage rec {
73112 "--skip=unix::symlink_inside_workspace"
74113 ] ;
75114
76- nativeInstallCheckInputs = [
115+ nativeCheckInputs = [
77116 versionCheckHook
78117 ] ;
79118 versionCheckProgramArg = [ "--version" ] ;
80- doInstallCheck = true ;
119+
120+ pythonImportsCheck = [ "ruff" ] ;
81121
82122 meta = {
83123 description = "Extremely fast Python linter" ;
0 commit comments