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.3.0"; 22 pyproject = true; 23 24 src = fetchFromGitHub { 25 owner = "python-lsp"; 26 repo = "python-lsp-ruff"; 27 tag = "v${version}"; 28 hash = "sha256-jtfDdZ68AroXlmR+AIVk/b3WpZk78BCtT8TUh4ELZZI="; 29 }; 30 31 postPatch = 32 let 33 ruffBin = lib.getExe ruff; 34 in 35 '' 36 substituteInPlace pylsp_ruff/plugin.py \ 37 --replace-fail \ 38 "*find_executable(executable)" \ 39 '"${ruffBin}"' 40 41 substituteInPlace tests/test_ruff_lint.py \ 42 --replace-fail "str(sys.executable)" '"${ruffBin}"' \ 43 --replace-fail '"-m",' "" \ 44 --replace-fail '"ruff",' "" \ 45 --replace-fail \ 46 'assert "ruff" in call_args' \ 47 'assert "${ruffBin}" in call_args' \ 48 --replace-fail \ 49 'ruff_executable = ruff_exe.name' \ 50 'ruff_executable = "${ruffBin}"' \ 51 --replace-fail 'os.chmod(ruff_executable, st.st_mode | stat.S_IEXEC)' "" 52 '' 53 # Nix builds everything in /build/ but ruff somehow doesn't run on files in /build/ and outputs empty results. 54 + '' 55 substituteInPlace tests/*.py \ 56 --replace-fail "workspace.root_path" '"/tmp/"' 57 ''; 58 59 pythonRemoveDeps = [ 60 # ruff binary is used directly, the ruff python package is not needed 61 "ruff" 62 ]; 63 64 dependencies = [ 65 cattrs 66 lsprotocol 67 python-lsp-server 68 ] 69 ++ lib.optionals (pythonOlder "3.11") [ tomli ]; 70 71 nativeCheckInputs = [ pytestCheckHook ]; 72 73 meta = { 74 homepage = "https://github.com/python-lsp/python-lsp-ruff"; 75 description = "Ruff linting plugin for pylsp"; 76 changelog = "https://github.com/python-lsp/python-lsp-ruff/releases/tag/v${version}"; 77 license = lib.licenses.mit; 78 maintainers = with lib.maintainers; [ linsui ]; 79 }; 80}