-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbump_version.py
More file actions
36 lines (26 loc) · 1014 Bytes
/
Copy pathbump_version.py
File metadata and controls
36 lines (26 loc) · 1014 Bytes
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
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import re
from pathlib import Path
DEFAULT_VERSION_PATH = Path("justoneapi/_version.py")
VERSION_RE = re.compile(r'^__version__ = "(\d+)\.(\d+)\.(\d+)"\s*$')
def bump_patch_version(path: Path) -> str:
content = path.read_text()
match = VERSION_RE.fullmatch(content.strip())
if not match:
raise ValueError(
f"{path} must contain a single __version__ = \"X.Y.Z\" assignment"
)
major, minor, patch = (int(part) for part in match.groups())
next_version = f"{major}.{minor}.{patch + 1}"
path.write_text(f'__version__ = "{next_version}"\n')
return next_version
def main() -> int:
parser = argparse.ArgumentParser(description="Bump the package patch version.")
parser.add_argument("--path", type=Path, default=DEFAULT_VERSION_PATH)
args = parser.parse_args()
print(bump_patch_version(args.path))
return 0
if __name__ == "__main__":
raise SystemExit(main())