18 src = fetchFromGitHub {
20 repo = "basedpyright";
21 rev = "refs/tags/v${version}";
22 hash = "sha256-nYbxgrNFhQ576rN8W+Hf/Keohy1N8tihOeTQHItKPRc=";
25 # To regenerate the patched package-lock.json, copy the patched package.json
26 # and run `nix-shell -p nodejs --command 'npm update --package-lock'`
27 patchedPackageJSON = runCommand "package.json" { } ''
29 .devDependencies |= with_entries(select(.key == "glob" or .key == "jsonc-parser" or .key == "@detachhead/ts-helpers"))
31 ' ${src}/package.json > $out
34 pyright-root = buildNpmPackage {
35 pname = "pyright-root";
37 npmDepsHash = "sha256-vxfoaShk3ihmhr/5/2GSOuMqeo6rxebO6aiD3DybjW4=";
40 cp ${patchedPackageJSON} ./package.json
41 cp ${./package-lock.json} ./package-lock.json
50 pyright-internal = buildNpmPackage {
51 pname = "pyright-internal";
53 sourceRoot = "${src.name}/packages/pyright-internal";
54 npmDepsHash = "sha256-Md17EF3a1GBfnHD2fnLGS76r0xiWYJmBBTzZWRc0j5c=";
56 # Uncomment this flag when using unreleased peer dependencies
57 # npmFlags = [ "--legacy-peer-deps" ];
65 docstubs = stdenvNoCC.mkDerivation {
68 nativeBuildInputs = [ docify ];
72 cp -r packages/pyright-internal/typeshed-fallback docstubs
73 docify docstubs/stdlib --builtins-only --in-place
74 cp -rv docstubs "$out"
80 pname = "basedpyright";
83 sourceRoot = "${src.name}/packages/pyright";
84 npmDepsHash = "sha256-6/OhBbIuFjXTN8N/PitaQ57aYZmpwcUOJ/vlLbhiXAU=";
88 ln -s ${docstubs} ../../docstubs
89 ln -s ${pyright-root}/node_modules ../../node_modules
90 chmod +w ../pyright-internal
91 ln -s ${pyright-internal}/node_modules ../pyright-internal/node_modules
95 mv "$out/bin/pyright" "$out/bin/basedpyright"
96 mv "$out/bin/pyright-langserver" "$out/bin/basedpyright-langserver"
102 updateScript = ./update.sh;
104 version = testers.testVersion { package = basedpyright; };
106 # We are expecting 3 errors. Any other amount would indicate, not working
107 # stub files, for instance.
108 simple = testers.testEqualContents {
109 assertion = "simple type checking";
110 expected = writeText "expected" ''
116 nativeBuildInputs = [
120 base = writeText "base" ''
123 if sys.platform == "win32":
127 nonexistentfunction(3)
132 (basedpyright --outputjson $base || true) | jq -r .summary.errorCount > $out
139 changelog = "https://github.com/detachhead/basedpyright/releases/tag/${version}";
140 description = "Type checker for the Python language";
141 homepage = "https://github.com/detachhead/basedpyright";
142 license = lib.licenses.mit;
143 mainProgram = "basedpyright";
144 maintainers = with lib.maintainers; [ kiike ];