diff options
Diffstat (limited to 'pkgs/by-name/ba/basedpyright/package.nix')
-rw-r--r-- | pkgs/by-name/ba/basedpyright/package.nix | 155 |
1 files changed, 66 insertions, 89 deletions
diff --git a/pkgs/by-name/ba/basedpyright/package.nix b/pkgs/by-name/ba/basedpyright/package.nix index 1fa304672947..6ebee6cfe498 100644 --- a/pkgs/by-name/ba/basedpyright/package.nix +++ b/pkgs/by-name/ba/basedpyright/package.nix @@ -2,118 +2,95 @@ lib, fetchFromGitHub, runCommand, - jq, buildNpmPackage, - python3, - stdenvNoCC, + docify, testers, + writeText, + jq, basedpyright, + pkg-config, + libsecret, + nix-update-script, + versionCheckHook, }: -let - version = "1.17.5"; +buildNpmPackage rec { + pname = "basedpyright"; + version = "1.21.0"; src = fetchFromGitHub { owner = "detachhead"; repo = "basedpyright"; rev = "refs/tags/v${version}"; - hash = "sha256-DaNxPGY0ahTcluCnsEZNL2oP9zKWQlON8i1bxeJ5GnU="; + hash = "sha256-OQXqwpvYIitWGWshEv1/j2hAphFnGXDuvbRav5TilI4="; }; - patchedPackageJSON = runCommand "package.json" { } '' - ${jq}/bin/jq ' - .devDependencies |= with_entries(select(.key == "glob" or .key == "jsonc-parser")) - | .scripts = { } - ' ${src}/package.json > $out - ''; + npmDepsHash = "sha256-hCZ68sLpQs/7SYVf3pMAHfstRm1C/d80j8fESIFdhnw="; + npmWorkspace = "packages/pyright"; - pyright-root = buildNpmPackage { - pname = "pyright-root"; - inherit version src; - npmDepsHash = "sha256-63kUhKrxtJhwGCRBnxBfOFXs2ARCNn+OOGu6+fSJey4="; - dontNpmBuild = true; - postPatch = '' - cp ${patchedPackageJSON} ./package.json - cp ${./package-lock.json} ./package-lock.json - ''; - installPhase = '' - runHook preInstall - cp -r . "$out" - runHook postInstall - ''; - }; - - pyright-internal = buildNpmPackage { - pname = "pyright-internal"; - inherit version src; - sourceRoot = "${src.name}/packages/pyright-internal"; - npmDepsHash = "sha256-A1XP2IMfQMI1fFk2leuvm/57MsK43Md6Kyag9dQVAdg="; - dontNpmBuild = true; - # Uncomment this flag when using unreleased peer dependencies - # npmFlags = [ "--legacy-peer-deps" ]; - installPhase = '' - runHook preInstall - cp -r . "$out" - runHook postInstall - ''; - }; - - docify = python3.pkgs.buildPythonApplication { - pname = "docify"; - version = "unstable"; - format = "pyproject"; - src = fetchFromGitHub { - owner = "AThePeanut4"; - repo = "docify"; - rev = "7380a6faa6d1e8a3dc790a00254e6d77f84cbd91"; - hash = "sha256-BPR1rc/JzdBweiWmdHxgardDDrJZVWkUIF3ZEmEYf/A="; - }; - buildInputs = [ python3.pkgs.setuptools ]; - propagatedBuildInputs = [ - python3.pkgs.libcst - python3.pkgs.tqdm - ]; - }; - - docstubs = stdenvNoCC.mkDerivation { - name = "docstubs"; - inherit src; - buildInputs = [ docify ]; - - installPhase = '' - runHook preInstall - cp -r packages/pyright-internal/typeshed-fallback docstubs - ${docify}/bin/docify docstubs/stdlib --builtins-only --in-place - cp -rv docstubs "$out" - runHook postInstall - ''; - }; -in -buildNpmPackage rec { - pname = "basedpyright"; - inherit version src; + preBuild = '' + # Build the docstubs + cp -r packages/pyright-internal/typeshed-fallback docstubs + docify docstubs/stdlib --builtins-only --in-place + ''; - sourceRoot = "${src.name}/packages/pyright"; - npmDepsHash = "sha256-wvxwvPdTKcw4X8F5800ft4an7/xwmRPlL1Wzcm5jim8="; + nativeBuildInputs = [ + docify + pkg-config + ]; - postPatch = '' - chmod +w ../../ - ln -s ${docstubs} ../../docstubs - ln -s ${pyright-root}/node_modules ../../node_modules - chmod +w ../pyright-internal - ln -s ${pyright-internal}/node_modules ../pyright-internal/node_modules - ''; + buildInputs = [ libsecret ]; postInstall = '' mv "$out/bin/pyright" "$out/bin/basedpyright" mv "$out/bin/pyright-langserver" "$out/bin/basedpyright-langserver" ''; - dontNpmBuild = true; + nativeInstallCheckInputs = [ versionCheckHook ]; + versionCheckProgramArg = [ "--version" ]; + doInstallCheck = true; passthru = { - updateScript = ./update.sh; - tests.version = testers.testVersion { package = basedpyright; }; + updateScript = nix-update-script { }; + tests = { + # We are expecting 4 errors. Any other amount would indicate not working + # stub files, for instance. + simple = testers.testEqualContents { + assertion = "simple type checking"; + expected = writeText "expected" '' + 4 + ''; + actual = + runCommand "actual" + { + nativeBuildInputs = [ + jq + basedpyright + ]; + base = writeText "test.py" '' + import sys + from time import tzset + + def print_string(a_string: str): + a_string += 42 + print(a_string) + + if sys.platform == "win32": + print_string(69) + this_function_does_not_exist("nice!") + else: + result_of_tzset_is_None: str = tzset() + ''; + configFile = writeText "pyproject.toml" '' + [tool.pyright] + typeCheckingMode = "strict" + ''; + } + '' + (basedpyright --outputjson $base || true) | jq -r .summary.errorCount > $out + ''; + }; + }; }; meta = { |