From cc5ea3d455e6b4f382c9e12ae1a678eb625c0a0a 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-lsp/package.nix | 2 +- pkgs/by-name/ru/ruff/package.nix | 53 ++++++------------- .../python-modules/ruff/default.nix | 27 ++++++++++ pkgs/top-level/python-packages.nix | 4 +- 4 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 pkgs/development/python-modules/ruff/default.nix diff --git a/pkgs/by-name/ru/ruff-lsp/package.nix b/pkgs/by-name/ru/ruff-lsp/package.nix index 97b905e340c3c6..6214bb2d9332d4 100644 --- a/pkgs/by-name/ru/ruff-lsp/package.nix +++ b/pkgs/by-name/ru/ruff-lsp/package.nix @@ -36,7 +36,7 @@ python3Packages.buildPythonApplication rec { pytestCheckHook pytest-asyncio python-lsp-jsonrpc - ruff.bin + ruff versionCheckHook ]; versionCheckProgramArg = [ "--version" ]; diff --git a/pkgs/by-name/ru/ruff/package.nix b/pkgs/by-name/ru/ruff/package.nix index 2449165caeb0e0..d4b820b834d924 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, @@ -14,15 +13,9 @@ nixosTests, }: -python3Packages.buildPythonPackage rec { +rustPlatform.buildRustPackage rec { pname = "ruff"; version = "0.8.0"; - pyproject = true; - - outputs = [ - "bin" - "out" - ]; src = fetchFromGitHub { owner = "astral-sh"; @@ -39,18 +32,10 @@ python3Packages.buildPythonPackage rec { 'return "${placeholder "bin"}/bin/ruff"' ''; - cargoDeps = rustPlatform.fetchCargoVendor { - inherit pname version src; - hash = "sha256-O5+uVYWtSMEj7hBrc/FUuqRBN4hUlEbtDPF42kpL7PA="; - }; + useFetchCargoVendor = true; + cargoHash = "sha256-O5+uVYWtSMEj7hBrc/FUuqRBN4hUlEbtDPF42kpL7PA="; - nativeBuildInputs = - [ installShellFiles ] - ++ (with rustPlatform; [ - cargoSetupHook - maturinBuildHook - cargoCheckHook - ]); + nativeBuildInputs = [ installShellFiles ]; buildInputs = [ @@ -61,18 +46,12 @@ python3Packages.buildPythonPackage rec { libiconv ]; - postInstall = - '' - mkdir -p $bin/bin - mv $out/bin/ruff $bin/bin/ - rmdir $out/bin - '' - + 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) - ''; + postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' + installShellCompletion --cmd ruff \ + --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 = { tests = { @@ -82,11 +61,11 @@ python3Packages.buildPythonPackage rec { updateScript = nix-update-script { }; }; - # Run cargo tests - cargoCheckType = "debug"; - postInstallCheck = '' - cargoCheckHook - ''; + # # Run cargo tests + # cargoCheckType = "debug"; + # postInstallCheck = '' + # cargoCheckHook + # ''; # Failing on darwin for an unclear reason. # According to the maintainers, those tests are from an experimental crate that isn't actually @@ -121,8 +100,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..4686db2c5db03c --- /dev/null +++ b/pkgs/development/python-modules/ruff/default.nix @@ -0,0 +1,27 @@ +{ + 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 b9010ea5411dbb..609778c4b60f2b 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -14115,9 +14115,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 { };