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 23, 2024
1 parent a112c12 commit e1cd562
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion pkgs/by-name/ru/ruff-lsp/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ python3Packages.buildPythonApplication rec {
pytestCheckHook
pytest-asyncio
python-lsp-jsonrpc
ruff.bin
ruff
versionCheckHook
];
versionCheckProgramArg = [ "--version" ];
Expand Down
50 changes: 12 additions & 38 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 @@ -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";
Expand All @@ -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 =
[
Expand All @@ -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 = {
Expand All @@ -82,11 +61,8 @@ python3Packages.buildPythonPackage rec {
updateScript = nix-update-script { };
};

# Run cargo tests
cargoCheckType = "debug";
postInstallCheck = ''
cargoCheckHook
'';
# # Run cargo tests
checkType = "debug";

# Failing on darwin for an unclear reason.
# According to the maintainers, those tests are from an experimental crate that isn't actually
Expand Down Expand Up @@ -121,8 +97,6 @@ python3Packages.buildPythonPackage rec {
];
versionCheckProgramArg = [ "--version" ];

pythonImportsCheck = [ "ruff" ];

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

Expand Down

0 comments on commit e1cd562

Please sign in to comment.