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