forked from mirrors/nixpkgs
tree-sitter/update: move checkTreeSitterRepos into python impl
Direct translation of the jq set logic.
This commit is contained in:
parent
923975a604
commit
a953387d22
|
@ -42,9 +42,7 @@ let
|
||||||
fetchSubmodules = true;
|
fetchSubmodules = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
update-all-grammars = callPackage ./update.nix {
|
update-all-grammars = callPackage ./update.nix {};
|
||||||
inherit src;
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchGrammar = (v: fetchgit { inherit (v) url rev sha256 fetchSubmodules; });
|
fetchGrammar = (v: fetchgit { inherit (v) url rev sha256 fetchSubmodules; });
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,7 @@
|
||||||
, lib
|
, lib
|
||||||
, coreutils
|
, coreutils
|
||||||
, curl
|
, curl
|
||||||
, jq
|
|
||||||
, xe
|
, xe
|
||||||
, src
|
|
||||||
}:
|
}:
|
||||||
|
|
||||||
# Grammar list:
|
# Grammar list:
|
||||||
|
@ -389,21 +387,6 @@ let
|
||||||
|
|
||||||
jsonFile = name: val: (formats.json { }).generate name val;
|
jsonFile = name: val: (formats.json { }).generate name val;
|
||||||
|
|
||||||
# check the tree-sitter orga repos
|
|
||||||
checkTreeSitterRepos = writeShellScript "get-grammars.sh" ''
|
|
||||||
set -euo pipefail
|
|
||||||
res=$(${jq}/bin/jq \
|
|
||||||
--slurpfile known "${knownTreeSitterOrgGrammarReposJson}" \
|
|
||||||
--slurpfile ignore "${ignoredTreeSitterOrgReposJson}" \
|
|
||||||
'. - ($known[0] + $ignore[0])' \
|
|
||||||
)
|
|
||||||
if [ ! "$res" == "[]" ]; then
|
|
||||||
echo "These repositories are neither known nor ignored:" 1>&2
|
|
||||||
echo "$res" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
|
|
||||||
# implementation of the fetching of repo information from github
|
# implementation of the fetching of repo information from github
|
||||||
fetchImpl = passArgs "fetchImpl-with-args" {
|
fetchImpl = passArgs "fetchImpl-with-args" {
|
||||||
binaries = {
|
binaries = {
|
||||||
|
@ -411,6 +394,10 @@ let
|
||||||
nix-prefetch-git = "${nix-prefetch-git}/bin/nix-prefetch-git";
|
nix-prefetch-git = "${nix-prefetch-git}/bin/nix-prefetch-git";
|
||||||
inherit atomically-write;
|
inherit atomically-write;
|
||||||
};
|
};
|
||||||
|
inherit
|
||||||
|
knownTreeSitterOrgGrammarRepos
|
||||||
|
ignoredTreeSitterOrgRepos
|
||||||
|
;
|
||||||
}
|
}
|
||||||
(writers.writePython3 "fetchImpl" {
|
(writers.writePython3 "fetchImpl" {
|
||||||
flakeIgnore = ["E501"];
|
flakeIgnore = ["E501"];
|
||||||
|
@ -443,7 +430,7 @@ let
|
||||||
echo "fetching list of grammars" 1>&2
|
echo "fetching list of grammars" 1>&2
|
||||||
treeSitterRepos=$(${fetchImpl} fetch-orga-latest-repos '{"orga": "tree-sitter"}')
|
treeSitterRepos=$(${fetchImpl} fetch-orga-latest-repos '{"orga": "tree-sitter"}')
|
||||||
echo "checking the tree-sitter repo list against the grammars we know" 1>&2
|
echo "checking the tree-sitter repo list against the grammars we know" 1>&2
|
||||||
printf '%s' "$treeSitterRepos" | ${checkTreeSitterRepos}
|
printf '%s' "$treeSitterRepos" | ${fetchImpl} check-tree-sitter-repos '{}'
|
||||||
echo "writing files to ${outputDir}" 1>&2
|
echo "writing files to ${outputDir}" 1>&2
|
||||||
mkdir -p "${outputDir}"
|
mkdir -p "${outputDir}"
|
||||||
${forEachParallel
|
${forEachParallel
|
||||||
|
|
|
@ -16,6 +16,10 @@ jsonArg: dict = json.loads(sys.argv[2])
|
||||||
Args = Iterator[str]
|
Args = Iterator[str]
|
||||||
|
|
||||||
|
|
||||||
|
def log(msg: str) -> None:
|
||||||
|
print(msg, file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def curl_github_args(token: str | None, url: str) -> Args:
|
def curl_github_args(token: str | None, url: str) -> Args:
|
||||||
"""Query the github API via curl"""
|
"""Query the github API via curl"""
|
||||||
yield bins["curl"]
|
yield bins["curl"]
|
||||||
|
@ -58,7 +62,7 @@ def nix_prefetch_git_args(url: str, version_rev: str) -> Args:
|
||||||
def run_cmd(args: Args) -> bytes:
|
def run_cmd(args: Args) -> bytes:
|
||||||
all = list(args)
|
all = list(args)
|
||||||
if debug:
|
if debug:
|
||||||
print(all, file=sys.stderr)
|
log(str(all))
|
||||||
return sub.check_output(all)
|
return sub.check_output(all)
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,14 +95,14 @@ def fetchRepo() -> None:
|
||||||
match curl_result(out):
|
match curl_result(out):
|
||||||
case "not found":
|
case "not found":
|
||||||
# github sometimes returns an empty list even tough there are releases
|
# github sometimes returns an empty list even tough there are releases
|
||||||
print(f"uh-oh, latest for {orga}/{repo} is not there, using HEAD", file=sys.stderr)
|
log(f"uh-oh, latest for {orga}/{repo} is not there, using HEAD")
|
||||||
release = "HEAD"
|
release = "HEAD"
|
||||||
case {"tag_name": tag_name}:
|
case {"tag_name": tag_name}:
|
||||||
release = tag_name
|
release = tag_name
|
||||||
case _:
|
case _:
|
||||||
sys.exit(f"git result for {orga}/{repo} did not have a `tag_name` field")
|
sys.exit(f"git result for {orga}/{repo} did not have a `tag_name` field")
|
||||||
|
|
||||||
print(f"Fetching latest release ({release}) of {orga}/{repo} …", file=sys.stderr)
|
log(f"Fetching latest release ({release}) of {orga}/{repo} …")
|
||||||
res = run_cmd(
|
res = run_cmd(
|
||||||
atomically_write_args(
|
atomically_write_args(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
|
@ -144,10 +148,24 @@ def fetchOrgaLatestRepos() -> None:
|
||||||
sys.exit("input json must have `orga` key")
|
sys.exit("input json must have `orga` key")
|
||||||
|
|
||||||
|
|
||||||
|
def checkTreeSitterRepos() -> None:
|
||||||
|
"""Make sure we know about all tree sitter repos on the tree sitter orga."""
|
||||||
|
github_tree_sitter_repos: set[str] = set(json.load(sys.stdin))
|
||||||
|
known: set[str] = set(args["knownTreeSitterOrgGrammarRepos"])
|
||||||
|
ignored: set[str] = set(args["ignoredTreeSitterOrgRepos"])
|
||||||
|
|
||||||
|
unknown = github_tree_sitter_repos - (known | ignored)
|
||||||
|
|
||||||
|
if unknown:
|
||||||
|
sys.exit(f"These repositories are neither known nor ignored:\n{unknown}")
|
||||||
|
|
||||||
|
|
||||||
match mode:
|
match mode:
|
||||||
case "fetch-repo":
|
case "fetch-repo":
|
||||||
fetchRepo()
|
fetchRepo()
|
||||||
case "fetch-orga-latest-repos":
|
case "fetch-orga-latest-repos":
|
||||||
fetchOrgaLatestRepos()
|
fetchOrgaLatestRepos()
|
||||||
|
case "check-tree-sitter-repos":
|
||||||
|
checkTreeSitterRepos()
|
||||||
case _:
|
case _:
|
||||||
sys.exit(f"mode {mode} unknown")
|
sys.exit(f"mode {mode} unknown")
|
||||||
|
|
Loading…
Reference in a new issue