From 4fa027bc99facff63fe791e6a4328cee4ca3c936 Mon Sep 17 00:00:00 2001 From: EthanMcManus Date: Fri, 30 Jan 2026 17:30:02 -0500 Subject: [PATCH] Fix version bump parsing for pyproject --- scripts/bump_version.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/bump_version.py b/scripts/bump_version.py index ee3803e..9a6ec86 100644 --- a/scripts/bump_version.py +++ b/scripts/bump_version.py @@ -17,16 +17,27 @@ def main() -> int: pyproject_path = Path("plugin/pyproject.toml") text = pyproject_path.read_text(encoding="utf-8") - updated, count = re.subn( - r'(?m)^version\\s*=\\s*"[^"]+"', - f'version = "{version}"', - text, - count=1, - ) - if count != 1: + lines = text.splitlines(keepends=True) + updated_lines = [] + in_project = False + replaced = False + + for line in lines: + stripped = line.lstrip("\ufeff").strip() + if stripped.startswith("[") and stripped.endswith("]"): + in_project = stripped == "[project]" + if in_project and stripped.startswith("version") and "=" in stripped and not replaced: + indent = line[: len(line) - len(line.lstrip("\ufeff "))] + line = f'{indent}version = "{version}"\n' + replaced = True + updated_lines.append(line) + + if not replaced: print("Failed to find version in plugin/pyproject.toml.") return 1 + updated = "".join(updated_lines) + pyproject_path.write_text(updated, encoding="utf-8") return 0