tree-sitter/update: prepare moving more stuff to python
I don’t want to split up the python code, so for now I’m just passing a “mode” to the script to run a different subset of the functionality.
This commit is contained in:
parent
d325f6f702
commit
7948439959
1 changed files with 34 additions and 24 deletions
|
@ -407,8 +407,8 @@ let
|
|||
# TODO
|
||||
urlEscape = x: x;
|
||||
|
||||
# update one tree-sitter grammar repo and print their nix-prefetch-git output
|
||||
updateGrammar = writers.writePython3 "latest-github-release" {
|
||||
# implementation of the fetching of repo information from github
|
||||
fetchImpl = writers.writePython3 "fetchImpl" {
|
||||
flakeIgnore = ["E501"];
|
||||
} ''
|
||||
from urllib.parse import quote
|
||||
|
@ -419,7 +419,8 @@ let
|
|||
|
||||
debug = True if os.environ.get("DEBUG", False) else False
|
||||
|
||||
jsonArg = sys.argv[1]
|
||||
mode = sys.argv[1]
|
||||
jsonArg = json.loads(sys.argv[2])
|
||||
|
||||
|
||||
def curl_args(orga, repo, token):
|
||||
|
@ -458,7 +459,9 @@ let
|
|||
yield version_rev
|
||||
|
||||
|
||||
match json.loads(jsonArg):
|
||||
def fetchRepo():
|
||||
"""fetch the given repo and print its nix-prefetch output to stdout"""
|
||||
match jsonArg:
|
||||
case {"orga": orga, "repo": repo}:
|
||||
token = os.environ.get("GITHUB_TOKEN", None)
|
||||
curl_cmd = list(curl_args(orga, repo, token))
|
||||
|
@ -481,6 +484,13 @@ let
|
|||
)
|
||||
case _:
|
||||
sys.exit("input json must have `orga` and `repo` keys")
|
||||
|
||||
|
||||
match mode:
|
||||
case "fetch-repo":
|
||||
fetchRepo()
|
||||
case _:
|
||||
sys.exit(f"mode {mode} unknown")
|
||||
'';
|
||||
|
||||
# find the latest repos of a github organization
|
||||
|
@ -522,7 +532,7 @@ let
|
|||
mkdir -p "$outputDir"
|
||||
${foreachSh allGrammars
|
||||
({name, orga, repo}: ''
|
||||
${updateGrammar} '${lib.generators.toJSON {} {inherit orga repo;}}' \
|
||||
${fetchImpl} fetch-repo '${lib.generators.toJSON {} {inherit orga repo;}}' \
|
||||
> $outputDir/${name}.json
|
||||
'')}
|
||||
( echo "{ lib }:"
|
||||
|
|
Loading…
Reference in a new issue