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