Skip to content

Commit

Permalink
release.py: introduce pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Jun 4, 2024
1 parent a09a059 commit fa3def3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions extra/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
),
Expand All @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit fa3def3

Please sign in to comment.