Files
training_material/contrib/ci/course.py
Leo Germond 5765516233 can specify DO_NOT_MERGE.SINGLE_COURSE on CI
+ checks on GitLab's CI that it is not specified on MR or main
2024-03-12 14:49:47 +01:00

35 lines
1.1 KiB
Python

import json
import os
import argparse
from pathlib import Path
SINGLE_COURSE_FILE = Path(__file__).resolve().parents[2] / "DO_NOT_MERGE.SINGLE_COURSE"
if __name__ == "__main__":
ap = argparse.ArgumentParser()
ap.add_argument("action", choices=["find"])
ap.add_argument("dir", type=Path)
ap.add_argument("--json", action="store_true")
args = ap.parse_args()
assert args.dir.is_dir()
if args.action == "find":
# courses are all the direct subdirs that contain a course.toml file,
# and any txt files in those dirs is a course variant
if SINGLE_COURSE_FILE.is_file():
with open(SINGLE_COURSE_FILE) as f:
courses = [args.dir / f.read().strip()]
else:
courses = [d.parent for d in args.dir.glob("**/course.toml")]
courses += [f for d in courses for f in d.glob("*.txt")]
courses_str = [str(c.relative_to(args.dir)) for c in courses]
if args.json:
print(json.dumps(courses_str))
else:
print(os.linesep.join(courses_str))