diff options
author | Profpatsch <mail@profpatsch.de> | 2022-09-24 13:18:13 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2022-11-04 18:14:33 +0100 |
commit | 0242c271aa61d1ef917e581c2d4ea9e3aaeeed75 (patch) | |
tree | ca9c292dbb0ad86d024ae9d532b659c2023cc2a9 /pkgs/development/tools/parsing | |
parent | 8f2f2e34d0440b92a789ccc421c948ec65be1a85 (diff) |
tree-sitter/update: fetch orgas and directly check in python
Diffstat (limited to 'pkgs/development/tools/parsing')
-rw-r--r-- | pkgs/development/tools/parsing/tree-sitter/update.nix | 5 | ||||
-rw-r--r-- | pkgs/development/tools/parsing/tree-sitter/update_impl.py | 60 |
2 files changed, 31 insertions, 34 deletions
diff --git a/pkgs/development/tools/parsing/tree-sitter/update.nix b/pkgs/development/tools/parsing/tree-sitter/update.nix index 72f27e90e2b69..ad62530ee31d7 100644 --- a/pkgs/development/tools/parsing/tree-sitter/update.nix +++ b/pkgs/development/tools/parsing/tree-sitter/update.nix @@ -429,10 +429,7 @@ let update-all-grammars = writeShellScript "update-all-grammars.sh" '' set -euo pipefail - echo "fetching list of grammars" 1>&2 - treeSitterRepos=$(${updateImpl} fetch-orga-latest-repos '{"orga": "tree-sitter"}') - echo "checking the tree-sitter repo list against the grammars we know" 1>&2 - printf '%s' "$treeSitterRepos" | ${updateImpl} check-tree-sitter-repos '{}' + ${updateImpl} fetch-and-check-tree-sitter-repos '{}' echo "writing files to ${outputDir}" 1>&2 mkdir -p "${outputDir}" ${forEachParallel diff --git a/pkgs/development/tools/parsing/tree-sitter/update_impl.py b/pkgs/development/tools/parsing/tree-sitter/update_impl.py index 92db75ef6502b..db470617ed9c2 100644 --- a/pkgs/development/tools/parsing/tree-sitter/update_impl.py +++ b/pkgs/development/tools/parsing/tree-sitter/update_impl.py @@ -132,40 +132,35 @@ def fetchRepo() -> None: sys.exit("input json must have `orga` and `repo` keys") -def fetchOrgaLatestRepos() -> None: +def fetchOrgaLatestRepos(orga: str) -> set[str]: """fetch the latest (100) repos from the given github organization""" - match jsonArg: - case {"orga": orga}: - token: str | None = os.environ.get("GITHUB_TOKEN", None) - out = run_cmd( - curl_github_args( - token, - url=f"https://api.github.com/orgs/{quote(orga)}/repos?per_page=100" - ) - ) - match curl_result(out): - case "not found": - sys.exit(f"github organization {orga} not found") - case list(repos): - res: list[str] = [] - for repo in repos: - name = repo.get("name") - if name: - res.append(name) - json.dump(res, sys.stdout) - case other: - sys.exit(f"github result was not a list of repos, but {other}") + token: str | None = os.environ.get("GITHUB_TOKEN", None) + out = run_cmd( + curl_github_args( + token, + url=f"https://api.github.com/orgs/{quote(orga)}/repos?per_page=100" + ) + ) + match curl_result(out): + case "not found": + sys.exit(f"github organization {orga} not found") + case list(repos): + res: list[str] = [] + for repo in repos: + name = repo.get("name") + if name: + res.append(name) + return set(res) case _: - sys.exit("input json must have `orga` key") + sys.exit("github result was not a list of repos, but {other}") -def checkTreeSitterRepos() -> None: +def checkTreeSitterRepos(latest_github_repos: set[str]) -> 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) + unknown = latest_github_repos - (known | ignored) if unknown: sys.exit(f"These repositories are neither known nor ignored:\n{unknown}") @@ -204,13 +199,18 @@ def printAllGrammarsNixFile() -> None: ) +def fetchAndCheckTreeSitterRepos() -> None: + log("fetching list of grammars") + latest_repos = fetchOrgaLatestRepos(orga="tree-sitter") + log("checking the tree-sitter repo list against the grammars we know") + checkTreeSitterRepos(latest_repos) + + match mode: case "fetch-repo": fetchRepo() - case "fetch-orga-latest-repos": - fetchOrgaLatestRepos() - case "check-tree-sitter-repos": - checkTreeSitterRepos() + case "fetch-and-check-tree-sitter-repos": + fetchAndCheckTreeSitterRepos() case "print-all-grammars-nix-file": printAllGrammarsNixFile() case _: |