Skip to content

Commit

Permalink
pyright: repackage using buildNpmPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
kalekseev committed Apr 18, 2024
1 parent 2e359fb commit 3d95a24
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 6 deletions.
193 changes: 193 additions & 0 deletions pkgs/by-name/py/pyright/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions pkgs/by-name/py/pyright/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{ lib, buildNpmPackage, fetchFromGitHub, runCommand, jq }:

let
version = "1.1.359";

src = fetchFromGitHub {
owner = "Microsoft";
repo = "pyright";
rev = "${version}";
hash = "sha256-gqMAfmYjYO6D9sRu+uJv4yJ/+csioFAwsUPBDF29VDs=";
};

patchedPackageJSON = runCommand "package.json" { } ''
${jq}/bin/jq '
.devDependencies |= with_entries(select(.key == "glob" or .key == "jsonc-parser"))
| .scripts = { }
' ${src}/package.json > $out
'';

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-p2KamNFJ3sJHmJm0MEPhI8L/8zAVzfc9NYy24rAdFcQ=";
dontNpmBuild = true;
installPhase = ''
runHook preInstall
cp -r . "$out"
runHook postInstall
'';
};
in
buildNpmPackage rec {
pname = "pyright";
inherit version src;

sourceRoot = "${src.name}/packages/pyright";
npmDepsHash = "sha256-U7WdMIYg9U4fJ8YtDruMzloRS2BQAa2QWExle9uwPbU=";

postPatch = ''
chmod +w ../../
ln -s ${pyright-root}/node_modules ../../node_modules
chmod +w ../pyright-internal
ln -s ${pyright-internal}/node_modules ../pyright-internal/node_modules
'';

dontNpmBuild = true;

passthru.updateScript = ./update.sh;

meta = {
changelog = "https://github.com/Microsoft/pyright/releases/tag/${version}";
description = "Type checker for the Python language";
homepage = "https://github.com/Microsoft/pyright";
license = lib.licenses.mit;
mainProgram = "pyright";
maintainers = with lib.maintainers; [ kalekseev ];
};
}
44 changes: 44 additions & 0 deletions pkgs/by-name/py/pyright/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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\""} -s https://api.github.com/repos/microsoft/pyright/releases/latest | jq -r '.tag_name | sub("^v"; "")')

update-source-version pyright "$version"

root="$(dirname "$(readlink -f "$0")")"
FILE_PATH="$root/package.nix"
REPO_URL_PREFIX="https://github.com/microsoft/pyright/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}/${version}${source_root_path}/package-lock.json"

# Download package-lock.json to temporary directory
curl -fsSL -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"
1 change: 0 additions & 1 deletion pkgs/development/node-packages/main-programs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
purs-tidy = "purs-tidy";
purty = "purty";
pscid = "pscid";
pyright = "pyright";
remod-cli = "remod";
svelte-language-server = "svelteserver";
teck-programmer = "teck-firmware-upgrade";
Expand Down
1 change: 0 additions & 1 deletion pkgs/development/node-packages/node-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@
, "purescript-psa"
, "purs-tidy"
, "purty"
, "pyright"
, "remod-cli"
, "reveal.js"
, "rimraf"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/servers/home-assistant/parse-requirements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p "python3.withPackages (ps: with ps; [ packaging rich ])" -p nodePackages.pyright ruff isort
#! nix-shell -i python3 -p "python3.withPackages (ps: with ps; [ packaging rich ])" -p pyright ruff isort
#
# This script downloads Home Assistant's source tarball.
# Inside the homeassistant/components directory, each integration has an associated manifest.json,
Expand Down
2 changes: 1 addition & 1 deletion pkgs/servers/home-assistant/update.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env nix-shell
#!nix-shell -I nixpkgs=channel:nixpkgs-unstable -i python3 -p "python3.withPackages (ps: with ps; [ aiohttp packaging ])" -p git nurl nodePackages.pyright ruff isort
#!nix-shell -I nixpkgs=channel:nixpkgs-unstable -i python3 -p "python3.withPackages (ps: with ps; [ aiohttp packaging ])" -p git nurl pyright ruff isort

import asyncio
import json
Expand Down
2 changes: 0 additions & 2 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33453,8 +33453,6 @@ with pkgs;

ptex = callPackage ../development/libraries/ptex { };

pyright = nodePackages.pyright;

qbec = callPackage ../applications/networking/cluster/qbec { };

qemacs = callPackage ../applications/editors/qemacs { };
Expand Down

0 comments on commit 3d95a24

Please sign in to comment.