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 authored and GaetanLepage committed Dec 24, 2024
1 parent 6815b62 commit d4873da
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 40 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
52 changes: 16 additions & 36 deletions pkgs/by-name/ru/ruff/package.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
lib,
stdenv,
python3Packages,
fetchFromGitHub,
rustPlatform,
fetchFromGitHub,
installShellFiles,

rust-jemalloc-sys,
versionCheckHook,

Expand All @@ -14,15 +14,9 @@
nix-update-script,
}:

python3Packages.buildPythonPackage rec {
rustPlatform.buildRustPackage rec {
pname = "ruff";
version = "0.8.4";
pyproject = true;

outputs = [
"bin"
"out"
];

src = fetchFromGitHub {
owner = "astral-sh";
Expand All @@ -39,38 +33,25 @@ python3Packages.buildPythonPackage rec {
'return "${placeholder "bin"}/bin/ruff"'
'';

cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
hash = "sha256-jbUjsIJRpkKYc+qHN8tkcZrcjPTFJfdCsatezzdX4Ss=";
};
useFetchCargoVendor = true;
cargoHash = "sha256-jbUjsIJRpkKYc+qHN8tkcZrcjPTFJfdCsatezzdX4Ss=";

nativeBuildInputs =
[ installShellFiles ]
++ (with rustPlatform; [
cargoSetupHook
maturinBuildHook
cargoCheckHook
]);
nativeBuildInputs = [ installShellFiles ];

buildInputs = [
rust-jemalloc-sys
];

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)
'';

# Run cargo tests
cargoCheckType = "debug";
checkType = "debug";

# tests do not appear to respect linker options on doctests
# Upstream issue: https://github.com/rust-lang/cargo/issues/14189
# This causes errors like "error: linker `cc` not found" on static builds
Expand Down Expand Up @@ -106,12 +87,11 @@ python3Packages.buildPythonPackage rec {
"--skip=unix::symlink_inside_workspace"
];

nativeCheckInputs = [
nativeInstallCheckInputs = [
versionCheckHook
];
versionCheckProgramArg = [ "--version" ];

pythonImportsCheck = [ "ruff" ];
doInstallCheck = true;

passthru = {
tests =
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
meta
;

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 @@ -14282,9 +14282,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 d4873da

Please sign in to comment.