Parses a version string with prefix, for example: v0.45.0-dev (f01773cb1) or v0.115.0-dev.0
(cls: type[T], version: str, drop_dev_suffix: bool = False)
| 47 | |
| 48 | @classmethod |
| 49 | def parse(cls: type[T], version: str, drop_dev_suffix: bool = False) -> T: |
| 50 | """Parses a version string with prefix, for example: v0.45.0-dev (f01773cb1) or v0.115.0-dev.0""" |
| 51 | expected_prefix = cls.get_prefix() |
| 52 | if not version.startswith(expected_prefix): |
| 53 | raise ValueError( |
| 54 | f"Invalid version string '{version}', expected prefix '{expected_prefix}'" |
| 55 | ) |
| 56 | version = version.removeprefix(expected_prefix) |
| 57 | if " " in version: |
| 58 | version, git_hash = version.split(" ") |
| 59 | if not git_hash[0] == "(" or not git_hash[-1] == ")": |
| 60 | raise ValueError(f"Invalid mz version string: {version}") |
| 61 | # Hash ignored |
| 62 | |
| 63 | if drop_dev_suffix: |
| 64 | version, _, _ = version.partition("-dev") |
| 65 | |
| 66 | result = super().parse(version) |
| 67 | assert isinstance(result, cls) |
| 68 | return result |
| 69 | |
| 70 | @classmethod |
| 71 | def try_parse( |