File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed
Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -17,16 +17,27 @@ def main() -> int:
1717
1818 pyproject_path = Path ("plugin/pyproject.toml" )
1919 text = pyproject_path .read_text (encoding = "utf-8" )
20- updated , count = re .subn (
21- r'(?m)^version\\s*=\\s*"[^"]+"' ,
22- f'version = "{ version } "' ,
23- text ,
24- count = 1 ,
25- )
26- if count != 1 :
20+ lines = text .splitlines (keepends = True )
21+ updated_lines = []
22+ in_project = False
23+ replaced = False
24+
25+ for line in lines :
26+ stripped = line .lstrip ("\ufeff " ).strip ()
27+ if stripped .startswith ("[" ) and stripped .endswith ("]" ):
28+ in_project = stripped == "[project]"
29+ if in_project and stripped .startswith ("version" ) and "=" in stripped and not replaced :
30+ indent = line [: len (line ) - len (line .lstrip ("\ufeff " ))]
31+ line = f'{ indent } version = "{ version } "\n '
32+ replaced = True
33+ updated_lines .append (line )
34+
35+ if not replaced :
2736 print ("Failed to find version in plugin/pyproject.toml." )
2837 return 1
2938
39+ updated = "" .join (updated_lines )
40+
3041 pyproject_path .write_text (updated , encoding = "utf-8" )
3142 return 0
3243
You can’t perform that action at this time.
0 commit comments