chromium,chromedriver: 129.0.6668.91 -> 129.0.6668.100
[NixPkgs.git] / pkgs / by-name / ba / basedpyright / package.nix
blobe899d7dbf1873f35c707815d275606af0f05bdb3
2   lib,
3   fetchFromGitHub,
4   runCommand,
5   buildNpmPackage,
6   stdenvNoCC,
7   docify,
8   testers,
9   writeText,
10   jq,
11   python3,
12   basedpyright,
15 let
16   version = "1.18.2";
18   src = fetchFromGitHub {
19     owner = "detachhead";
20     repo = "basedpyright";
21     rev = "refs/tags/v${version}";
22     hash = "sha256-nYbxgrNFhQ576rN8W+Hf/Keohy1N8tihOeTQHItKPRc=";
23   };
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" { } ''
28     ${jq}/bin/jq '
29       .devDependencies |= with_entries(select(.key == "glob" or .key == "jsonc-parser" or .key == "@detachhead/ts-helpers"))
30       | .scripts =  {  }
31       ' ${src}/package.json > $out
32   '';
34   pyright-root = buildNpmPackage {
35     pname = "pyright-root";
36     inherit version src;
37     npmDepsHash = "sha256-vxfoaShk3ihmhr/5/2GSOuMqeo6rxebO6aiD3DybjW4=";
38     dontNpmBuild = true;
39     postPatch = ''
40       cp ${patchedPackageJSON} ./package.json
41       cp ${./package-lock.json} ./package-lock.json
42     '';
43     installPhase = ''
44       runHook preInstall
45       cp -r . "$out"
46       runHook postInstall
47     '';
48   };
50   pyright-internal = buildNpmPackage {
51     pname = "pyright-internal";
52     inherit version src;
53     sourceRoot = "${src.name}/packages/pyright-internal";
54     npmDepsHash = "sha256-Md17EF3a1GBfnHD2fnLGS76r0xiWYJmBBTzZWRc0j5c=";
55     dontNpmBuild = true;
56     # Uncomment this flag when using unreleased peer dependencies
57     # npmFlags = [ "--legacy-peer-deps" ];
58     installPhase = ''
59       runHook preInstall
60       cp -r . "$out"
61       runHook postInstall
62     '';
63   };
65   docstubs = stdenvNoCC.mkDerivation {
66     name = "docstubs";
67     inherit src;
68     nativeBuildInputs = [ docify ];
70     installPhase = ''
71       runHook preInstall
72       cp -r packages/pyright-internal/typeshed-fallback docstubs
73       docify docstubs/stdlib --builtins-only --in-place
74       cp -rv docstubs "$out"
75       runHook postInstall
76     '';
77   };
79 buildNpmPackage rec {
80   pname = "basedpyright";
81   inherit version src;
83   sourceRoot = "${src.name}/packages/pyright";
84   npmDepsHash = "sha256-6/OhBbIuFjXTN8N/PitaQ57aYZmpwcUOJ/vlLbhiXAU=";
86   postPatch = ''
87     chmod +w ../../
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
92   '';
94   postInstall = ''
95     mv "$out/bin/pyright" "$out/bin/basedpyright"
96     mv "$out/bin/pyright-langserver" "$out/bin/basedpyright-langserver"
97   '';
99   dontNpmBuild = true;
101   passthru = {
102     updateScript = ./update.sh;
103     tests = {
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" ''
111           3
112         '';
113         actual =
114           runCommand "actual"
115             {
116               nativeBuildInputs = [
117                 jq
118                 basedpyright
119               ];
120               base = writeText "base" ''
121                 import sys
123                 if sys.platform == "win32":
124                     a = "a" + 1
126                 print(3)
127                 nonexistentfunction(3)
128               '';
130             }
131             ''
132               (basedpyright --outputjson $base || true) | jq -r .summary.errorCount > $out
133             '';
134       };
135     };
136   };
138   meta = {
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 ];
145   };