From 41c42b8681dc1245a65e2db8491a573bba1827dc Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 21 Jul 2024 13:39:14 +0200 Subject: [PATCH] Make it easier to debug version numbers. --- src/websockets/version.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/websockets/version.py b/src/websockets/version.py index f1de3cbf..145c7a9e 100644 --- a/src/websockets/version.py +++ b/src/websockets/version.py @@ -55,7 +55,8 @@ def get_version(tag: str) -> str: else: description_re = r"[0-9.]+-([0-9]+)-(g[0-9a-f]{7,}(?:-dirty)?)" match = re.fullmatch(description_re, description) - assert match is not None + if match is None: + raise ValueError(f"Unexpected git description: {description}") distance, remainder = match.groups() remainder = remainder.replace("-", ".") # required by PEP 440 return f"{tag}.dev{distance}+{remainder}" @@ -75,7 +76,8 @@ def get_commit(tag: str, version: str) -> str: # Extract commit from version, falling back to tag if not available. version_re = r"[0-9.]+\.dev[0-9]+\+g([0-9a-f]{7,}|unknown)(?:\.dirty)?" match = re.fullmatch(version_re, version) - assert match is not None + if match is None: + raise ValueError(f"Unexpected version: {version}") (commit,) = match.groups() return tag if commit == "unknown" else commit