Skip to content

Commit 584ff0e

Browse files
committed
scripts/release.py: add script to help releasing
This will do git tagging and changelog generation and others, but does not push anything to anywhere. Also, no pypi upload (yet!).
1 parent 5a4d8b8 commit 584ff0e

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
# The short X.Y version.
6161
version = '1.0.1'
6262
# The full version, including alpha/beta/rc tags.
63-
release = '1.0.1'
63+
release = version
6464

6565
# The language for content autogenerated by Sphinx. Refer to documentation
6666
# for a list of supported languages.

scripts/release.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import re
5+
import subprocess
6+
import sys
7+
from pathlib import Path
8+
from typing import List
9+
10+
11+
class UsageError(Exception):
12+
pass
13+
14+
15+
def parse_version():
16+
with Path("setup.py").open() as infile:
17+
for line in infile:
18+
if m := re.match(r"VERSION\s*=\s*\"(.*)\"$", line):
19+
return m.groups()[0]
20+
21+
22+
def bump_version(path: Path, prefixes: List[str], current_version: str, new_version: str):
23+
prefixes = tuple(prefixes)
24+
lines = []
25+
for line in path.open():
26+
if line.startswith(prefixes):
27+
line = line.replace(current_version, new_version)
28+
lines.append(line)
29+
30+
path.write_text("".join(lines))
31+
32+
33+
def git(*args):
34+
return subprocess.check_call(["git"] + list(args))
35+
36+
37+
def make(*args):
38+
return subprocess.check_call(["make"] + list(args))
39+
40+
41+
def check_changelog():
42+
old_changelog = Path("CHANGES.rst").read_text()
43+
make("changes")
44+
new_changelog = Path("CHANGES.rst").read_text()
45+
if old_changelog == new_changelog:
46+
raise UsageError("No new changelog entries")
47+
48+
49+
def main():
50+
parser = argparse.ArgumentParser()
51+
parser.add_argument("new_version", help="Version to release")
52+
53+
args = parser.parse_args()
54+
new_version: str = args.new_version
55+
56+
current_version = parse_version()
57+
if current_version is None:
58+
raise UsageError("Unable to parse version")
59+
60+
print(f"Current version: {current_version}")
61+
62+
if current_version == new_version:
63+
raise UsageError("Current version is the same as new version")
64+
65+
check_changelog()
66+
67+
bump_version(Path("setup.py"), ["VERSION"], current_version, new_version)
68+
bump_version(Path("doc/conf.py"), ["version"], current_version, new_version)
69+
70+
git("add", "setup.py", "doc/conf.py")
71+
git("commit", "-m", "Version bump to {}".format(new_version))
72+
git("tag", new_version)
73+
make("changes")
74+
git("add", "CHANGES.rst")
75+
git("commit", "-m", "CHANGES.rst: add release notes for {}".format(new_version))
76+
git("tag", "-f", new_version)
77+
78+
79+
if __name__ == "__main__":
80+
try:
81+
main()
82+
except UsageError as err:
83+
print(f"ERROR: {err}", file=sys.stderr)
84+
sys.exit(1)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from setuptools import setup, find_packages
44

5-
5+
VERSION = "1.0.1"
66
DESCRIPTION = open("README.md").read()
77

88
setup(
99
name="pytest_httpserver",
10-
version="1.0.1",
10+
version=VERSION,
1111
url="https://www.github.com/csernazs/pytest-httpserver",
1212
packages=find_packages(),
1313
package_data={"pytest_httpserver": ["py.typed"]},

0 commit comments

Comments
 (0)