Skip to content

Commit

Permalink
ruff: Build as a standalone without Python
Browse files Browse the repository at this point in the history
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)).
  • Loading branch information
adisbladis committed Nov 22, 2024
1 parent 351d61c commit 1facbb3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
28 changes: 8 additions & 20 deletions pkgs/by-name/ru/ruff/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
fetchFromGitHub,
installShellFiles,
stdenv,
python3Packages,
darwin,
rust-jemalloc-sys,
ruff-lsp,
Expand All @@ -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";
Expand Down Expand Up @@ -50,7 +43,8 @@ python3Packages.buildPythonPackage rec {
[ installShellFiles ]
++ (with rustPlatform; [
cargoSetupHook
maturinBuildHook
cargoBuildHook
cargoInstallHook
cargoCheckHook
]);

Expand All @@ -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 = {
Expand All @@ -84,6 +73,7 @@ python3Packages.buildPythonPackage rec {
};

# Run cargo tests
cargoBuildType = "release";
cargoCheckType = "debug";
postInstallCheck = ''
cargoCheckHook
Expand Down Expand Up @@ -119,8 +109,6 @@ python3Packages.buildPythonPackage rec {
];
versionCheckProgramArg = [ "--version" ];

pythonImportsCheck = [ "ruff" ];

meta = {
description = "Extremely fast Python linter";
homepage = "https://github.com/astral-sh/ruff";
Expand Down
28 changes: 28 additions & 0 deletions pkgs/development/python-modules/ruff/default.nix
Original file line number Diff line number Diff line change
@@ -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" ];
}

4 changes: 1 addition & 3 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };

Expand Down

0 comments on commit 1facbb3

Please sign in to comment.