haystack-tutorials
54 строки · 1.8 Кб
1import tomllib2import argparse3import json4
5
6def read_index(path):7with open(path, "rb") as f:8return tomllib.load(f)9
10
11if __name__ == "__main__":12parser = argparse.ArgumentParser(usage="""python generate_matrix.py --haystack-version v1.18.1""")13parser.add_argument("--index", dest="index", default="index.toml")14parser.add_argument("--notebooks", dest="notebooks", nargs="+", default=[])15parser.add_argument("--haystack-version", dest="version", required=True)16parser.add_argument("--include-main", dest="main", action="store_true")17
18args = parser.parse_args()19index = read_index(args.index)20
21matrix = []22for tutorial in index["tutorial"]:23notebook = tutorial["notebook"]24
25if args.notebooks and notebook not in args.notebooks:26# If the user specified a list of notebooks to run, only run those27# otherwise run all of them28continue29
30if tutorial.get("needs_gpu", False):31# We're not running GPU tutorials on GitHub Actions32# since we don't have a GPUs there33continue34
35if not tutorial.get("colab", True):36# This tutorial doesn't have any runnable Python code37# so there's nothing to test38continue39
40if tutorial.get("haystack_2", False):41# Haystack 2.0 tutorials should be skipped for now42continue43
44version = tutorial.get("haystack_version", args.version)45if version[0] != "v":46version = f"v{version}"47
48matrix.append({"notebook": notebook[:-6], "haystack_version": version})49
50if args.main and "haystack_version" not in tutorial:51# If a tutorial doesn't specify a version, we also test it on main52matrix.append({"notebook": notebook[:-6], "haystack_version": "main"})53
54print(json.dumps(matrix))55