mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
basedpyright: 1.19.0 -> 1.21.0 (#354204)
This commit is contained in:
commit
ff09150750
12120
pkgs/by-name/ba/basedpyright/package-lock.json
generated
12120
pkgs/by-name/ba/basedpyright/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -3,112 +3,62 @@
|
||||
fetchFromGitHub,
|
||||
runCommand,
|
||||
buildNpmPackage,
|
||||
stdenvNoCC,
|
||||
docify,
|
||||
testers,
|
||||
writeText,
|
||||
jq,
|
||||
python3,
|
||||
basedpyright,
|
||||
pkg-config,
|
||||
libsecret,
|
||||
nix-update-script,
|
||||
versionCheckHook,
|
||||
}:
|
||||
|
||||
let
|
||||
version = "1.19.0";
|
||||
buildNpmPackage rec {
|
||||
pname = "basedpyright";
|
||||
version = "1.21.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "detachhead";
|
||||
repo = "basedpyright";
|
||||
rev = "refs/tags/v${version}";
|
||||
hash = "sha256-R8QEINTlO84YrnfRsZU5vNEwYcy5uZEKmmTPJ4qxYk8=";
|
||||
hash = "sha256-OQXqwpvYIitWGWshEv1/j2hAphFnGXDuvbRav5TilI4=";
|
||||
};
|
||||
|
||||
# To regenerate the patched package-lock.json, copy the patched package.json
|
||||
# and run `nix-shell -p nodejs --command 'npm update --package-lock'`
|
||||
patchedPackageJSON = runCommand "package.json" { } ''
|
||||
${jq}/bin/jq '
|
||||
.devDependencies |= with_entries(select(.key == "glob" or .key == "jsonc-parser" or .key == "@detachhead/ts-helpers"))
|
||||
| .scripts = { }
|
||||
' ${src}/package.json > $out
|
||||
npmDepsHash = "sha256-hCZ68sLpQs/7SYVf3pMAHfstRm1C/d80j8fESIFdhnw=";
|
||||
npmWorkspace = "packages/pyright";
|
||||
|
||||
preBuild = ''
|
||||
# Build the docstubs
|
||||
cp -r packages/pyright-internal/typeshed-fallback docstubs
|
||||
docify docstubs/stdlib --builtins-only --in-place
|
||||
'';
|
||||
|
||||
pyright-root = buildNpmPackage {
|
||||
pname = "pyright-root";
|
||||
inherit version src;
|
||||
npmDepsHash = "sha256-vxfoaShk3ihmhr/5/2GSOuMqeo6rxebO6aiD3DybjW4=";
|
||||
dontNpmBuild = true;
|
||||
postPatch = ''
|
||||
cp ${patchedPackageJSON} ./package.json
|
||||
cp ${./package-lock.json} ./package-lock.json
|
||||
'';
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
cp -r . "$out"
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
nativeBuildInputs = [
|
||||
docify
|
||||
pkg-config
|
||||
];
|
||||
|
||||
pyright-internal = buildNpmPackage {
|
||||
pname = "pyright-internal";
|
||||
inherit version src;
|
||||
sourceRoot = "${src.name}/packages/pyright-internal";
|
||||
npmDepsHash = "sha256-Xswt1kH9Iet6DSAlZctEV3qCpn+IWwceQgldyFzsaRk=";
|
||||
dontNpmBuild = true;
|
||||
# Uncomment this flag when using unreleased peer dependencies
|
||||
# npmFlags = [ "--legacy-peer-deps" ];
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
cp -r . "$out"
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
|
||||
docstubs = stdenvNoCC.mkDerivation {
|
||||
name = "docstubs";
|
||||
inherit src;
|
||||
nativeBuildInputs = [ docify ];
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
cp -r packages/pyright-internal/typeshed-fallback docstubs
|
||||
docify docstubs/stdlib --builtins-only --in-place
|
||||
cp -rv docstubs "$out"
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
in
|
||||
buildNpmPackage rec {
|
||||
pname = "basedpyright";
|
||||
inherit version src;
|
||||
|
||||
sourceRoot = "${src.name}/packages/pyright";
|
||||
npmDepsHash = "sha256-YhXVoh5sAnUkuc4iDMd/N15y92vMhUwT7PlLn2pzb20=";
|
||||
|
||||
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;
|
||||
updateScript = nix-update-script { };
|
||||
tests = {
|
||||
version = testers.testVersion { package = basedpyright; };
|
||||
|
||||
# We are expecting 3 errors. Any other amount would indicate, not working
|
||||
# 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" ''
|
||||
3
|
||||
4
|
||||
'';
|
||||
actual =
|
||||
runCommand "actual"
|
||||
@ -117,16 +67,24 @@ buildNpmPackage rec {
|
||||
jq
|
||||
basedpyright
|
||||
];
|
||||
base = writeText "base" ''
|
||||
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":
|
||||
a = "a" + 1
|
||||
|
||||
print(3)
|
||||
nonexistentfunction(3)
|
||||
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
|
||||
|
@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p curl gnused common-updater-scripts jq prefetch-npm-deps
|
||||
set -euo pipefail
|
||||
|
||||
version=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -v -s https://api.github.com/repos/detachhead/basedpyright/releases/latest | jq -r '.tag_name | sub("^v"; "")')
|
||||
|
||||
update-source-version basedpyright "$version"
|
||||
|
||||
root="$(dirname "$(readlink -f "$0")")"
|
||||
FILE_PATH="$root/package.nix"
|
||||
REPO_URL_PREFIX="https://github.com/detachhead/basedpyright/raw"
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
|
||||
trap 'rm -rf "$TEMP_DIR"' EXIT
|
||||
|
||||
# Function to download `package-lock.json` for a given source path and update hash
|
||||
update_hash() {
|
||||
local source_root_path="$1"
|
||||
local existing_hash="$2"
|
||||
|
||||
# Formulate download URL
|
||||
local download_url="${REPO_URL_PREFIX}/v${version}${source_root_path}/package-lock.json"
|
||||
|
||||
# Download package-lock.json to temporary directory
|
||||
curl -fsSL -v -o "${TEMP_DIR}/package-lock.json" "$download_url"
|
||||
|
||||
# Calculate the new hash
|
||||
local new_hash
|
||||
new_hash=$(prefetch-npm-deps "${TEMP_DIR}/package-lock.json")
|
||||
|
||||
# Update npmDepsHash in the original file
|
||||
sed -i "s|$existing_hash|${new_hash}|" "$FILE_PATH"
|
||||
}
|
||||
|
||||
while IFS= read -r source_root_line; do
|
||||
[[ "$source_root_line" =~ sourceRoot ]] || continue
|
||||
source_root_path=$(echo "$source_root_line" | sed -e 's/^.*"${src.name}\(.*\)";.*$/\1/')
|
||||
|
||||
# Extract the current npmDepsHash for this sourceRoot
|
||||
existing_hash=$(grep -A1 "$source_root_line" "$FILE_PATH" | grep 'npmDepsHash' | sed -e 's/^.*npmDepsHash = "\(.*\)";$/\1/')
|
||||
|
||||
# Call the function to download and update the hash
|
||||
update_hash "$source_root_path" "$existing_hash"
|
||||
done < "$FILE_PATH"
|
Loading…
Reference in New Issue
Block a user