Skip to content

Commit 65b7da6

Browse files
authoredMar 2, 2021
Hide implementation path from generated toc.yml (#1836)
1 parent 0939b27 commit 65b7da6

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
 

Diff for: ‎update_toc_no_implemetation.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This script is intended for use in intermediate doc repos generated from docs.ms CI.
2+
# Given a reference ToC and a set of namespaces, limit the reference to ToC entries that contain
3+
# namespaces in our set.
4+
5+
import argparse
6+
import os
7+
8+
# by default, yaml does not maintain insertion order of the dicts
9+
# given that this is intended to generate TABLE OF CONTENTS values,
10+
# maintaining this order is important.
11+
# The drop-in replacement oyaml is a handy solution for us.
12+
import oyaml as yaml
13+
14+
TARGET_SOURCE_FOLDER = "docs-ref-autogen"
15+
PREVIEW_SOURCE_FOLDER = "preview/docs-ref-autogen"
16+
LEGACY_SOURCE_FOLDER = "legacy/docs-ref-autogen"
17+
18+
root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), ".."))
19+
20+
def check_implementation(uid_path) :
21+
if "implementation" in uid_path:
22+
return True
23+
return False
24+
25+
def grep_children_namespaces(autogenerated_toc_yml, toc_items):
26+
for elem in autogenerated_toc_yml:
27+
if check_implementation(elem['uid']):
28+
continue
29+
toc_map = {}
30+
toc_map['uid'] = elem['uid']
31+
toc_map['name'] = elem['name']
32+
if 'items' in elem:
33+
child_toc_items = []
34+
toc_map['items'] = grep_children_namespaces(elem['items'], child_toc_items)
35+
elif 'type' in elem:
36+
toc_map['type'] = elem['type']
37+
toc_items.append(toc_map)
38+
return toc_items
39+
40+
if __name__ == "__main__":
41+
try:
42+
with open(os.path.join(root_dir, TARGET_SOURCE_FOLDER, "toc.yml"), "r") as latest_reference_yml:
43+
origin_latest_toc = yaml.safe_load(latest_reference_yml)
44+
with open(os.path.join(root_dir, PREVIEW_SOURCE_FOLDER, "toc.yml"), "r") as preview_reference_yml:
45+
origin_preview_toc = yaml.safe_load(preview_reference_yml)
46+
with open(os.path.join(root_dir, LEGACY_SOURCE_FOLDER, "toc.yml"), "r") as legacy_reference_yml:
47+
origin_legacy_toc = yaml.safe_load(legacy_reference_yml)
48+
except Exception as f:
49+
print(
50+
"Execution requires that both the known namespaces and reference yml be defined."
51+
)
52+
present_in_latest = grep_children_namespaces(origin_latest_toc, [])
53+
present_in_preview = grep_children_namespaces(origin_preview_toc, [])
54+
present_in_legacy = grep_children_namespaces(origin_legacy_toc, [])
55+
update_latest_content = yaml.dump(present_in_latest, default_flow_style=False)
56+
update_preview_content = yaml.dump(present_in_preview, default_flow_style=False)
57+
update_legacy_content = yaml.dump(present_in_legacy, default_flow_style=False)
58+
# write the toc
59+
with open(os.path.join(root_dir, TARGET_SOURCE_FOLDER, "toc.yml"), "w", encoding="utf-8") as latest_toc:
60+
latest_toc.write(update_latest_content)
61+
with open(os.path.join(root_dir, PREVIEW_SOURCE_FOLDER, "toc.yml"), "w", encoding="utf-8") as preview_toc:
62+
preview_toc.write(update_preview_content)
63+
with open(os.path.join(root_dir, LEGACY_SOURCE_FOLDER, "toc.yml"), "w", encoding="utf-8") as legacy_toc:
64+
legacy_toc.write(update_legacy_content)

0 commit comments

Comments
 (0)
Please sign in to comment.