From 070acf3c4efe051d32d88289d9d9f888c1bc8eda Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 7 Aug 2024 15:37:35 -0400 Subject: [PATCH 1/3] Add __version__ and __version_info__ to rerun package --- .github/workflows/release.yml | 4 ++ rerun_py/rerun_sdk/rerun/__init__.py | 3 ++ scripts/ci/update_rerun_py_version.py | 66 +++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 scripts/ci/update_rerun_py_version.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b0ccc4c8663a..a4d38187ae67 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -137,6 +137,10 @@ jobs: echo "current=$current" >> "$GITHUB_OUTPUT" echo "final=$final" >> "$GITHUB_OUTPUT" + - name: Update rerun_py version + run: | + pixi run python scripts/ci/update_rerun_py_version.py "${{ steps.versioning.outputs.current }}" + - name: Update rerun_notebook package version run: | pixi run python scripts/ci/update_rerun_notebook_version.py "${{ steps.versioning.outputs.current }}" diff --git a/rerun_py/rerun_sdk/rerun/__init__.py b/rerun_py/rerun_sdk/rerun/__init__.py index 6a4186720ecf..71b78c6b7c02 100644 --- a/rerun_py/rerun_sdk/rerun/__init__.py +++ b/rerun_py/rerun_sdk/rerun/__init__.py @@ -7,6 +7,9 @@ import numpy as np +__version__ = "0.18.0-alpha.1" +__version_info__ = (0, 18, 0, "alpha.1") + # ===================================== # API RE-EXPORTS # Important: always us the `import _ as _` format to make it explicit to type-checkers that these are public APIs. diff --git a/scripts/ci/update_rerun_py_version.py b/scripts/ci/update_rerun_py_version.py new file mode 100644 index 000000000000..94cf612a3810 --- /dev/null +++ b/scripts/ci/update_rerun_py_version.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +""" +Updates the version information in rerun_sdk. + +This includes: +- `rerun.__version__` +- `rerun.__version_info__` +""" + +from __future__ import annotations + +import argparse +import sys +from pathlib import Path + +import semver + + +def update(line, version_line, version_info_line): + if line.startswith("__version__"): + if line != version_line: + return version_line + if line.startswith("__version_info__"): + if line != version_info_line: + return version_info_line + return line + + +def set_rerun_py_version(init_path: Path, version: str) -> None: + sem_version = semver.VersionInfo.parse(version) + + version_line = f'__version__ = "{version}"\n' + version_info_line = f'__version_info__ = ({sem_version.major}, {sem_version.minor}, {sem_version.patch}, "{sem_version.prerelease}")\n' + + with init_path.open() as f: + lines = f.readlines() + + new_lines = [update(line, version_line, version_info_line) for line in lines] + + if new_lines != lines: + with init_path.open("w") as f: + f.writelines(new_lines) + else: + print(f"Version already set to {version} in {init_path}") + + +def main() -> None: + parser = argparse.ArgumentParser(description="Update rerun_py __version__ variable.") + parser.add_argument("VERSION", help="Version to use") + args = parser.parse_args() + + # check that the version is valid + try: + semver.VersionInfo.parse(args.VERSION) + except ValueError: + print(f"Invalid semver version: {args.VERSION}", file=sys.stderr, flush=True) + sys.exit(1) + + project_path = Path(__file__).parent.parent.parent.absolute() + + set_rerun_py_version(project_path / "rerun_py" / "rerun_sdk" / "rerun" / "__init__.py", args.VERSION) + + +if __name__ == "__main__": + main() From 9dc299251eb9de8199994ab5b62b787a3a666458 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 7 Aug 2024 15:52:26 -0400 Subject: [PATCH 2/3] Add a release checklist for the version --- .../python/release_checklist/check_version.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/python/release_checklist/check_version.py diff --git a/tests/python/release_checklist/check_version.py b/tests/python/release_checklist/check_version.py new file mode 100644 index 000000000000..78d34a59a5d2 --- /dev/null +++ b/tests/python/release_checklist/check_version.py @@ -0,0 +1,48 @@ +from __future__ import annotations + +import os +from argparse import Namespace +from uuid import uuid4 + +import rerun as rr + +README = """\ +# Version check + +- Verify the version number is correct given the release. +""" + + +def log_readme() -> None: + rr.log("readme", rr.TextDocument(README, media_type=rr.MediaType.MARKDOWN), timeless=True) + + +def log_the_versions() -> None: + rr.log( + "/version", + rr.TextDocument( + f"""``` +__version__ = {rr.__version__} +___version_info___ = {rr.__version_info__} +rr.version() = {rr.version()} +``` +""", + media_type=rr.MediaType.MARKDOWN, + ), + ) + + +def run(args: Namespace) -> None: + rr.script_setup(args, f"{os.path.basename(__file__)}", recording_id=uuid4()) + + log_readme() + log_the_versions() + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser(description="Interactive release checklist") + rr.script_add_args(parser) + args = parser.parse_args() + run(args) From 5ef6363d39fb6e7e0171b4fc713c4981f487bf84 Mon Sep 17 00:00:00 2001 From: Jeremy Leibs Date: Wed, 7 Aug 2024 15:59:38 -0400 Subject: [PATCH 3/3] Also unit-test that our versions are self-consistent --- rerun_py/tests/unit/test_version.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 rerun_py/tests/unit/test_version.py diff --git a/rerun_py/tests/unit/test_version.py b/rerun_py/tests/unit/test_version.py new file mode 100644 index 000000000000..052c5c2c6b3e --- /dev/null +++ b/rerun_py/tests/unit/test_version.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +import rerun as rr +import semver + + +def test_version() -> None: + ver = semver.VersionInfo.parse(rr.__version__) + + assert ver.major == rr.__version_info__[0] + assert ver.minor == rr.__version_info__[1] + assert ver.patch == rr.__version_info__[2] + + if ver.prerelease: + assert ver.prerelease == rr.__version_info__[3] + else: + assert len(rr.__version_info__) == 3 + + assert rr.__version__ in rr.version() + + +if __name__ == "__main__": + test_version()