Commit b12686d5 authored by figsoda's avatar figsoda
Browse files

vimPlugins.nvim-treesitter: switch to nurl in update script

parent 67b0f840
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
# generated by pkgs/applications/editors/vim/plugins/nvim-treesitter/update.py

{ buildGrammar, fetchFromGitHub, fetchFromGitLab, fetchgit }:
{ buildGrammar, fetchFromGitHub, fetchFromGitLab, fetchFromSourcehut, fetchgit }:

{
  ada = buildGrammar {
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ let
in

mkShell {
  packages = [ neovim nix-prefetch python3 ];
  packages = [ neovim nurl python3 ];

  NVIM_TREESITTER = nvim-treesitter;
}
+5 −46
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@
#!nix-shell update-shell.nix -i python

import json
import re
import subprocess
from concurrent.futures import ThreadPoolExecutor
from os import environ
from os.path import dirname, join

@@ -22,8 +22,6 @@ configs = json.loads(
    )
)

regex = re.compile("^https?://(github.com|gitlab.com)/(.+?)/(.+?)(.git)?$")


def generate_grammar(item):
    lang, lock = item
@@ -40,47 +38,8 @@ def generate_grammar(item):
    version = "{rev[:7]}";
    source = """

    m = regex.fullmatch(url)
    cmd = ["nix-prefetch", "--rev", rev]

    match m and m.group(1, 2, 3):
        case "github.com", owner, repo:
            cmd += [
                "fetchFromGitHub",
                "--owner",
                owner,
                "--repo",
                repo,
            ]

            generated += f"""fetchFromGitHub {{
      owner = "{owner}";
      repo = "{repo}";"""

        case "gitlab.com", owner, repo:
            cmd += [
                "fetchFromGitLab",
                "--owner",
                owner,
                "--repo",
                repo,
            ]

            generated += f"""fetchFromGitLab {{
      owner = "{owner}";
      repo = "{repo}";"""

        case _:
            cmd += ["fetchgit", "--url", url]
            generated += f"""fetchgit {{
      url = "{url}";"""

    hash = subprocess.check_output(cmd, text=True).strip()

    generated += f"""
      rev = "{rev}";
      hash = "{hash}";
    }};"""
    generated += subprocess.check_output(["nurl", url, rev, "--indent=4"], text=True)
    generated += ";"

    location = info.get("location")
    if location:
@@ -101,12 +60,12 @@ def generate_grammar(item):

generated_file = """# generated by pkgs/applications/editors/vim/plugins/nvim-treesitter/update.py

{ buildGrammar, fetchFromGitHub, fetchFromGitLab, fetchgit }:
{ buildGrammar, fetchFromGitHub, fetchFromGitLab, fetchFromSourcehut, fetchgit }:

{
"""

for generated in map(generate_grammar, lockfile.items()):
for generated in ThreadPoolExecutor().map(generate_grammar, lockfile.items()):
    generated_file += generated

generated_file += "}\n"