66
77from click import ClickException , UsageError , command , confirm , echo , option , secho
88
9+ # Static global paths for template file replacements
10+ APP_MD_PATH = Path ("docs/reference/app.md" )
11+ MKDOCS_PATH = Path ("mkdocs.yml" )
12+ PYPROJECT_PATH = Path ("pyproject.toml" )
13+ README_PATH = Path ("docs/README.md" )
14+ CODEOWNERS_PATH = Path (".github/CODEOWNERS" )
15+ FUNDING_PATH = Path (".github/FUNDING.yml" )
16+
917
1018def _get_git_config (key : str ) -> str :
1119 try :
@@ -74,20 +82,18 @@ def toml_escape(s: str) -> str:
7482 escaped_email = toml_escape (email )
7583
7684 # 1. Update docs/reference/app.md
77- path_ref = Path ("docs/reference/app.md" )
78- if path_ref .exists ():
79- content = path_ref .read_text ()
85+ if APP_MD_PATH .exists ():
86+ content = APP_MD_PATH .read_text ()
8087 new_content = re .sub (r"^::: project\.app" , lambda _ , r = f"::: { source } .app" : r , content , flags = re .MULTILINE )
8188 if new_content != content :
82- path_ref .write_text (new_content )
89+ APP_MD_PATH .write_text (new_content )
8390 secho (" Updated docs/reference/app.md ✅" , fg = "blue" )
8491 else :
8592 secho (" Warning: File docs/reference/app.md not found, skipping. ⚠️" , fg = "yellow" )
8693
8794 # 2. Update mkdocs.yml
88- path_mkdocs = Path ("mkdocs.yml" )
89- if path_mkdocs .exists ():
90- content = path_mkdocs .read_text ()
95+ if MKDOCS_PATH .exists ():
96+ content = MKDOCS_PATH .read_text ()
9197 new_content = re .sub (
9298 r"^repo_name: .*" ,
9399 lambda _ , r = f"repo_name: { github } /{ name } " : r ,
@@ -101,15 +107,14 @@ def toml_escape(s: str) -> str:
101107 flags = re .MULTILINE ,
102108 )
103109 if new_content != content :
104- path_mkdocs .write_text (new_content )
110+ MKDOCS_PATH .write_text (new_content )
105111 secho (" Updated mkdocs.yml ✅" , fg = "blue" )
106112 else :
107113 secho (" Warning: File mkdocs.yml not found, skipping. ⚠️" , fg = "yellow" )
108114
109115 # 3. Update pyproject.toml
110- path_pyproject = Path ("pyproject.toml" )
111- if path_pyproject .exists ():
112- content = path_pyproject .read_text ()
116+ if PYPROJECT_PATH .exists ():
117+ content = PYPROJECT_PATH .read_text ()
113118 new_content = re .sub (
114119 r"^source = \[.*\]" ,
115120 lambda _ , r = f'source = ["{ source } "]' : r ,
@@ -141,40 +146,37 @@ def toml_escape(s: str) -> str:
141146 flags = re .MULTILINE ,
142147 )
143148 if new_content != content :
144- path_pyproject .write_text (new_content )
149+ PYPROJECT_PATH .write_text (new_content )
145150 secho (" Updated pyproject.toml ✅" , fg = "blue" )
146151 else :
147152 secho (" Warning: File pyproject.toml not found, skipping. ⚠️" , fg = "yellow" )
148153
149154 # 4. Update docs/README.md
150- path_readme = Path ("docs/README.md" )
151- if path_readme .exists ():
152- content = path_readme .read_text ()
155+ if README_PATH .exists ():
156+ content = README_PATH .read_text ()
153157 new_content = re .sub (r"^# .*" , lambda _ , r = f"# { description } " : r , content , flags = re .MULTILINE )
154158 if new_content != content :
155- path_readme .write_text (new_content )
159+ README_PATH .write_text (new_content )
156160 secho (" Updated docs/README.md ✅" , fg = "blue" )
157161 else :
158162 secho (" Warning: File docs/README.md not found, skipping. ⚠️" , fg = "yellow" )
159163
160164 # 5. Update .github/CODEOWNERS
161- path_owners = Path (".github/CODEOWNERS" )
162- if path_owners .exists ():
163- content = path_owners .read_text ()
165+ if CODEOWNERS_PATH .exists ():
166+ content = CODEOWNERS_PATH .read_text ()
164167 new_content = re .sub (r"@.*" , lambda _ , r = f"@{ github } " : r , content , flags = re .MULTILINE )
165168 if new_content != content :
166- path_owners .write_text (new_content )
169+ CODEOWNERS_PATH .write_text (new_content )
167170 secho (" Updated .github/CODEOWNERS ✅" , fg = "blue" )
168171 else :
169172 secho (" Warning: File .github/CODEOWNERS not found, skipping. ⚠️" , fg = "yellow" )
170173
171174 # 6. Update .github/FUNDING.yml
172- path_funding = Path (".github/FUNDING.yml" )
173- if path_funding .exists ():
174- content = path_funding .read_text ()
175+ if FUNDING_PATH .exists ():
176+ content = FUNDING_PATH .read_text ()
175177 new_content = re .sub (r"^github: \[.*\]" , lambda _ , r = f"github: [{ github } ]" : r , content , flags = re .MULTILINE )
176178 if new_content != content :
177- path_funding .write_text (new_content )
179+ FUNDING_PATH .write_text (new_content )
178180 secho (" Updated .github/FUNDING.yml ✅" , fg = "blue" )
179181 else :
180182 secho (" Warning: File .github/FUNDING.yml not found, skipping. ⚠️" , fg = "yellow" )
0 commit comments