3
0
Fork 0
forked from mirrors/nixpkgs

tree-sitter/update: move checkTreeSitterRepos into python impl

Direct translation of the jq set logic.
This commit is contained in:
Profpatsch 2022-09-12 16:25:42 +02:00
parent 923975a604
commit a953387d22
3 changed files with 27 additions and 24 deletions

View file

@ -42,9 +42,7 @@ let
fetchSubmodules = true;
};
update-all-grammars = callPackage ./update.nix {
inherit src;
};
update-all-grammars = callPackage ./update.nix {};
fetchGrammar = (v: fetchgit { inherit (v) url rev sha256 fetchSubmodules; });

View file

@ -6,9 +6,7 @@
, lib
, coreutils
, curl
, jq
, xe
, src
}:
# Grammar list:
@ -389,21 +387,6 @@ let
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
fetchImpl = passArgs "fetchImpl-with-args" {
binaries = {
@ -411,6 +394,10 @@ let
nix-prefetch-git = "${nix-prefetch-git}/bin/nix-prefetch-git";
inherit atomically-write;
};
inherit
knownTreeSitterOrgGrammarRepos
ignoredTreeSitterOrgRepos
;
}
(writers.writePython3 "fetchImpl" {
flakeIgnore = ["E501"];
@ -443,7 +430,7 @@ let
echo "fetching list of grammars" 1>&2
treeSitterRepos=$(${fetchImpl} fetch-orga-latest-repos '{"orga": "tree-sitter"}')
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
mkdir -p "${outputDir}"
${forEachParallel

View file

@ -16,6 +16,10 @@ jsonArg: dict = json.loads(sys.argv[2])
Args = Iterator[str]
def log(msg: str) -> None:
print(msg, file=sys.stderr)
def curl_github_args(token: str | None, url: str) -> Args:
"""Query the github API via 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:
all = list(args)
if debug:
print(all, file=sys.stderr)
log(str(all))
return sub.check_output(all)
@ -91,14 +95,14 @@ def fetchRepo() -> None:
match curl_result(out):
case "not found":
# 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"
case {"tag_name": tag_name}:
release = tag_name
case _:
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(
atomically_write_args(
os.path.join(
@ -144,10 +148,24 @@ def fetchOrgaLatestRepos() -> None:
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:
case "fetch-repo":
fetchRepo()
case "fetch-orga-latest-repos":
fetchOrgaLatestRepos()
case "check-tree-sitter-repos":
checkTreeSitterRepos()
case _:
sys.exit(f"mode {mode} unknown")