1{
2 lib,
3 buildPythonPackage,
4 pythonOlder,
5 fetchFromGitHub,
6
7 ruff,
8
9 # dependencies
10 cattrs,
11 lsprotocol,
12 python-lsp-server,
13 tomli,
14
15 # checks
16 pytestCheckHook,
17}:
18
19buildPythonPackage rec {
20 pname = "python-lsp-ruff";
21 version = "2.2.2";
22 pyproject = true;
23 disabled = pythonOlder "3.8";
24
25 src = fetchFromGitHub {
26 owner = "python-lsp";
27 repo = "python-lsp-ruff";
28 rev = "refs/tags/v${version}";
29 hash = "sha256-czGA/gl7uoWG9UqYUaY9zER79IKfv7ClqgimgyNCAa4=";
30 };
31
32 postPatch = ''
33 # ruff binary is used directly, the ruff python package is not needed
34 sed -i '/"ruff>=/d' pyproject.toml
35 sed -i 's|sys.executable, "-m", "ruff"|"${ruff}/bin/ruff"|' pylsp_ruff/plugin.py
36 sed -i -e '/sys.executable/,+2c"${ruff}/bin/ruff",' -e 's|assert "ruff" in call_args|assert "${ruff}/bin/ruff" in call_args|' tests/test_ruff_lint.py
37 # Nix builds everything in /build/ but ruff somehow doesn't run on files in /build/ and outputs empty results.
38 sed -i -e "s|workspace.root_path|'/tmp/'|g" tests/*.py
39 '';
40
41 dependencies = [
42 cattrs
43 lsprotocol
44 python-lsp-server
45 ] ++ lib.optionals (pythonOlder "3.11") [ tomli ];
46
47 nativeCheckInputs = [ pytestCheckHook ];
48
49 meta = {
50 homepage = "https://github.com/python-lsp/python-lsp-ruff";
51 description = "Ruff linting plugin for pylsp";
52 changelog = "https://github.com/python-lsp/python-lsp-ruff/releases/tag/v${version}";
53 license = lib.licenses.mit;
54 maintainers = with lib.maintainers; [ linsui ];
55 };
56}