From 1facbb3909d530d9a8b75bfc6f7f25e6604159b6 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Fri, 22 Nov 2024 00:04:52 +0000 Subject: [PATCH] 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. https://github.com/NixOS/nixpkgs/pull/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](https://github.com/NixOS/nixpkgs/pull/357113#issue-2670270577). --- pkgs/by-name/ru/ruff/package.nix | 28 ++++++------------- .../python-modules/ruff/default.nix | 28 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 4 +-- 3 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 pkgs/development/python-modules/ruff/default.nix diff --git a/pkgs/by-name/ru/ruff/package.nix b/pkgs/by-name/ru/ruff/package.nix index 7bbb02e100b473..48039b1b2fa141 100644 --- a/pkgs/by-name/ru/ruff/package.nix +++ b/pkgs/by-name/ru/ruff/package.nix @@ -4,7 +4,6 @@ fetchFromGitHub, installShellFiles, stdenv, - python3Packages, darwin, rust-jemalloc-sys, ruff-lsp, @@ -13,15 +12,9 @@ libiconv, }: -python3Packages.buildPythonPackage rec { +stdenv.mkDerivation rec { pname = "ruff"; version = "0.7.4"; - pyproject = true; - - outputs = [ - "bin" - "out" - ]; src = fetchFromGitHub { owner = "astral-sh"; @@ -50,7 +43,8 @@ python3Packages.buildPythonPackage rec { [ installShellFiles ] ++ (with rustPlatform; [ cargoSetupHook - maturinBuildHook + cargoBuildHook + cargoInstallHook cargoCheckHook ]); @@ -64,16 +58,11 @@ python3Packages.buildPythonPackage rec { ]; postInstall = - '' - mkdir -p $bin/bin - mv $out/bin/ruff $bin/bin/ - rmdir $out/bin - '' - + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' installShellCompletion --cmd ruff \ - --bash <($bin/bin/ruff generate-shell-completion bash) \ - --fish <($bin/bin/ruff generate-shell-completion fish) \ - --zsh <($bin/bin/ruff generate-shell-completion zsh) + --bash <($out/bin/ruff generate-shell-completion bash) \ + --fish <($out/bin/ruff generate-shell-completion fish) \ + --zsh <($out/bin/ruff generate-shell-completion zsh) ''; passthru = { @@ -84,6 +73,7 @@ python3Packages.buildPythonPackage rec { }; # Run cargo tests + cargoBuildType = "release"; cargoCheckType = "debug"; postInstallCheck = '' cargoCheckHook @@ -119,8 +109,6 @@ python3Packages.buildPythonPackage rec { ]; versionCheckProgramArg = [ "--version" ]; - pythonImportsCheck = [ "ruff" ]; - meta = { description = "Extremely fast Python linter"; homepage = "https://github.com/astral-sh/ruff"; diff --git a/pkgs/development/python-modules/ruff/default.nix b/pkgs/development/python-modules/ruff/default.nix new file mode 100644 index 00000000000000..216a168a05564f --- /dev/null +++ b/pkgs/development/python-modules/ruff/default.nix @@ -0,0 +1,28 @@ +{ + buildPythonPackage, + pkgs, + rustPlatform, + installShellFiles, +}: + +buildPythonPackage { + inherit (pkgs.ruff) + pname + version + src + postPatch + cargoDeps + postInstall + ; + + pyproject = true; + + nativeBuildInputs = [ + installShellFiles + rustPlatform.cargoSetupHook + rustPlatform.maturinBuildHook + ]; + + pythonImportsCheck = [ "ruff" ]; +} + diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 62a1df04f4d3e4..e1c33ff5879e21 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -14118,9 +14118,7 @@ self: super: with self; { rubymarshal = callPackage ../development/python-modules/rubymarshal { }; - ruff = toPythonModule (pkgs.ruff.override { - python3Packages = self; - }); + ruff = callPackage ../development/python-modules/ruff { }; ruff-api = callPackage ../development/python-modules/ruff-api { };