MCPcopy Create free account
hub / github.com/ModalityDance/Omni-R1 / check_model_doc

Function check_model_doc

src/transformers/utils/check_doc_toc.py:80–126  ·  view source on GitHub ↗

Check that the content of the table of content in `_toctree.yml` is clean (no duplicates and sorted for the model API doc) and potentially auto-cleans it. Args: overwrite (`bool`, *optional*, defaults to `False`): Whether to just check if the TOC is clean or to auto

(overwrite: bool = False)

Source from the content-addressed store, hash-verified

78
79
80def check_model_doc(overwrite: bool = False):
81 """
82 Check that the content of the table of content in `_toctree.yml` is clean (no duplicates and sorted for the model
83 API doc) and potentially auto-cleans it.
84
85 Args:
86 overwrite (`bool`, *optional*, defaults to `False`):
87 Whether to just check if the TOC is clean or to auto-clean it (when `overwrite=True`).
88 """
89 with open(PATH_TO_TOC, encoding="utf-8") as f:
90 content = yaml.safe_load(f.read())
91
92 # Get to the API doc
93 api_idx = 0
94 while content[api_idx]["title"] != "API":
95 api_idx += 1
96 api_doc = content[api_idx]["sections"]
97
98 # Then to the model doc
99 model_idx = 0
100 while api_doc[model_idx]["title"] != "Models":
101 model_idx += 1
102
103 model_doc = api_doc[model_idx]["sections"]
104
105 # Extract the modalities and clean them one by one.
106 modalities_docs = [(idx, section) for idx, section in enumerate(model_doc) if "sections" in section]
107 diff = False
108 for idx, modality_doc in modalities_docs:
109 old_modality_doc = modality_doc["sections"]
110 new_modality_doc = clean_model_doc_toc(old_modality_doc)
111
112 if old_modality_doc != new_modality_doc:
113 diff = True
114 if overwrite:
115 model_doc[idx]["sections"] = new_modality_doc
116
117 if diff:
118 if overwrite:
119 api_doc[model_idx]["sections"] = model_doc
120 content[api_idx]["sections"] = api_doc
121 with open(PATH_TO_TOC, "w", encoding="utf-8") as f:
122 f.write(yaml.dump(content, allow_unicode=True))
123 else:
124 raise ValueError(
125 "The model doc part of the table of content is not properly sorted, run `make style` to fix this."
126 )
127
128
129if __name__ == "__main__":

Callers 1

check_doc_toc.pyFile · 0.85

Calls 3

clean_model_doc_tocFunction · 0.85
readMethod · 0.80
writeMethod · 0.80

Tested by

no test coverage detected