Update the package version in astrbot/__init__.py. Args: version: Release version to write. Returns: Path to the modified astrbot/__init__.py file. Raises: ReleaseError: The package version constant cannot be found or parsed.
(version: str)
| 194 | |
| 195 | |
| 196 | def update_package_version(version: str) -> Path: |
| 197 | """Update the package version in astrbot/__init__.py. |
| 198 | |
| 199 | Args: |
| 200 | version: Release version to write. |
| 201 | |
| 202 | Returns: |
| 203 | Path to the modified astrbot/__init__.py file. |
| 204 | |
| 205 | Raises: |
| 206 | ReleaseError: The package version constant cannot be found or parsed. |
| 207 | """ |
| 208 | package_init_path = REPO_ROOT / "astrbot" / "__init__.py" |
| 209 | lines = package_init_path.read_text(encoding="utf-8").splitlines(keepends=True) |
| 210 | |
| 211 | for index, line in enumerate(lines): |
| 212 | match = re.match( |
| 213 | r"^(\s*__version__\s*=\s*)([\"'])(.*?)(\2)(\s*(?:#.*)?)(\n?)$", |
| 214 | line, |
| 215 | ) |
| 216 | if not match: |
| 217 | continue |
| 218 | |
| 219 | prefix, quote, _current, _closing_quote, suffix, newline = match.groups() |
| 220 | lines[index] = f"{prefix}{quote}{version}{quote}{suffix}{newline}" |
| 221 | package_init_path.write_text("".join(lines), encoding="utf-8") |
| 222 | return package_init_path |
| 223 | |
| 224 | raise ReleaseError("Missing __version__ in astrbot/__init__.py") |
| 225 | |
| 226 | |
| 227 | def write_changelog(version: str, commits: list[str]) -> Path: |
no test coverage detected