From 5dd3ab50d863fb3d5bba6b3ce34f8c377fa18b44 Mon Sep 17 00:00:00 2001 From: Wenbin Hou Date: Tue, 27 Jan 2026 15:55:29 +0800 Subject: [PATCH 1/2] Add bump-version.py script and bump version to 0.1.1 Implement bump-version.py to automate version updates across pyproject.toml and memorylake/__init__.py. The script validates semver format and ensures consistency between version declarations. --- cicd/bump-version.py | 102 +++++++++++++++++++++++++++++++++++++++++ memorylake/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100755 cicd/bump-version.py diff --git a/cicd/bump-version.py b/cicd/bump-version.py new file mode 100755 index 0000000..c0e801c --- /dev/null +++ b/cicd/bump-version.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 + +from __future__ import annotations + +import os +import re +import sys +from pathlib import Path +from typing import Optional + + +def validate_version(version: str) -> bool: + """ + Validate that the version string follows basic semver format (X.Y.Z). + """ + pattern: str = r"^\d+\.\d+\.\d+$" + return bool(re.match(pattern, version)) + + +def update_pyproject_version(new_version: str) -> None: + """ + Update version in pyproject.toml. + """ + pyproject_path: Path = Path("pyproject.toml") + if not pyproject_path.exists(): + raise FileNotFoundError("pyproject.toml not found") + + content: str = pyproject_path.read_text() + + # Use regex to replace the version line under [project] + pattern: str = r'^(version\s*=\s*")[^"]+(")' + match: Optional[re.Match[str]] = re.search(pattern, content, flags=re.MULTILINE) + + if not match: + raise ValueError("Could not find version field in pyproject.toml") + + new_content: str = re.sub(pattern, rf"\g<1>{new_version}\g<2>", content, flags=re.MULTILINE) + pyproject_path.write_text(new_content) + print(f"Updated pyproject.toml: version = \"{new_version}\"") + + +def update_init_version(new_version: str) -> None: + """ + Update version in memorylake/__init__.py. + """ + init_path: Path = Path("memorylake/__init__.py") + if not init_path.exists(): + raise FileNotFoundError("memorylake/__init__.py not found") + + content: str = init_path.read_text() + + # Use regex to replace the __version__ line + pattern: str = r'^(__version__\s*:\s*str\s*=\s*")[^"]+(")$' + match: Optional[re.Match[str]] = re.search(pattern, content, flags=re.MULTILINE) + + if not match: + raise ValueError("Could not find __version__ field in memorylake/__init__.py") + + new_content: str = re.sub(pattern, rf"\g<1>{new_version}\g<2>", content, flags=re.MULTILINE) + init_path.write_text(new_content) + print(f"Updated memorylake/__init__.py: __version__ = \"{new_version}\"") + + +def main() -> int: + """ + Bump version in pyproject.toml and memorylake/__init__.py. + """ + if len(sys.argv) != 2: + print("Usage: bump-version.py ") + print("Example: bump-version.py 1.2.3") + return 1 + + new_version: str = sys.argv[1] + + # Validate version format + if not validate_version(new_version): + print(f"ERROR: Invalid version format: {new_version!r}") + print("Version must follow semver format (e.g., 0.1.1, 1.0.0)") + return 1 + + # Change to repository root + repo_dir: Path = Path(__file__).parent.parent + os.chdir(repo_dir) + + print(f"Bumping version to {new_version!r}...") + print() + + # Update files + try: + update_pyproject_version(new_version) + update_init_version(new_version) + except Exception as e: + print(f"ERROR: {e}") + return 1 + + print() + print(f"Successfully bumped version to {new_version!r}") + return 0 + + +if __name__ == "__main__": + exit(main()) diff --git a/memorylake/__init__.py b/memorylake/__init__.py index c66c5db..96bdbff 100644 --- a/memorylake/__init__.py +++ b/memorylake/__init__.py @@ -1 +1 @@ -__version__: str = "0.1.0" +__version__: str = "0.1.1" diff --git a/pyproject.toml b/pyproject.toml index 47c989c..289d433 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "memorylake" -version = "0.1.0" +version = "0.1.1" description = "MemoryLake" authors = [ {name = "Powerdrill Authors", email = "info@powerdrill.ai"} From 451c95e4d625210527601d466a57418a2d22656e Mon Sep 17 00:00:00 2001 From: Wenbin Hou Date: Tue, 27 Jan 2026 16:00:51 +0800 Subject: [PATCH 2/2] Fix flake8 whitespace errors in bump-version.py --- cicd/bump-version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cicd/bump-version.py b/cicd/bump-version.py index c0e801c..d96262e 100755 --- a/cicd/bump-version.py +++ b/cicd/bump-version.py @@ -30,7 +30,7 @@ def update_pyproject_version(new_version: str) -> None: # Use regex to replace the version line under [project] pattern: str = r'^(version\s*=\s*")[^"]+(")' match: Optional[re.Match[str]] = re.search(pattern, content, flags=re.MULTILINE) - + if not match: raise ValueError("Could not find version field in pyproject.toml") @@ -52,7 +52,7 @@ def update_init_version(new_version: str) -> None: # Use regex to replace the __version__ line pattern: str = r'^(__version__\s*:\s*str\s*=\s*")[^"]+(")$' match: Optional[re.Match[str]] = re.search(pattern, content, flags=re.MULTILINE) - + if not match: raise ValueError("Could not find __version__ field in memorylake/__init__.py")