@@ -299,30 +299,40 @@ def update_plotlyjs_dev(args, outdir):
299299
300300
301301def bump_version_pyproject_toml (new_version ):
302- """Bump the version in pyproject.toml to new_version"""
303-
302+ """
303+ Bump the version in pyproject.toml to new_version
304+ Returns True on success, False on failure
305+ """
304306 pyproject_toml_path = "pyproject.toml"
305307 pattern = r'(^\s*version\s*=\s*")([\w.]+)"(\s*$)'
306308 with open (pyproject_toml_path , "r" ) as f :
307309 content = f .read ()
308- new_content = re .sub (
310+ new_content , n_subs = re .subn (
309311 pattern ,
310312 rf'\g<1>{ new_version } "\g<3>' ,
311313 content ,
312314 count = 1 , # replace only the first match
313315 flags = re .MULTILINE ,
314316 )
317+ if n_subs < 1 :
318+ print (f"FAILED to update version in { pyproject_toml_path } . Please update manually and then run `uv lock`." )
319+ return False
320+
315321 with open (pyproject_toml_path , "w" ) as f :
316322 f .write (new_content )
317323
318324 # Run `uv lock` to update the version number in the `uv.lock` file (do not update manually)
319325 subprocess .run (["uv" , "lock" ], check = True )
320326
321327 print (f"Updated version in { pyproject_toml_path } to { new_version } , and updated uv lockfile" )
328+ return True
322329
323330
324331def bump_version_package_json (new_version ):
325- """Bump the version in package.json to new_version"""
332+ """
333+ Bump the version in package.json to new_version
334+ Returns True on success, False on failure
335+ """
326336 js_dir = "js"
327337 subprocess .run (
328338 ["npm" , "version" , new_version , "--no-git-tag-version" , "--allow-same-version" ],
@@ -332,66 +342,103 @@ def bump_version_package_json(new_version):
332342 print (
333343 f"Updated version in { js_dir } /package.json and { js_dir } /package-lock.json to { new_version } "
334344 )
345+ return True
335346
336347
337348def bump_version_citation_cff (new_version , new_date ):
338- """Bump the version in CITATION.cff to new_version and date-released to new_date"""
349+ """
350+ Bump the version in CITATION.cff to new_version and date-released to new_date
351+ Returns True on success, False on failure
352+ """
339353 citation_cff_path = "CITATION.cff"
340354 pattern_version = r'(^\s*version\s*:\s*)([\w.]+)(\s*$)'
341355 pattern_date = r'(^\s*date-released\s*:\s*)([0-9\-]+)(\s*$)'
342356
343357 with open (citation_cff_path , "r" ) as f :
344358 content = f .read ()
345- new_content = re .sub (
359+ new_content , n_subs = re .subn (
346360 pattern_version ,
347361 rf'\g<1>{ new_version } \g<3>' ,
348362 content ,
349363 count = 1 , # replace only the first match
350364 flags = re .MULTILINE ,
351365 )
352- new_content = re .sub (
366+ if n_subs < 1 :
367+ print (f"FAILED to update version in { citation_cff_path } . Please update manually." )
368+ return False
369+ new_content , n_subs = re .subn (
353370 pattern_date ,
354371 rf'\g<1>{ new_date } \g<3>' ,
355372 new_content ,
356373 count = 1 , # replace only the first match
357374 flags = re .MULTILINE ,
358375 )
376+ if n_subs < 1 :
377+ print (f"FAILED to update date-released in { citation_cff_path } . Please update manually." )
378+ return False
379+
359380 with open (citation_cff_path , "w" ) as f :
360381 f .write (new_content )
361382 print (
362383 f"Updated version in { citation_cff_path } to { new_version } and date-released to { new_date } "
363384 )
385+ return True
364386
365387def bump_version_changelog_md (new_version , new_date ):
366- """Bump the version in CHANGELOG.md to new_version and date to new_date"""
388+ """
389+ Bump the version in CHANGELOG.md to new_version and date to new_date
390+ Returns True on success, False on failure
391+ """
367392 changelog_md_path = "CHANGELOG.md"
368393 pattern = r'(^\s*##\s*Unreleased\s*$)'
369394 new_header = f"\n \n ## [{ new_version } ] - { new_date } \n "
395+
396+
370397 with open (changelog_md_path , "r" ) as f :
371398 content = f .read ()
372- new_content = re .sub (
399+
400+ # Check if the header already exists, so that we don't add a double header
401+ already_exists_pattern = rf'(^\s*##\s*\[ *{ re .escape (new_version )} *\])'
402+ if re .search (already_exists_pattern , content , flags = re .MULTILINE ):
403+ print (f"Header for version { new_version } already exists in { changelog_md_path } ." )
404+ return True
405+
406+ new_content , n_subs = re .subn (
373407 pattern ,
374408 rf'\g<1>{ new_header } ' ,
375409 content ,
376410 count = 1 , # replace only the first match
377411 flags = re .MULTILINE ,
378412 )
413+ if n_subs < 1 :
414+ print (f"FAILED to update version in { changelog_md_path } . Please update manually." )
415+ return False
416+
379417 with open (changelog_md_path , "w" ) as f :
380418 f .write (new_content )
381- print (f"Updated version in { changelog_md_path } to { new_version } " )
419+ print (f"Added header in { changelog_md_path } with version { new_version } and release date { new_date } " )
420+ return True
382421
383422
384423def bump_version (args ):
385424 """Bump the version of plotly.py everywhere it needs to be updated."""
386425 new_version = args .version
387426 new_date = time .strftime ("%Y-%m-%d" )
388427
389- # bump_version_citation_cff(new_version, new_date)
390- # bump_version_changelog_md(new_version, new_date)
391- # bump_version_package_json(new_version)
428+ success = True
429+
430+ success = success and bump_version_citation_cff (new_version , new_date )
431+ success = success and bump_version_changelog_md (new_version , new_date )
432+ success = success and bump_version_package_json (new_version )
392433 # Do this one last since it's the most visible,
393434 # so that if one of the above commands fails it will be easier to notice
394- bump_version_pyproject_toml (new_version )
435+ success = success and bump_version_pyproject_toml (new_version )
436+
437+ if not success :
438+ print ("\n \n *** FAILED to update version for at least one file. Please check the output above for details. ***\n \n " )
439+ exit (1 )
440+
441+ print (f"\n \n *** SUCCESSFULLY updated version to { new_version } . Please verify the result using `git diff`. ***\n \n " )
395442
396443
397444def make_parser ():
0 commit comments