From fa3def3b67ad13edf8614cdc8e1b2ca30d415b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Tue, 4 Jun 2024 13:06:01 +0100 Subject: [PATCH] release.py: introduce pyproject.toml --- extra/release.py | 17 +++++++++-------- pyproject.toml | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/extra/release.py b/extra/release.py index 028f5bc619..72a2a58b18 100755 --- a/extra/release.py +++ b/extra/release.py @@ -9,10 +9,11 @@ from typing import Callable, List, Tuple import click +import tomli from packaging.version import Version, parse BASE = Path(__file__).parent.parent.absolute() -BEETS_INIT = BASE / "beets" / "__init__.py" +PYPROJECT = BASE / "pyproject.toml" CHANGELOG = BASE / "docs" / "changelog.rst" MD_CHANGELOG_SECTION_LIST = re.compile(r"- .+?(?=\n\n###|$)", re.DOTALL) @@ -49,7 +50,11 @@ def update_changelog(text: str, new: Version) -> str: UpdateVersionCallable = Callable[[str, Version], str] FILENAME_AND_UPDATE_TEXT: List[Tuple[Path, UpdateVersionCallable]] = [ ( - BEETS_INIT, + PYPROJECT, + lambda text, new: re.sub(r"(?<=\nversion = )[^\n]+", f'"{new}"', text), + ), + ( + BASE / "beets" / "__init__.py", lambda text, new: re.sub( r"(?<=__version__ = )[^\n]+", f'"{new}"', text ), @@ -63,12 +68,8 @@ def validate_new_version( ctx: click.Context, param: click.Argument, value: Version ) -> Version: """Validate the version is newer than the current one.""" - with BEETS_INIT.open() as f: - contents = f.read() - - m = re.search(r'(?<=__version__ = ")[^"]+', contents) - assert m, "Current version not found in __init__.py" - current = parse(m.group()) + with PYPROJECT.open("rb") as f: + current = parse(tomli.load(f)["tool"]["poetry"]["version"]) if not value > current: msg = f"version must be newer than {current}" diff --git a/pyproject.toml b/pyproject.toml index 53f2ae8b93..9ed2aebaca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -139,6 +139,7 @@ web = ["flask", "flask-cors"] [tool.poetry.scripts] beet = "beets.ui:main" +release = "extra.release:cli" [build-system] requires = ["poetry-core>=1.0.0"]