version.py
python
sha256:c3910cc561368d2b40576c1fbb0841b5d3abefd0a65c96c85114a7238222c77c
fix: root-of-push snapshots were never hash-verified before…
Sonnet 5
patch
5 days ago
| 1 | """Muse version — single source of truth is pyproject.toml. |
| 2 | |
| 3 | All version references (app, protocol, MCP server) read from here. |
| 4 | """ |
| 5 | |
| 6 | |
| 7 | |
| 8 | def _read_version() -> str: |
| 9 | try: |
| 10 | from importlib.metadata import version |
| 11 | return version("musehub") |
| 12 | except Exception: |
| 13 | pass |
| 14 | try: |
| 15 | from pathlib import Path |
| 16 | import re |
| 17 | pyproject = Path(__file__).resolve().parent.parent.parent / "pyproject.toml" |
| 18 | match = re.search(r'^version\s*=\s*"([^"]+)"', pyproject.read_text(), re.MULTILINE) |
| 19 | if match: |
| 20 | return match.group(1) |
| 21 | except Exception: |
| 22 | pass |
| 23 | return "0.0.0-unknown" |
| 24 | |
| 25 | |
| 26 | MUSE_VERSION: str = _read_version() |
| 27 | |
| 28 | import re as _re |
| 29 | |
| 30 | _version_parts = MUSE_VERSION.split(".") |
| 31 | MUSE_VERSION_MAJOR: int = int(_version_parts[0]) if len(_version_parts) > 0 else 0 |
| 32 | MUSE_VERSION_MINOR: int = int(_version_parts[1]) if len(_version_parts) > 1 else 0 |
| 33 | # Strip PEP 440 pre-release / post-release suffixes (e.g. "0rc1", "0a1", "0b2", "0.post1") |
| 34 | MUSE_VERSION_PATCH: int = ( |
| 35 | int(m.group()) if (m := _re.match(r"\d+", _version_parts[2])) else 0 |
| 36 | ) if len(_version_parts) > 2 else 0 |
| 37 | |
| 38 | |
| 39 | def is_compatible(client_version: str) -> bool: |
| 40 | """Check if a client version is compatible (same major version).""" |
| 41 | try: |
| 42 | parts = client_version.split(".") |
| 43 | client_major = int(parts[0]) |
| 44 | return client_major == MUSE_VERSION_MAJOR |
| 45 | except (ValueError, IndexError): |
| 46 | return False |
File History
1 commit
sha256:c3910cc561368d2b40576c1fbb0841b5d3abefd0a65c96c85114a7238222c77c
fix: root-of-push snapshots were never hash-verified before…
Sonnet 5
patch
5 days ago