Skip to content

Commit a62c645

Browse files
Merge pull request #6 from ClipABit/Workflow-Automation-Update
Fix version bump parsing for pyproject
2 parents 8406a0d + 4fa027b commit a62c645

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

scripts/bump_version.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)