Merge pull request #329823 from ExpidusOS/fix/pkgsllvm/elfutils
[NixPkgs.git] / pkgs / by-name / ba / basedpyright / package.nix
blobe244266b32b33c5ba9bb27be654ddb70c9f96964
2   lib,
3   fetchFromGitHub,
4   runCommand,
5   jq,
6   buildNpmPackage,
7   python3,
8   stdenvNoCC,
9   testers,
10   basedpyright,
13 let
14   version = "1.15.0";
16   src = fetchFromGitHub {
17     owner = "detachhead";
18     repo = "basedpyright";
19     rev = "refs/tags/v${version}";
20     hash = "sha256-SMF7BXPhoMyUqGY8WK5pIVAy+p/mS+Li+Lz0uLyhFjY=";
21   };
23   patchedPackageJSON = runCommand "package.json" { } ''
24     ${jq}/bin/jq '
25       .devDependencies |= with_entries(select(.key == "glob" or .key == "jsonc-parser"))
26       | .scripts =  {  }
27       ' ${src}/package.json > $out
28   '';
30   pyright-root = buildNpmPackage {
31     pname = "pyright-root";
32     inherit version src;
33     npmDepsHash = "sha256-63kUhKrxtJhwGCRBnxBfOFXs2ARCNn+OOGu6+fSJey4=";
34     dontNpmBuild = true;
35     postPatch = ''
36       cp ${patchedPackageJSON} ./package.json
37       cp ${./package-lock.json} ./package-lock.json
38     '';
39     installPhase = ''
40       runHook preInstall
41       cp -r . "$out"
42       runHook postInstall
43     '';
44   };
46   pyright-internal = buildNpmPackage {
47     pname = "pyright-internal";
48     inherit version src;
49     sourceRoot = "${src.name}/packages/pyright-internal";
50     npmDepsHash = "sha256-GO6ozBtf9P6tKhqtgNJjNdziJ9rYImH0fdYi7KZ1NgI=";
51     dontNpmBuild = true;
52     # FIXME: Remove this flag when TypeScript 5.5 is released
53     npmFlags = [ "--legacy-peer-deps" ];
54     installPhase = ''
55       runHook preInstall
56       cp -r . "$out"
57       runHook postInstall
58     '';
59   };
61   docify = python3.pkgs.buildPythonApplication {
62     pname = "docify";
63     version = "unstable";
64     format = "pyproject";
65     src = fetchFromGitHub {
66       owner = "AThePeanut4";
67       repo = "docify";
68       rev = "7380a6faa6d1e8a3dc790a00254e6d77f84cbd91";
69       hash = "sha256-BPR1rc/JzdBweiWmdHxgardDDrJZVWkUIF3ZEmEYf/A=";
70     };
71     buildInputs = [ python3.pkgs.setuptools ];
72     propagatedBuildInputs = [
73       python3.pkgs.libcst
74       python3.pkgs.tqdm
75     ];
76   };
78   docstubs = stdenvNoCC.mkDerivation {
79     name = "docstubs";
80     inherit src;
81     buildInputs = [ docify ];
83     installPhase = ''
84       runHook preInstall
85       cp -r packages/pyright-internal/typeshed-fallback docstubs
86       ${docify}/bin/docify docstubs/stdlib --builtins-only --in-place
87       cp -rv docstubs "$out"
88       runHook postInstall
89     '';
90   };
92 buildNpmPackage rec {
93   pname = "basedpyright";
94   inherit version src;
96   sourceRoot = "${src.name}/packages/pyright";
97   npmDepsHash = "sha256-areRNvJXmnK/yNCwQ//SNVI6eDOqweYxTULvrANLwPo=";
99   postPatch = ''
100     chmod +w ../../
101     ln -s ${docstubs} ../../docstubs
102     ln -s ${pyright-root}/node_modules ../../node_modules
103     chmod +w ../pyright-internal
104     ln -s ${pyright-internal}/node_modules ../pyright-internal/node_modules
105   '';
107   postInstall = ''
108     mv "$out/bin/pyright" "$out/bin/basedpyright"
109     mv "$out/bin/pyright-langserver" "$out/bin/basedpyright-langserver"
110   '';
112   dontNpmBuild = true;
114   passthru = {
115     updateScript = ./update.sh;
116     tests.version = testers.testVersion { package = basedpyright; };
117   };
119   meta = {
120     changelog = "https://github.com/detachhead/basedpyright/releases/tag/${version}";
121     description = "Type checker for the Python language";
122     homepage = "https://github.com/detachhead/basedpyright";
123     license = lib.licenses.mit;
124     mainProgram = "basedpyright";
125     maintainers = with lib.maintainers; [ kiike ];
126   };