Returns version object from Semver string. Args: string: version string version_type: version parameter Raises: RuntimeError: If the version string is not valid.
(string, version_type)
| 113 | |
| 114 | @staticmethod |
| 115 | def parse_from_string(string, version_type): |
| 116 | """Returns version object from Semver string. |
| 117 | |
| 118 | Args: |
| 119 | string: version string |
| 120 | version_type: version parameter |
| 121 | |
| 122 | Raises: |
| 123 | RuntimeError: If the version string is not valid. |
| 124 | """ |
| 125 | # Check validity of new version string. |
| 126 | if not re.search(r"[0-9]+\.[0-9]+\.[a-zA-Z0-9]+", string): |
| 127 | raise RuntimeError("Invalid version string: %s" % string) |
| 128 | |
| 129 | major, minor, extension = string.split(".", 2) |
| 130 | |
| 131 | # Isolate patch and identifier string if identifier string exists. |
| 132 | extension_split = extension.split("-", 1) |
| 133 | patch = extension_split[0] |
| 134 | if len(extension_split) == 2: |
| 135 | identifier_string = "-" + extension_split[1] |
| 136 | else: |
| 137 | identifier_string = "" |
| 138 | |
| 139 | return Version(major, |
| 140 | minor, |
| 141 | patch, |
| 142 | identifier_string, |
| 143 | version_type) |
| 144 | |
| 145 | |
| 146 | def get_current_semver_version(): |