Return the tuple (major, minor, patch) version extracted from the str.
(
version_str: str, allow_wildcard=False
)
| 242 | |
| 243 | |
| 244 | def _str_to_version( |
| 245 | version_str: str, allow_wildcard=False |
| 246 | ) -> tuple[int | str, int | str, int | str]: |
| 247 | """Return the tuple (major, minor, patch) version extracted from the str.""" |
| 248 | if not isinstance(version_str, str): |
| 249 | raise TypeError( |
| 250 | "Can only convert strings to versions. " |
| 251 | f"Got: {type(version_str)} with value {version_str}." |
| 252 | ) |
| 253 | reg = _VERSION_WILDCARD_REG if allow_wildcard else _VERSION_RESOLVED_REG |
| 254 | res = reg.match(version_str) |
| 255 | if not res: |
| 256 | msg = "Invalid version '{}'. Format should be x.y.z".format(version_str) |
| 257 | if allow_wildcard: |
| 258 | msg += " with {x,y,z} being digits or wildcard." |
| 259 | else: |
| 260 | msg += " with {x,y,z} being numbers without leading zeros." |
| 261 | raise ValueError(msg) |
| 262 | return tuple( |
| 263 | v if v == "*" else int(v) # pylint:disable=g-complex-comprehension |
| 264 | for v in [res.group("major"), res.group("minor"), res.group("patch")] |
| 265 | ) |
| 266 | |
| 267 | |
| 268 | def list_all_versions(root_dir: epath.PathLike) -> list[Version]: |