From cab40630573dc9444590782f88471cb8cb0625a4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 14 Oct 2022 09:23:35 -0500 Subject: [PATCH] Make it easier to locally test ci_set_matrix Now you can e.g., `tools/ci_set_matrix.py ports/raspberrypi/mpconfigport.h` and see what outputs would be set. --- docs/shared_bindings_matrix.py | 7 +++---- tools/ci_set_matrix.py | 28 ++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py index 5b9b63d8fd..196415ca2f 100644 --- a/docs/shared_bindings_matrix.py +++ b/docs/shared_bindings_matrix.py @@ -80,12 +80,11 @@ This is the same list as in the preprocess_frozen_modules script.""" repository_urls = {} """Cache of repository URLs for frozen modules.""" +root_dir = pathlib.Path(__file__).resolve().parent.parent + def get_circuitpython_root_dir(): """ The path to the root './circuitpython' directory. """ - file_path = pathlib.Path(__file__).resolve() - root_dir = file_path.parent.parent - return root_dir def get_shared_bindings(): @@ -102,7 +101,7 @@ def get_board_mapping(): """ boards = {} for port in SUPPORTED_PORTS: - board_path = os.path.join("../ports", port, "boards") + board_path = root_dir / "ports" / port / "boards" for board_path in os.scandir(board_path): if board_path.is_dir(): board_files = os.listdir(board_path.path) diff --git a/tools/ci_set_matrix.py b/tools/ci_set_matrix.py index 0ae6010ac9..198aca899b 100644 --- a/tools/ci_set_matrix.py +++ b/tools/ci_set_matrix.py @@ -19,6 +19,13 @@ import os import sys import json import yaml +import pathlib + +tools_dir = pathlib.Path(__file__).resolve().parent +top_dir = tools_dir.parent + +sys.path.insert(0, str(tools_dir / "adabot")) +sys.path.insert(0, str(top_dir / "docs")) import build_board_info from shared_bindings_matrix import get_settings_from_makefile @@ -40,12 +47,17 @@ IGNORE = [ "tools/ci_check_duplicate_usb_vid_pid.py", ] -changed_files = {} -try: - changed_files = json.loads(os.environ["CHANGED_FILES"]) -except json.decoder.JSONDecodeError as exc: - if exc.msg != "Expecting value": - raise +if len(sys.argv) > 1: + print("Using files list on commandline") + changed_files = sys.argv[1:] +else: + c = os.environ["CHANGED_FILES"] + if c == "": + print("CHANGED_FILES is in environment, but value is empty") + changed_files = [] + else: + print("Using files list in CHANGED_FILES") + changed_files = json.loads(os.environ["CHANGED_FILES"]) def set_output(name, value): @@ -53,7 +65,7 @@ def set_output(name, value): with open(os.environ["GITHUB_OUTPUT"], "at") as f: print(f"{name}={value}", file=f) else: - print("Would set GitHub actions output {name} to '{value}'") + print(f"Would set GitHub actions output {name} to '{value}'") def set_boards_to_build(build_all): @@ -114,7 +126,7 @@ def set_boards_to_build(build_all): for board in all_board_ids: if board not in board_settings: board_settings[board] = get_settings_from_makefile( - "../ports/" + board_to_port[board], board + str(top_dir / "ports" / board_to_port[board]), board ) settings = board_settings[board]