Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions pkgs/development/python-modules/ruff/default.nix
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
{
buildPythonPackage,
hatchling,
lib,
ruff,
rustPlatform,
installShellFiles,
}:

buildPythonPackage {
inherit (ruff)
pname
version
src
cargoDeps
postInstall
meta
;
pyproject = true;

# Do not rely on path lookup at runtime to find the ruff binary
postPatch = ''
substituteInPlace python/ruff/__main__.py \
--replace-fail \
'ruff_exe = "ruff" + sysconfig.get_config_var("EXE")' \
'return "${placeholder "out"}/bin/ruff"'
'';
build-system = [ hatchling ];

pyproject = true;
postPatch =
# Do not rely on path lookup at runtime to find the ruff binary.
# Use the propagated binary instead.
''
substituteInPlace python/ruff/__main__.py \
--replace-fail \
'ruff_exe = "ruff" + sysconfig.get_config_var("EXE")' \
'return "${lib.getExe ruff}"'
''
# Sidestep the maturin build system in favour of reusing the binary already built by nixpkgs,
# to avoid rebuilding the ruff binary for every active python package set.
+ ''
substituteInPlace pyproject.toml \
--replace-fail 'requires = ["maturin>=1.0,<2.0"]' 'requires = ["hatchling"]' \
--replace-fail 'build-backend = "maturin"' 'build-backend = "hatchling.build"'

nativeBuildInputs = [
installShellFiles
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];
cat >> pyproject.toml <<EOF
[tool.hatch.build]
packages = ['python/ruff']

EOF
'';

postInstall = ''
mkdir -p $out/bin && ln -s ${lib.getExe ruff} $out/bin/ruff
'';

pythonImportsCheck = [ "ruff" ];
}