Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __version__ and __version_info__ to rerun package #7104

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
3 changes: 3 additions & 0 deletions rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions rerun_py/tests/unit/test_version.py
Original file line number Diff line number Diff line change
@@ -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()
66 changes: 66 additions & 0 deletions scripts/ci/update_rerun_py_version.py
Original file line number Diff line number Diff line change
@@ -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()
48 changes: 48 additions & 0 deletions tests/python/release_checklist/check_version.py
Original file line number Diff line number Diff line change
@@ -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)
Loading