Hide implementation path from generated toc.yml (#1836)

This commit is contained in:
Sima Zhu 2021-03-02 15:39:30 -08:00 коммит произвёл GitHub
Родитель 0939b27426
Коммит 65b7da627c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 64 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,64 @@
# This script is intended for use in intermediate doc repos generated from docs.ms CI.
# Given a reference ToC and a set of namespaces, limit the reference to ToC entries that contain
# namespaces in our set.
import argparse
import os
# by default, yaml does not maintain insertion order of the dicts
# given that this is intended to generate TABLE OF CONTENTS values,
# maintaining this order is important.
# The drop-in replacement oyaml is a handy solution for us.
import oyaml as yaml
TARGET_SOURCE_FOLDER = "docs-ref-autogen"
PREVIEW_SOURCE_FOLDER = "preview/docs-ref-autogen"
LEGACY_SOURCE_FOLDER = "legacy/docs-ref-autogen"
root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), ".."))
def check_implementation(uid_path) :
if "implementation" in uid_path:
return True
return False
def grep_children_namespaces(autogenerated_toc_yml, toc_items):
for elem in autogenerated_toc_yml:
if check_implementation(elem['uid']):
continue
toc_map = {}
toc_map['uid'] = elem['uid']
toc_map['name'] = elem['name']
if 'items' in elem:
child_toc_items = []
toc_map['items'] = grep_children_namespaces(elem['items'], child_toc_items)
elif 'type' in elem:
toc_map['type'] = elem['type']
toc_items.append(toc_map)
return toc_items
if __name__ == "__main__":
try:
with open(os.path.join(root_dir, TARGET_SOURCE_FOLDER, "toc.yml"), "r") as latest_reference_yml:
origin_latest_toc = yaml.safe_load(latest_reference_yml)
with open(os.path.join(root_dir, PREVIEW_SOURCE_FOLDER, "toc.yml"), "r") as preview_reference_yml:
origin_preview_toc = yaml.safe_load(preview_reference_yml)
with open(os.path.join(root_dir, LEGACY_SOURCE_FOLDER, "toc.yml"), "r") as legacy_reference_yml:
origin_legacy_toc = yaml.safe_load(legacy_reference_yml)
except Exception as f:
print(
"Execution requires that both the known namespaces and reference yml be defined."
)
present_in_latest = grep_children_namespaces(origin_latest_toc, [])
present_in_preview = grep_children_namespaces(origin_preview_toc, [])
present_in_legacy = grep_children_namespaces(origin_legacy_toc, [])
update_latest_content = yaml.dump(present_in_latest, default_flow_style=False)
update_preview_content = yaml.dump(present_in_preview, default_flow_style=False)
update_legacy_content = yaml.dump(present_in_legacy, default_flow_style=False)
# write the toc
with open(os.path.join(root_dir, TARGET_SOURCE_FOLDER, "toc.yml"), "w", encoding="utf-8") as latest_toc:
latest_toc.write(update_latest_content)
with open(os.path.join(root_dir, PREVIEW_SOURCE_FOLDER, "toc.yml"), "w", encoding="utf-8") as preview_toc:
preview_toc.write(update_preview_content)
with open(os.path.join(root_dir, LEGACY_SOURCE_FOLDER, "toc.yml"), "w", encoding="utf-8") as legacy_toc:
legacy_toc.write(update_legacy_content)