Cleans the table of content of the model documentation by removing duplicates and sorting models alphabetically.
(doc_list)
| 23 | |
| 24 | |
| 25 | def clean_doc_toc(doc_list): |
| 26 | """ |
| 27 | Cleans the table of content of the model documentation by removing duplicates and sorting models alphabetically. |
| 28 | """ |
| 29 | counts = defaultdict(int) |
| 30 | overview_doc = [] |
| 31 | new_doc_list = [] |
| 32 | for doc in doc_list: |
| 33 | if "local" in doc: |
| 34 | counts[doc["local"]] += 1 |
| 35 | |
| 36 | if doc["title"].lower() == "overview": |
| 37 | overview_doc.append({"local": doc["local"], "title": doc["title"]}) |
| 38 | else: |
| 39 | new_doc_list.append(doc) |
| 40 | |
| 41 | doc_list = new_doc_list |
| 42 | duplicates = [key for key, value in counts.items() if value > 1] |
| 43 | |
| 44 | new_doc = [] |
| 45 | for duplicate_key in duplicates: |
| 46 | titles = list({doc["title"] for doc in doc_list if doc["local"] == duplicate_key}) |
| 47 | if len(titles) > 1: |
| 48 | raise ValueError( |
| 49 | f"{duplicate_key} is present several times in the documentation table of content at " |
| 50 | "`docs/source/en/_toctree.yml` with different *Title* values. Choose one of those and remove the " |
| 51 | "others." |
| 52 | ) |
| 53 | # Only add this once |
| 54 | new_doc.append({"local": duplicate_key, "title": titles[0]}) |
| 55 | |
| 56 | # Add none duplicate-keys |
| 57 | new_doc.extend([doc for doc in doc_list if "local" not in counts or counts[doc["local"]] == 1]) |
| 58 | new_doc = sorted(new_doc, key=lambda s: s["title"].lower()) |
| 59 | |
| 60 | # "overview" gets special treatment and is always first |
| 61 | if len(overview_doc) > 1: |
| 62 | raise ValueError("{doc_list} has two 'overview' docs which is not allowed.") |
| 63 | |
| 64 | overview_doc.extend(new_doc) |
| 65 | |
| 66 | # Sort |
| 67 | return overview_doc |
| 68 | |
| 69 | |
| 70 | def check_scheduler_doc(overwrite=False): |
no outgoing calls
no test coverage detected