Coverage for src/ezcompiler/utils/_version_utils.py: 100.00%
6 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-16 16:37 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-16 16:37 +0000
1# ///////////////////////////////////////////////////////////////
2# VERSION_UTILS - Version string helpers
3# Project: ezcompiler
4# ///////////////////////////////////////////////////////////////
6"""
7Version utils - Pure helpers for reasoning about version strings.
9No I/O, no logging: these are predicates used by the publication path to
10decide how a release is labelled.
11"""
13from __future__ import annotations
15# ///////////////////////////////////////////////////////////////
16# IMPORTS
17# ///////////////////////////////////////////////////////////////
18import re
20# ///////////////////////////////////////////////////////////////
21# CONSTANTS
22# ///////////////////////////////////////////////////////////////
24# Pre-release markers as components, not as substrings.
25_PRERELEASE_RE = re.compile(
26 r"(?<![a-z])(?:alpha|beta|rc|dev|a\d+|b\d+)(?![a-z])", re.IGNORECASE
27)
29# ///////////////////////////////////////////////////////////////
30# FUNCTIONS
31# ///////////////////////////////////////////////////////////////
34def is_prerelease(version: str) -> bool:
35 """Whether a version string denotes a pre-release.
37 Args:
38 version: Version string, e.g. ``"1.2.3"`` or ``"1.2.3-rc.1"``.
40 Returns:
41 bool: True when the version carries a pre-release marker.
43 Example:
44 >>> is_prerelease("1.2.3")
45 False
46 >>> is_prerelease("1.2.3-beta")
47 True
48 """
49 version_without_local_metadata = version.partition("+")[0]
50 return bool(_PRERELEASE_RE.search(version_without_local_metadata))