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