Skip to content

Commit b90b63b

Browse files
committed
don't use files to pass data; call and return directly in conf.py
1 parent 7b67ef1 commit b90b63b

2 files changed

Lines changed: 23 additions & 33 deletions

File tree

conf.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@
2525
sys.path.insert(0, os.path.abspath('docs'))
2626
sys.path.insert(0, os.path.abspath('.'))
2727

28+
import shared_bindings_matrix
29+
2830
master_doc = 'docs/index'
2931

3032
# Grab the JSON values to use while building the module support matrix
3133
# in 'shared-bindings/index.rst'
32-
shared_bindings_json = 'support_matrix.json'
33-
if 'TRAVIS' in os.environ:
34-
shared_bindings_json = os.path.join(os.environ['HOME'], shared_bindings_json)
35-
else:
36-
shared_bindings_json = os.path.join('shared-bindings', shared_bindings_json)
37-
with open(shared_bindings_json) as json_file:
38-
modules_support_matrix = json.load(json_file)
34+
35+
modules_support_matrix = shared_bindings_matrix.support_matrix()
36+
3937
html_context = {
4038
'support_matrix': modules_support_matrix
4139
}

docs/shared_bindings_matrix.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ def read_mpconfig():
4545
return configs
4646

4747

48-
def build_json(modules, configs):
48+
def build_module_map(modules, configs):
4949
""" Establish the base of the JSON file, based on the contents from
5050
`configs`. Base will contain module names, if they're part of
5151
the `FULL_BUILD`, or their default value (0 | 1).
5252
5353
"""
54-
base_json = dict()
54+
base = dict()
5555
full_build = False
5656
for module in modules:
5757
full_name = module
@@ -67,22 +67,22 @@ def build_json(modules, configs):
6767
default_val = find_config.group(1)
6868
else:
6969
default_val = "None"
70-
base_json[search_name] = {
70+
base[search_name] = {
7171
"name": full_name,
7272
"full_build": str(full_build),
7373
"default_value": default_val,
7474
"excluded": []
7575
}
7676

77-
return get_excluded_boards(base_json)
77+
return get_excluded_boards(base)
7878

7979

80-
def get_excluded_boards(base_json):
80+
def get_excluded_boards(base):
8181
""" Cycles through each board's `mpconfigboard.mk` file to determine
8282
if each module is included or not. Boards are selected by existence
8383
in a port listed in `SUPPORTED_PORTS` (e.g. `/port/nrf/feather_52840`)
8484
"""
85-
modules = list(base_json.keys())
85+
modules = list(base.keys())
8686
for port in SUPPORTED_PORTS:
8787
port_dir = "ports/{}/boards".format(port)
8888
for entry in os.scandir(port_dir):
@@ -97,8 +97,8 @@ def get_excluded_boards(base_json):
9797
# check if board uses `SMALL_BUILD`. if yes, and current
9898
# module is marked as `FULL_BUILD`, board is excluded
9999
small_build = re.search("CIRCUITPY_SMALL_BUILD = 1", contents)
100-
if small_build and base_json[module]["full_build"] == "1":
101-
base_json[module]["excluded"].append(entry.name)
100+
if small_build and base[module]["full_build"] == "1":
101+
base[module]["excluded"].append(entry.name)
102102
continue
103103

104104
# check if module is specifically disabled for this board
@@ -107,27 +107,19 @@ def get_excluded_boards(base_json):
107107
if not find_module:
108108
# check if default inclusion is off ('0'). if the board doesn't
109109
# have it explicitly enabled, its excluded.
110-
if base_json[module]["default_value"] == "0":
111-
base_json[module]["excluded"].append(entry.name)
110+
if base[module]["default_value"] == "0":
111+
base[module]["excluded"].append(entry.name)
112112
continue
113113
if (find_module.group(1) == "0" and
114-
find_module.group(1) != base_json[module]["default_value"]):
115-
base_json[module]["excluded"].append(entry.name)
114+
find_module.group(1) != base[module]["default_value"]):
115+
base[module]["excluded"].append(entry.name)
116116

117-
return base_json
117+
return base
118118

119-
if __name__ == "__main__":
119+
120+
def support_matrix():
120121
modules = get_shared_bindings()
121122
configs = read_mpconfig()
122-
base = build_json(sorted(modules), configs)
123-
124-
final_json = json.dumps(base, indent=2)
125-
126-
shared_bindings_json = 'support_matrix.json'
127-
if 'TRAVIS' in os.environ:
128-
shared_bindings_json = os.path.join(os.environ['HOME'], shared_bindings_json)
129-
else:
130-
print(final_json)
131-
shared_bindings_json = os.path.join('shared-bindings', shared_bindings_json)
132-
with open(shared_bindings_json, "w") as matrix:
133-
json.dump(base, matrix, indent=2)
123+
base = build_module_map(sorted(modules), configs)
124+
125+
return base

0 commit comments

Comments
 (0)