@@ -48,7 +48,7 @@ def update_authors_yml(data_update: dict):
4848 write_yaml (file_path , existing_data )
4949
5050
51- def update_myst_yml (data_update : dict , path : Path ):
51+ def update_myst_yml (data_update : dict , path : Path , add_comments : bool = False ):
5252 """Update myst.yml while preserving order and formatting
5353
5454 Args:
@@ -64,36 +64,39 @@ def update_myst_yml(data_update: dict, path: Path):
6464 )
6565
6666 existing_data = read_yaml (file_path ) or {}
67- existing_data = deep_merge (existing_data , data_update )
68-
69- # set comments for project section for convenience
70- if "project" in existing_data :
71- if not existing_data ["project" ].ca .items .get ("id" ):
72- existing_data ["project" ].yaml_set_comment_before_after_key (
73- "id" ,
74- before = "See how to create Table of Contents at: https://mystmd.org/guide/table-of-contents" ,
75- )
76- if not existing_data ["project" ].ca .items .get ("authors" ):
77- existing_data ["project" ].yaml_set_comment_before_after_key (
78- "authors" ,
79- before = "See more authors' fields at: https://mystmd.org/guide/frontmatter#frontmatter-authors" ,
80- )
81- if not existing_data ["project" ].ca .items .get ("venue" ):
82- existing_data ["project" ].yaml_set_comment_before_after_key (
83- "venue" ,
84- before = "See more venue's fields at: https://mystmd.org/guide/frontmatter#venue" ,
85- )
86- if "site" in existing_data :
87- if not existing_data ["site" ].ca .items .get ("options" ):
88- existing_data ["site" ].yaml_set_comment_before_after_key (
89- "options" ,
90- before = "See options at: https://mystmd.org/guide/website-templates#site-options" ,
91- )
92- if not existing_data ["site" ].ca .items .get ("actions" ):
93- existing_data ["site" ].yaml_set_comment_before_after_key (
94- "actions" ,
95- before = "See web layout at: https://mystmd.org/guide/website-navigation" ,
96- )
67+ existing_data = deep_merge (existing_data , data_update , extend_lists = False )
68+
69+ # NOTE: this checking existing_data["key1"].ca.items.get("key2") is buggy
70+ # only add_comments=True during init to avoid adding duplicate comments
71+ if add_comments :
72+ # set comments for project section for convenience
73+ if "project" in existing_data :
74+ if not existing_data ["project" ].ca .items .get ("id" ):
75+ existing_data ["project" ].yaml_set_comment_before_after_key (
76+ "id" ,
77+ before = "See how to create Table of Contents at: https://mystmd.org/guide/table-of-contents" ,
78+ )
79+ if not existing_data ["project" ].ca .items .get ("authors" ):
80+ existing_data ["project" ].yaml_set_comment_before_after_key (
81+ "authors" ,
82+ before = "See more authors' fields at: https://mystmd.org/guide/frontmatter#frontmatter-authors" ,
83+ )
84+ if not existing_data ["project" ].ca .items .get ("venue" ):
85+ existing_data ["project" ].yaml_set_comment_before_after_key (
86+ "venue" ,
87+ before = "See more venue's fields at: https://mystmd.org/guide/frontmatter#venue" ,
88+ )
89+ if "site" in existing_data :
90+ if not existing_data ["site" ].ca .items .get ("options" ):
91+ existing_data ["site" ].yaml_set_comment_before_after_key (
92+ "options" ,
93+ before = "See options at: https://mystmd.org/guide/website-templates#site-options" ,
94+ )
95+ if not existing_data ["site" ].ca .items .get ("actions" ):
96+ existing_data ["site" ].yaml_set_comment_before_after_key (
97+ "actions" ,
98+ before = "See web layout at: https://mystmd.org/guide/website-navigation" ,
99+ )
97100
98101 write_yaml (file_path , existing_data )
99102
@@ -116,7 +119,7 @@ def _write_welcome_file(content_type: tContentType):
116119
117120## Resources
118121
119- - [AfterPython's Project Website](https://ap .afterpython.org)
122+ - [AfterPython's Project Website](https://afterpython .afterpython.org)
120123- [MyST Markdown Guide](https://mystmd.org)
121124
122125Start building your amazing project! 🚀
@@ -159,6 +162,6 @@ def init_myst():
159162 },
160163 },
161164 }
162- update_myst_yml (myst_yml_defaults , path )
165+ update_myst_yml (myst_yml_defaults , path , add_comments = True )
163166 _write_welcome_file (content_type )
164167 subprocess .run (["ap" , "sync" ])
0 commit comments