99import os
1010import shutil
1111import tempfile
12+ from pathlib import Path
1213
1314import invoke
1415import requests
@@ -173,9 +174,7 @@ def yakerize(
173174 os .rename (taget_file , new_filename )
174175
175176
176- @invoke .task (
177- help = {"yak_file" : "Path to the .yak file to publish." , "test_server" : "True to publish to the test server." }
178- )
177+ @invoke .task (help = {"yak_file" : "Path to the .yak file to publish." , "test_server" : "True to publish to the test server." })
179178def publish_yak (ctx , yak_file : str , test_server : bool = False ):
180179 """Publish a YAK package to the YAK server."""
181180
@@ -196,3 +195,49 @@ def publish_yak(ctx, yak_file: str, test_server: bool = False):
196195 ctx .run (f"{ yak_exe_path } push --source https://test.yak.rhino3d.com { yak_file } " )
197196 else :
198197 ctx .run (f"{ yak_exe_path } push { yak_file } " )
198+
199+
200+ def _get_version_from_toml () -> str :
201+ with open ("pyproject.toml" , "r" ) as f :
202+ pyproject_data = tomlkit .load (f )
203+ if not pyproject_data :
204+ raise invoke .Exit ("Failed to load pyproject.toml." )
205+
206+ version = pyproject_data .get ("tool" , {}).get ("bumpversion" , {}).get ("current_version" , None )
207+ if not version :
208+ raise invoke .Exit ("Failed to get version from pyproject.toml. Please provide a version number." )
209+ return version
210+
211+
212+ def _get_package_name () -> str :
213+ with open ("pyproject.toml" , "r" ) as f :
214+ pyproject_data = tomlkit .load (f )
215+ if not pyproject_data :
216+ raise invoke .Exit ("Failed to load pyproject.toml." )
217+
218+ name = pyproject_data .get ("project" , {}).get ("name" , None )
219+ if not name :
220+ raise invoke .Exit ("Failed to get package name from pyproject.toml." )
221+ return name
222+
223+
224+ @invoke .task (help = {"version" : "New minimum version to set in the header. If not provided, current version is used." })
225+ def update_gh_header (ctx , version = None ):
226+ """Update the minimum version header of all CPython Grasshopper components."""
227+ version = version or _get_version_from_toml ()
228+ package_name = _get_package_name ()
229+ new_header = f"# r: { package_name } >={ version } "
230+
231+ for file in Path (ctx .ghuser_cpython .source_dir ).glob ("**/code.py" ):
232+ try :
233+ with open (file , "r" , encoding = "utf-8" ) as f :
234+ original_content = f .readlines ()
235+ with open (file , "w" , encoding = "utf-8" ) as f :
236+ for line in original_content :
237+ if line .startswith (f"# r: { package_name } " ):
238+ f .write (new_header + "\n " )
239+ else :
240+ f .write (line )
241+ print (f"✅ Updated: { file } " )
242+ except Exception as e :
243+ print (f"❌ Failed to update { file } : { e } " )
0 commit comments