Skip to content

Commit cab4063

Browse files
committed
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.
1 parent 81154b4 commit cab4063

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

docs/shared_bindings_matrix.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,11 @@
8080
repository_urls = {}
8181
"""Cache of repository URLs for frozen modules."""
8282

83+
root_dir = pathlib.Path(__file__).resolve().parent.parent
84+
8385
def get_circuitpython_root_dir():
8486
""" The path to the root './circuitpython' directory.
8587
"""
86-
file_path = pathlib.Path(__file__).resolve()
87-
root_dir = file_path.parent.parent
88-
8988
return root_dir
9089

9190
def get_shared_bindings():
@@ -102,7 +101,7 @@ def get_board_mapping():
102101
"""
103102
boards = {}
104103
for port in SUPPORTED_PORTS:
105-
board_path = os.path.join("../ports", port, "boards")
104+
board_path = root_dir / "ports" / port / "boards"
106105
for board_path in os.scandir(board_path):
107106
if board_path.is_dir():
108107
board_files = os.listdir(board_path.path)

tools/ci_set_matrix.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
import sys
2020
import json
2121
import yaml
22+
import pathlib
23+
24+
tools_dir = pathlib.Path(__file__).resolve().parent
25+
top_dir = tools_dir.parent
26+
27+
sys.path.insert(0, str(tools_dir / "adabot"))
28+
sys.path.insert(0, str(top_dir / "docs"))
2229

2330
import build_board_info
2431
from shared_bindings_matrix import get_settings_from_makefile
@@ -40,20 +47,25 @@
4047
"tools/ci_check_duplicate_usb_vid_pid.py",
4148
]
4249

43-
changed_files = {}
44-
try:
45-
changed_files = json.loads(os.environ["CHANGED_FILES"])
46-
except json.decoder.JSONDecodeError as exc:
47-
if exc.msg != "Expecting value":
48-
raise
50+
if len(sys.argv) > 1:
51+
print("Using files list on commandline")
52+
changed_files = sys.argv[1:]
53+
else:
54+
c = os.environ["CHANGED_FILES"]
55+
if c == "":
56+
print("CHANGED_FILES is in environment, but value is empty")
57+
changed_files = []
58+
else:
59+
print("Using files list in CHANGED_FILES")
60+
changed_files = json.loads(os.environ["CHANGED_FILES"])
4961

5062

5163
def set_output(name, value):
5264
if "GITHUB_OUTPUT" in os.environ:
5365
with open(os.environ["GITHUB_OUTPUT"], "at") as f:
5466
print(f"{name}={value}", file=f)
5567
else:
56-
print("Would set GitHub actions output {name} to '{value}'")
68+
print(f"Would set GitHub actions output {name} to '{value}'")
5769

5870

5971
def set_boards_to_build(build_all):
@@ -114,7 +126,7 @@ def set_boards_to_build(build_all):
114126
for board in all_board_ids:
115127
if board not in board_settings:
116128
board_settings[board] = get_settings_from_makefile(
117-
"../ports/" + board_to_port[board], board
129+
str(top_dir / "ports" / board_to_port[board]), board
118130
)
119131
settings = board_settings[board]
120132

0 commit comments

Comments
 (0)