-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_generators_list.py
More file actions
31 lines (25 loc) · 968 Bytes
/
get_generators_list.py
File metadata and controls
31 lines (25 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
Run in top level of libEnsemble repo to extract list of generators as json file.
Output goes in data/generators.json
"""
import os
import ast
import json
gen_dir = "libensemble/gen_funcs"
result = {}
for fname in os.listdir(gen_dir):
if fname.endswith(".py") and not fname.startswith("_"):
modname = fname[:-3]
path = os.path.join(gen_dir, fname)
with open(path, "r") as f:
source = f.read()
tree = ast.parse(source, filename=fname)
for node in tree.body:
if isinstance(node, ast.Assign):
for target in node.targets:
if isinstance(target, ast.Name) and target.id == "__all__":
if isinstance(node.value, (ast.List, ast.Tuple)):
result[modname] = [elt.s for elt in node.value.elts if isinstance(elt, ast.Str)]
# Save to JSON
with open("generators.json", "w") as out:
json.dump(result, out, indent=2)