release.py: introduce pyproject.toml

This commit is contained in:
Šarūnas Nejus 2024-06-04 13:06:01 +01:00
parent 7bbd215efc
commit 1aad6e0929
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
2 changed files with 10 additions and 8 deletions

View file

@ -11,10 +11,11 @@ from pathlib import Path
from typing import Callable from typing import Callable
import click import click
import tomli
from packaging.version import Version, parse from packaging.version import Version, parse
BASE = Path(__file__).parent.parent.absolute() BASE = Path(__file__).parent.parent.absolute()
BEETS_INIT = BASE / "beets" / "__init__.py" PYPROJECT = BASE / "pyproject.toml"
CHANGELOG = BASE / "docs" / "changelog.rst" CHANGELOG = BASE / "docs" / "changelog.rst"
MD_CHANGELOG_SECTION_LIST = re.compile(r"- .+?(?=\n\n###|$)", re.DOTALL) MD_CHANGELOG_SECTION_LIST = re.compile(r"- .+?(?=\n\n###|$)", re.DOTALL)
@ -51,7 +52,11 @@ Changelog goes here! Please add your entry to the bottom of one of the lists bel
UpdateVersionCallable = Callable[[str, Version], str] UpdateVersionCallable = Callable[[str, Version], str]
FILENAME_AND_UPDATE_TEXT: list[tuple[Path, UpdateVersionCallable]] = [ 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( lambda text, new: re.sub(
r"(?<=__version__ = )[^\n]+", f'"{new}"', text r"(?<=__version__ = )[^\n]+", f'"{new}"', text
), ),
@ -65,12 +70,8 @@ def validate_new_version(
ctx: click.Context, param: click.Argument, value: Version ctx: click.Context, param: click.Argument, value: Version
) -> Version: ) -> Version:
"""Validate the version is newer than the current one.""" """Validate the version is newer than the current one."""
with BEETS_INIT.open() as f: with PYPROJECT.open("rb") as f:
contents = f.read() current = parse(tomli.load(f)["tool"]["poetry"]["version"])
m = re.search(r'(?<=__version__ = ")[^"]+', contents)
assert m, "Current version not found in __init__.py"
current = parse(m.group())
if not value > current: if not value > current:
msg = f"version must be newer than {current}" msg = f"version must be newer than {current}"

View file

@ -136,6 +136,7 @@ web = ["flask", "flask-cors"]
[tool.poetry.scripts] [tool.poetry.scripts]
beet = "beets.ui:main" beet = "beets.ui:main"
release = "extra.release:cli"
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]