From 5331b63892d9ff7c14972860c01441f1b79f0e4c Mon Sep 17 00:00:00 2001 From: Tuomas Siipola Date: Thu, 2 Nov 2023 16:20:31 +0200 Subject: [PATCH] Update release-script --- pyproject.toml | 4 ++ release-version | 100 ------------------------------------------------ setup.py | 1 + 3 files changed, 5 insertions(+), 100 deletions(-) delete mode 100755 release-version diff --git a/pyproject.toml b/pyproject.toml index 190d6504..cf952ebb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,3 +15,7 @@ check_untyped_defs = true [[tool.mypy.overrides]] module = ["netCDF4.*"] ignore_missing_imports = true + +[tool.release-version] +filename = "src/data_processing/version.py" +pattern = ["MAJOR = (?P\\d+)", "MINOR = (?P\\d+)", "PATCH = (?P\\d+)"] diff --git a/release-version b/release-version deleted file mode 100755 index 097732cf..00000000 --- a/release-version +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env python3 -import argparse -import re -import subprocess -from dataclasses import dataclass -from pathlib import Path - -VERSION_FILE = "src/data_processing/version.py" - - -def main(component: str): - current_branch = ( - subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]) - .decode("utf-8") - .strip() - ) - assert current_branch == "main", "FATAL: Not in main branch" - old_version = _read_version() - match component: - case "major": - new_version = Version(old_version.major + 1, 0, 0) - case "minor": - new_version = Version(old_version.major, old_version.minor + 1, 0) - case "patch": - new_version = Version( - old_version.major, old_version.minor, old_version.patch + 1 - ) - if not _confirm(f"Updating version {old_version} -> {new_version}. Continue?"): - return - _write_version(new_version) - _commit_and_push(new_version) - - -@dataclass -class Version: - major: int - minor: int - patch: int - - def __str__(self): - return f"{self.major}.{self.minor}.{self.patch}" - - -def _confirm(msg: str) -> bool: - return input(f"{msg} y/n [y] ").lower() in ("y", "") - - -def _commit_and_push(version: Version): - git_commands = [ - ["add", VERSION_FILE], - ["commit", "-m", f"Release version {version}"], - ["push"], - ["tag", f"v{version}"], - ["push", "--tags"], - ] - for command in git_commands: - subprocess.run(["git"] + command, check=True) - - -def _read_int(text: str, key: str) -> int: - return int(re.search(rf"^{key} = (\d+)$", text, flags=re.M)[1]) - - -def _write_int(text: str, key: str, value: int) -> str: - return re.sub(rf"^{key} = \d+$", f"{key} = {value}", text, flags=re.M) - - -def _read_version() -> Version: - text = Path(VERSION_FILE).read_text() - return Version( - major=_read_int(text, "MAJOR"), - minor=_read_int(text, "MINOR"), - patch=_read_int(text, "PATCH"), - ) - - -def _write_version(version: Version): - p = Path(VERSION_FILE) - text = p.read_text() - text = _write_int(text, "MAJOR", version.major) - text = _write_int(text, "MINOR", version.minor) - text = _write_int(text, "PATCH", version.patch) - p.write_text(text) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="Bump cloudnet-processing version number." - ) - parser.add_argument( - "component", - choices=["major", "minor", "patch"], - type=str, - help="Version number component to be updated.", - ) - args = parser.parse_args() - try: - main(args.component) - except AssertionError as err: - print(err) diff --git a/setup.py b/setup.py index c8925080..7c960569 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,7 @@ "black", "docformatter", "pre-commit", + "release-version @ git+https://github.com/actris-cloudnet/release-version.git", ], }, include_package_data=True,