aiogram/scripts/bump_versions.py
Alex Root Junior 49d0784e33
Added full support of the Bot API 9.4 (#1761)
* Bump API schema to version 9.4, add new object types, methods, and properties.

* Add tests for `ChatOwnerChanged` and `ChatOwnerLeft` message types

* Add tests for `GetUserProfileAudios`, `RemoveMyProfilePhoto`, and `SetMyProfilePhoto` methods

* Bump version

* Update Makefile variables and refactor `test_get_user_profile_audios.py`

* Document new features and updates from Bot API 9.4 in changelog

* Add `ButtonStyle` enum to represent button styles in the Telegram API

* Fix review issues from PR #1761

- Remove stray '-' artifact from GameHighScore docstring and butcher schema
- Fix Makefile reformat target scope inconsistency (ruff check --fix)
- Fix ButtonStyle enum source URL (#chat -> #inlinekeyboardbutton)
- Add User.get_profile_audios() shortcut method (parallel to get_profile_photos)
- Test ChatOwnerLeft with new_owner=None (edge case)
- Add VideoQuality type and Video.qualities nesting tests
- Add User.get_profile_audios() test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Revert "Fix review issues from PR #1761"

This reverts commit 2184e98988.

* Update source links for `ButtonStyle` documentation to reflect accurate API references

* Fix review issues from PR #1761 (#1762)

* Fix review issues from PR #1761

- Remove stray '-' artifact from GameHighScore docstring
- Fix Makefile reformat target scope inconsistency (ruff check --fix)
- Add User.get_profile_audios() shortcut method (parallel to get_profile_photos)
- Test ChatOwnerLeft with new_owner=None (edge case)
- Add VideoQuality type and Video.qualities nesting tests
- Add User.get_profile_audios() test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Address review comments: use fixture and variables in tests, add changelog

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Address review follow-ups for PR #1762

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* Reformat code

* Shut up, ruff

---------

Co-authored-by: latand <latand666@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Kostiantyn Kriuchkov <36363097+Latand@users.noreply.github.com>
2026-02-10 23:43:52 +02:00

88 lines
2.5 KiB
Python

import json
import re
from pathlib import Path
import toml
BASE_PATTERN = r'({variable} = ").+(")'
PACKAGE_VERSION = re.compile(BASE_PATTERN.format(variable="__version__"))
API_VERSION = re.compile(BASE_PATTERN.format(variable="__api_version__"))
API_VERSION_BADGE = re.compile(r"(API-)[\d.]+(-blue\.svg)")
API_VERSION_LINE = re.compile(
r"(Supports `Telegram Bot API )[\d.]+( <https://core\.telegram\.org/bots/api>`_ )"
)
STAGE_MAPPING = {
"alpha": "a",
"beta": "b",
}
def get_package_version() -> str:
data = toml.load(Path("pyproject.toml").absolute())
raw_version: str = data["tool"]["poetry"]["version"]
if "-" not in raw_version:
return raw_version
version, stage_build = raw_version.split("-", maxsplit=1)
if stage_build:
stage, build = stage_build.split(".")
if stage_str := STAGE_MAPPING.get(stage):
version += f"{stage_str}{build}"
else:
return raw_version
return version
def get_telegram_api_version() -> str:
path = Path.cwd() / ".butcher" / "schema" / "schema.json"
schema = json.loads(path.read_text())
version = schema["api"]["version"]
path = Path.cwd() / ".apiversion"
path.write_text(version + "\n")
return version
def replace_line(content: str, pattern: re.Pattern, new_value: str) -> str:
return pattern.sub(f"\\g<1>{new_value}\\g<2>", content)
def write_package_meta(api_version: str) -> None:
path = Path.cwd() / "aiogram" / "__meta__.py"
content = path.read_text()
content = replace_line(content, API_VERSION, api_version)
print(f"Write {path}") # noqa: T201
path.write_text(content)
def write_readme(api_version: str) -> None:
path = Path.cwd() / "README.rst"
content = path.read_text()
content = replace_line(content, API_VERSION_BADGE, api_version)
content = replace_line(content, API_VERSION_LINE, api_version)
print(f"Write {path}") # noqa: T201
path.write_text(content)
def write_docs_index(api_version: str) -> None:
path = Path.cwd() / "docs" / "index.rst"
content = path.read_text()
content = replace_line(content, API_VERSION_BADGE, api_version)
print(f"Write {path}") # noqa: T201
path.write_text(content)
def main():
api_version = get_telegram_api_version()
print(f"Telegram Bot API version: {api_version}") # noqa: T201
write_package_meta(api_version=api_version)
write_readme(api_version=api_version)
write_docs_index(api_version=api_version)
if __name__ == "__main__":
main()