2323from dataclasses import dataclass , field
2424from typing import List , Set , Tuple
2525
26+ from scripts .common .guideline_pages import (
27+ build_guideline_page_content ,
28+ extract_guideline_title ,
29+ )
2630from scripts .common .guideline_templates import parse_bibliography_entries
2731from scripts .guideline_utils import (
2832 chapter_to_filename ,
3438 normalize_md ,
3539)
3640
37- # SPDX header to prepend to guideline files
38- GUIDELINE_FILE_HEADER = """\
39- .. SPDX-License-Identifier: MIT OR Apache-2.0
40- SPDX-FileCopyrightText: The Coding Guidelines Subcommittee Contributors
41-
42- """
43-
4441
4542@dataclass
4643class CodeTestResult :
@@ -138,9 +135,9 @@ def wrap_in_main(code: str) -> str:
138135 has_mod = re .search (r'\bmod\b' , code )
139136 has_type = re .search (r'\btype\b' , code )
140137
141- # If it looks like top-level items, don't wrap
138+ # If it looks like top-level items, add a stub main
142139 if has_functions or has_impl or has_struct or has_enum or has_trait or has_mod or has_type :
143- return code
140+ return code + " \n \n fn main() {}"
144141
145142 # Check for use/const/static statements
146143 has_use = re .search (r'\buse\b' , code )
@@ -575,8 +572,8 @@ def generate_comment(
575572 chapter_slug = chapter_to_filename (chapter )
576573 guideline_id = extract_guideline_id (rst_content )
577574
578- # Prepend the SPDX header to the RST content for display
579- full_rst_content = GUIDELINE_FILE_HEADER + rst_content . strip ( )
575+ page_title = extract_guideline_title ( rst_content ) or f"Guideline { guideline_id } "
576+ full_rst_content = build_guideline_page_content ( page_title , rst_content )
580577
581578 # Format test results
582579 test_results_section = format_test_results (test_results )
@@ -587,34 +584,36 @@ def generate_comment(
587584 # Determine target path based on whether we have a guideline ID
588585 if guideline_id :
589586 target_dir = f"src/coding-guidelines/{ chapter_slug } /"
590- target_file = f"{ target_dir } { guideline_id } .rst.inc "
587+ target_file = f"{ target_dir } { guideline_id } .rst"
591588 chapter_index_file = f"{ target_dir } index.rst"
592589 file_instructions = f"""
593590### 📁 Target Location
594591
595- Create a new file: `{ target_file } `
592+ Create a new file:
593+
594+ - `{ target_file } `
596595
597- > **Note:** The `.rst.inc` extension prevents Sphinx from auto-discovering the file.
598- > It will be included via the chapter's `index.rst`.
596+ Create the guideline page like this:
599597
600- We add it to this path, to allow the newly added guideline to appear in the correct chapter.
598+ ```rst
599+ { full_rst_content }
600+ ```
601601
602602### 🗂️ Update Chapter Index
603603
604- Update `{ chapter_index_file } ` to include `{ guideline_id } .rst.inc`, like so:
604+ Ensure `{ chapter_index_file } ` lists guideline pages with a toctree:
605+
606+ ```rst
607+ .. toctree::
608+ :maxdepth: 1
609+ :titlesonly:
610+ :glob:
605611
612+ gui_*
606613```
607- Chapter Name Here <- chapter heading inside of `{ chapter_index_file } `
608- =================
609-
610- .. include:: gui_7y0GAMmtMhch.rst.inc -| existing guidelines
611- .. include:: gui_ADHABsmK9FXz.rst.inc |
612- ... |
613- ... |
614- .. include:: gui_RHvQj8BHlz9b.rst.inc |
615- .. include:: gui_dCquvqE1csI3.rst.inc -|
616- .. include:: { guideline_id } .rst.inc <- your new guideline to add
617- ```"""
614+
615+ With `:glob:` you do not need to add the new guideline manually.
616+ """
618617 else :
619618 return "No guideline ID generated, failing!"
620619
@@ -632,16 +631,21 @@ def generate_comment(
632631 git pull origin main
633632 git checkout -b guideline/your-descriptive-branch-name
634633 ```
635- 3. **Create the guideline file **:
634+ 3. **Create the guideline directory **:
636635 ```bash
637636 mkdir -p src/coding-guidelines/{ chapter_slug }
638637 ```
639- 4. **Copy the RST content** below into a new file named `{ guideline_id } .rst.inc `
640- 5. **Update the chapter index** - Add an include directive to `src/coding-guidelines/{ chapter_slug } /index.rst`:
638+ 4. **Copy the RST content** below into a new file named `{ guideline_id } .rst`
639+ 5. **Ensure the chapter index** `src/coding-guidelines/{ chapter_slug } /index.rst` contains the toctree block :
641640 ```rst
642- .. include:: { guideline_id } .rst.inc
641+ .. toctree::
642+ :maxdepth: 1
643+ :titlesonly:
644+ :glob:
645+
646+ gui_*
643647 ```
644- Keep the includes in alphabetical order by guideline ID .
648+ With `:glob:` you do not need to update the index per guideline .
6456496. **Build locally** to verify the guideline renders correctly:
646650 ```bash
647651 ./make.py
0 commit comments