Read the [package].version field from Cargo.toml.
()
| 61 | |
| 62 | |
| 63 | def read_cargo_version() -> str: |
| 64 | """Read the [package].version field from Cargo.toml.""" |
| 65 | text = CARGO_TOML_PATH.read_text(encoding="utf-8") |
| 66 | # Find [package] section then walk to the first `version = "..."`. |
| 67 | in_package = False |
| 68 | for line in text.splitlines(): |
| 69 | stripped = line.strip() |
| 70 | if stripped.startswith("["): |
| 71 | in_package = stripped == "[package]" |
| 72 | continue |
| 73 | if not in_package: |
| 74 | continue |
| 75 | m = re.match(r'version\s*=\s*"([^"]+)"', stripped) |
| 76 | if m: |
| 77 | return m.group(1) |
| 78 | raise SystemExit("prepare-release: Cargo.toml [package].version not found") |
| 79 | |
| 80 | |
| 81 | def today_utc_iso() -> str: |