lol

tree-sitter/update: move checkTreeSitterRepos into python impl

Direct translation of the jq set logic.

+27 -24
+1 -3
pkgs/development/tools/parsing/tree-sitter/default.nix
··· 42 42 fetchSubmodules = true; 43 43 }; 44 44 45 - update-all-grammars = callPackage ./update.nix { 46 - inherit src; 47 - }; 45 + update-all-grammars = callPackage ./update.nix {}; 48 46 49 47 fetchGrammar = (v: fetchgit { inherit (v) url rev sha256 fetchSubmodules; }); 50 48
+5 -18
pkgs/development/tools/parsing/tree-sitter/update.nix
··· 6 6 , lib 7 7 , coreutils 8 8 , curl 9 - , jq 10 9 , xe 11 - , src 12 10 }: 13 11 14 12 # Grammar list: ··· 389 387 390 388 jsonFile = name: val: (formats.json { }).generate name val; 391 389 392 - # check the tree-sitter orga repos 393 - checkTreeSitterRepos = writeShellScript "get-grammars.sh" '' 394 - set -euo pipefail 395 - res=$(${jq}/bin/jq \ 396 - --slurpfile known "${knownTreeSitterOrgGrammarReposJson}" \ 397 - --slurpfile ignore "${ignoredTreeSitterOrgReposJson}" \ 398 - '. - ($known[0] + $ignore[0])' \ 399 - ) 400 - if [ ! "$res" == "[]" ]; then 401 - echo "These repositories are neither known nor ignored:" 1>&2 402 - echo "$res" 1>&2 403 - exit 1 404 - fi 405 - ''; 406 - 407 390 # implementation of the fetching of repo information from github 408 391 fetchImpl = passArgs "fetchImpl-with-args" { 409 392 binaries = { ··· 411 394 nix-prefetch-git = "${nix-prefetch-git}/bin/nix-prefetch-git"; 412 395 inherit atomically-write; 413 396 }; 397 + inherit 398 + knownTreeSitterOrgGrammarRepos 399 + ignoredTreeSitterOrgRepos 400 + ; 414 401 } 415 402 (writers.writePython3 "fetchImpl" { 416 403 flakeIgnore = ["E501"]; ··· 443 430 echo "fetching list of grammars" 1>&2 444 431 treeSitterRepos=$(${fetchImpl} fetch-orga-latest-repos '{"orga": "tree-sitter"}') 445 432 echo "checking the tree-sitter repo list against the grammars we know" 1>&2 446 - printf '%s' "$treeSitterRepos" | ${checkTreeSitterRepos} 433 + printf '%s' "$treeSitterRepos" | ${fetchImpl} check-tree-sitter-repos '{}' 447 434 echo "writing files to ${outputDir}" 1>&2 448 435 mkdir -p "${outputDir}" 449 436 ${forEachParallel
+21 -3
pkgs/development/tools/parsing/tree-sitter/update_impl.py
··· 16 16 Args = Iterator[str] 17 17 18 18 19 + def log(msg: str) -> None: 20 + print(msg, file=sys.stderr) 21 + 22 + 19 23 def curl_github_args(token: str | None, url: str) -> Args: 20 24 """Query the github API via curl""" 21 25 yield bins["curl"] ··· 58 62 def run_cmd(args: Args) -> bytes: 59 63 all = list(args) 60 64 if debug: 61 - print(all, file=sys.stderr) 65 + log(str(all)) 62 66 return sub.check_output(all) 63 67 64 68 ··· 91 95 match curl_result(out): 92 96 case "not found": 93 97 # github sometimes returns an empty list even tough there are releases 94 - print(f"uh-oh, latest for {orga}/{repo} is not there, using HEAD", file=sys.stderr) 98 + log(f"uh-oh, latest for {orga}/{repo} is not there, using HEAD") 95 99 release = "HEAD" 96 100 case {"tag_name": tag_name}: 97 101 release = tag_name 98 102 case _: 99 103 sys.exit(f"git result for {orga}/{repo} did not have a `tag_name` field") 100 104 101 - print(f"Fetching latest release ({release}) of {orga}/{repo} …", file=sys.stderr) 105 + log(f"Fetching latest release ({release}) of {orga}/{repo} …") 102 106 res = run_cmd( 103 107 atomically_write_args( 104 108 os.path.join( ··· 144 148 sys.exit("input json must have `orga` key") 145 149 146 150 151 + def checkTreeSitterRepos() -> None: 152 + """Make sure we know about all tree sitter repos on the tree sitter orga.""" 153 + github_tree_sitter_repos: set[str] = set(json.load(sys.stdin)) 154 + known: set[str] = set(args["knownTreeSitterOrgGrammarRepos"]) 155 + ignored: set[str] = set(args["ignoredTreeSitterOrgRepos"]) 156 + 157 + unknown = github_tree_sitter_repos - (known | ignored) 158 + 159 + if unknown: 160 + sys.exit(f"These repositories are neither known nor ignored:\n{unknown}") 161 + 162 + 147 163 match mode: 148 164 case "fetch-repo": 149 165 fetchRepo() 150 166 case "fetch-orga-latest-repos": 151 167 fetchOrgaLatestRepos() 168 + case "check-tree-sitter-repos": 169 + checkTreeSitterRepos() 152 170 case _: 153 171 sys.exit(f"mode {mode} unknown")