"src/targets/vscode:/vscode.git/clone" did not exist on "538dbd755f7e5ce94680dd71949f3331aabcebe5"
utils.py 1.75 KB
Newer Older
1
2
3
from typing import List
from lm_eval.utils import load_yaml_config
from pathlib import Path
baberabb's avatar
baberabb committed
4
5
from typing import Union
import os
6

baberabb's avatar
baberabb committed
7
8

# {{{CI}}}
9
# This is the path where the output for the changed files for the tasks folder is stored
baberabb's avatar
baberabb committed
10
# FILE_PATH = file_path = ".github/outputs/tasks_all_changed_and_modified_files.txt"
11

baberabb's avatar
baberabb committed
12

baberabb's avatar
baberabb committed
13
14
15
# reads a text file and returns a list of words
# used to read the output of the changed txt from tj-actions/changed-files
def load_changed_files(file_path: str) -> List[str]:
16
    with open(file_path, "r") as f:
baberabb's avatar
baberabb committed
17
18
19
        content = f.read()
        words_list = [x for x in content.split()]
    return words_list
20
21


22
23
24
# checks the txt file for list of changed files.
# if file ends with .yaml then check yaml for task name
# if file ends with .py then parse the folder for all yaml files
25
26
27
28
29
30
31
32
33
def parser(full_path: List[str]) -> List[str]:
    _output = set()
    for x in full_path:
        if x.endswith(".yaml"):
            _output.add(load_yaml_config(x)["task"])
        elif x.endswith(".py"):
            path = [str(x) for x in (list(Path(x).parent.glob("*.yaml")))]
            _output |= {load_yaml_config(x)["task"] for x in path}
    return list(_output)
baberabb's avatar
baberabb committed
34
35


baberabb's avatar
baberabb committed
36
def new_tasks() -> Union[List[str], None]:
baberabb's avatar
baberabb committed
37
38
39
40
41
42
43
44
45
46
47
48
    FILENAME = ".github/outputs/tasks_all_changed_and_modified_files.txt"
    if os.path.exists(FILENAME):
        # If tasks folder has changed then we get the list of files from FILENAME
        # and parse the yaml files to get the task names.
        return parser(load_changed_files(FILENAME))
    elif os.getenv("API") is not None:
        # Or if API has changed then we set the ENV variable API to True
        # and run  given tasks.
        return ["arc_easy", "hellaswag", "piqa", "wikitext"]
    # if both not true just do arc_easy
    else:
        return