Unverified Commit 90c84a98 authored by Gaétan Lepage's avatar Gaétan Lepage Committed by GitHub
Browse files

ruff: move to buildPythonPackage (#350654)

parents b021a000 6f3c4aab
Loading
Loading
Loading
Loading
+54 −14
Original line number Diff line number Diff line
@@ -4,16 +4,24 @@
  fetchFromGitHub,
  installShellFiles,
  stdenv,
  python3Packages,
  darwin,
  rust-jemalloc-sys,
  ruff-lsp,
  nix-update-script,
  versionCheckHook,
  libiconv,
}:

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

  outputs = [
    "bin"
    "out"
  ];

  src = fetchFromGitHub {
    owner = "astral-sh";
@@ -22,7 +30,15 @@ rustPlatform.buildRustPackage rec {
    hash = "sha256-//ayB5ayYM5FqiSXDDns2tIL+PJ0Osvkp8+MEEL0L+8=";
  };

  cargoLock = {
  # 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 "bin"}/bin/ruff"'
  '';

  cargoDeps = rustPlatform.importCargoLock {
    lockFile = ./Cargo.lock;
    outputHashes = {
      "lsp-types-0.95.1" = "sha256-8Oh299exWXVi6A39pALOISNfp8XBya8z+KT/Z7suRxQ=";
@@ -30,17 +46,34 @@ rustPlatform.buildRustPackage rec {
    };
  };

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

  buildInputs = [
  buildInputs =
    [
      rust-jemalloc-sys
  ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.CoreServices ];
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin [
      darwin.apple_sdk.frameworks.CoreServices
      libiconv
    ];

  postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
  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 <($out/bin/ruff generate-shell-completion bash) \
      --fish <($out/bin/ruff generate-shell-completion fish) \
      --zsh <($out/bin/ruff generate-shell-completion zsh)
        --bash <($bin/bin/ruff generate-shell-completion bash) \
        --fish <($bin/bin/ruff generate-shell-completion fish) \
        --zsh <($bin/bin/ruff generate-shell-completion zsh)
    '';

  passthru = {
@@ -50,6 +83,12 @@ rustPlatform.buildRustPackage rec {
    updateScript = nix-update-script { };
  };

  # 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
  # used by ruff currently and can thus be safely skipped.
@@ -73,11 +112,12 @@ rustPlatform.buildRustPackage rec {
    "--skip=unix::symlink_inside_workspace"
  ];

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

  pythonImportsCheck = [ "ruff" ];

  meta = {
    description = "Extremely fast Python linter";
+4 −0
Original line number Diff line number Diff line
@@ -13915,6 +13915,10 @@ self: super: with self; {
  rubymarshal = callPackage ../development/python-modules/rubymarshal { };
  ruff = toPythonModule (pkgs.ruff.override {
    python3Packages = self;
  });
  ruff-api = callPackage ../development/python-modules/ruff-api { };
  ruffus = callPackage ../development/python-modules/ruffus { };