(overwrite=False)
| 103 | |
| 104 | |
| 105 | def check_pipeline_doc(overwrite=False): |
| 106 | with open(PATH_TO_TOC, encoding="utf-8") as f: |
| 107 | content = yaml.safe_load(f.read()) |
| 108 | |
| 109 | # Get to the API doc |
| 110 | api_idx = 0 |
| 111 | while content[api_idx]["title"] != "API": |
| 112 | api_idx += 1 |
| 113 | api_doc = content[api_idx]["sections"] |
| 114 | |
| 115 | # Then to the model doc |
| 116 | pipeline_idx = 0 |
| 117 | while api_doc[pipeline_idx]["title"] != "Pipelines": |
| 118 | pipeline_idx += 1 |
| 119 | |
| 120 | diff = False |
| 121 | pipeline_docs = api_doc[pipeline_idx]["sections"] |
| 122 | new_pipeline_docs = [] |
| 123 | |
| 124 | # sort sub pipeline docs |
| 125 | for pipeline_doc in pipeline_docs: |
| 126 | if "section" in pipeline_doc: |
| 127 | sub_pipeline_doc = pipeline_doc["section"] |
| 128 | new_sub_pipeline_doc = clean_doc_toc(sub_pipeline_doc) |
| 129 | if overwrite: |
| 130 | pipeline_doc["section"] = new_sub_pipeline_doc |
| 131 | new_pipeline_docs.append(pipeline_doc) |
| 132 | |
| 133 | # sort overall pipeline doc |
| 134 | new_pipeline_docs = clean_doc_toc(new_pipeline_docs) |
| 135 | |
| 136 | if new_pipeline_docs != pipeline_docs: |
| 137 | diff = True |
| 138 | if overwrite: |
| 139 | api_doc[pipeline_idx]["sections"] = new_pipeline_docs |
| 140 | |
| 141 | if diff: |
| 142 | if overwrite: |
| 143 | content[api_idx]["sections"] = api_doc |
| 144 | with open(PATH_TO_TOC, "w", encoding="utf-8") as f: |
| 145 | f.write(yaml.dump(content, allow_unicode=True)) |
| 146 | else: |
| 147 | raise ValueError( |
| 148 | "The model doc part of the table of content is not properly sorted, run `make style` to fix this." |
| 149 | ) |
| 150 | |
| 151 | |
| 152 | if __name__ == "__main__": |
no test coverage detected