nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 111 lines 2.9 kB view raw
1{ 2 lib, 3 fetchFromGitHub, 4 runCommand, 5 stdenv, 6 clang_20, 7 buildNpmPackage, 8 docify, 9 testers, 10 writeText, 11 jq, 12 basedpyright, 13 pkg-config, 14 libsecret, 15 nix-update-script, 16 versionCheckHook, 17}: 18 19buildNpmPackage rec { 20 pname = "basedpyright"; 21 version = "1.37.2"; 22 23 src = fetchFromGitHub { 24 owner = "detachhead"; 25 repo = "basedpyright"; 26 tag = "v${version}"; 27 hash = "sha256-xFbVeNfOse7FfivTFwBnEZ0XUU2uUXqe1im6MncZwyY="; 28 }; 29 30 npmDepsHash = "sha256-aZ9kfkW+S6Hjt59Z4Fc5joghs7OQ32354IYevFuKNeo="; 31 npmWorkspace = "packages/pyright"; 32 33 preBuild = '' 34 # Build the docstubs 35 cp -r packages/pyright-internal/typeshed-fallback docstubs 36 docify docstubs/stdlib --builtins-only --in-place 37 ''; 38 39 nativeBuildInputs = [ 40 docify 41 pkg-config 42 ] 43 ++ lib.optional stdenv.isDarwin [ clang_20 ]; # clang_21 breaks keytar 44 45 buildInputs = [ libsecret ]; 46 47 postInstall = '' 48 mv "$out/bin/pyright" "$out/bin/basedpyright" 49 mv "$out/bin/pyright-langserver" "$out/bin/basedpyright-langserver" 50 # Remove dangling symlinks created during installation (remove -delete to just see the files, or -print '%l\n' to see the target 51 find -L $out -type l -print -delete 52 ''; 53 54 nativeInstallCheckInputs = [ versionCheckHook ]; 55 doInstallCheck = true; 56 57 passthru = { 58 updateScript = nix-update-script { }; 59 tests = { 60 # We are expecting 4 errors. Any other amount would indicate not working 61 # stub files, for instance. 62 simple = testers.testEqualContents { 63 assertion = "simple type checking"; 64 expected = writeText "expected" '' 65 4 66 ''; 67 actual = 68 runCommand "actual" 69 { 70 nativeBuildInputs = [ 71 jq 72 basedpyright 73 ]; 74 base = writeText "test.py" '' 75 import sys 76 from time import tzset 77 78 def print_string(a_string: str): 79 a_string += 42 80 print(a_string) 81 82 if sys.platform == "win32": 83 print_string(69) 84 this_function_does_not_exist("nice!") 85 else: 86 result_of_tzset_is_None: str = tzset() 87 ''; 88 configFile = writeText "pyproject.toml" '' 89 [tool.pyright] 90 typeCheckingMode = "strict" 91 ''; 92 } 93 '' 94 (basedpyright --outputjson $base || true) | jq -r .summary.errorCount > $out 95 ''; 96 }; 97 }; 98 }; 99 100 meta = { 101 changelog = "https://github.com/detachhead/basedpyright/releases/tag/${src.tag}"; 102 description = "Type checker for the Python language"; 103 homepage = "https://github.com/detachhead/basedpyright"; 104 license = lib.licenses.mit; 105 mainProgram = "basedpyright"; 106 maintainers = with lib.maintainers; [ 107 kiike 108 misilelab 109 ]; 110 }; 111}