File: bump_release.py

package info (click to toggle)
python-editables 0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 160 kB
  • sloc: python: 370; makefile: 14
file content (43 lines) | stat: -rw-r--r-- 1,251 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Very hacky script to bump the version when cutting a new release.
#
# This does the following:
#
# 1. Edit the version number in the 3 places in the code it's specified
# 2. Commit the change to git
# 3. Tag the commit with the version
#
# Note - this assumes that you will *immediately* release the new version,
# if you make changes before doing so, the tag will not match the release.

import re
import subprocess
import sys
from pathlib import Path

new_version = sys.argv[1]

files = [
    ("src/editables/__init__.py", r'^__version__ = "(\d+\.\d+)"$'),
    ("pyproject.toml", r'^version = "(\d+\.\d+)"$'),
    ("docs/source/conf.py", r'^release = "(\d+\.\d+)"$'),
]


def repl(m):
    # Replace group 1 with new_version
    return (
        m.group(0)[: m.start(1) - m.start(0)]
        + new_version
        + m.group(0)[m.end(1) - m.start(0) :]
    )


for file, regex in files:
    file = Path(file)
    content = file.read_text(encoding="utf-8")
    new_content = re.sub(regex, repl, content, flags=re.MULTILINE)
    file.write_text(new_content, encoding="utf-8")

subprocess.run(["git", "add"] + [f for f, re in files])
subprocess.run(["git", "commit", "-m", f"Bump version to {new_version}"])
subprocess.run(["git", "tag", new_version])