From 10dcfbb3ad14fc4695568a7695adf77db8ce7b0a Mon Sep 17 00:00:00 2001 From: Phil Schaf Date: Mon, 16 Sep 2024 12:19:51 +0200 Subject: [PATCH] simpler validation --- ci/scripts/towncrier_automation.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/ci/scripts/towncrier_automation.py b/ci/scripts/towncrier_automation.py index 091fe5f8f0..ee5c7e3049 100755 --- a/ci/scripts/towncrier_automation.py +++ b/ci/scripts/towncrier_automation.py @@ -2,19 +2,15 @@ from __future__ import annotations import argparse -import re import subprocess from typing import TYPE_CHECKING -from packaging.version import VERSION_PATTERN as _VP +from packaging.version import Version if TYPE_CHECKING: from collections.abc import Sequence -VERSION = re.compile(_VP, re.VERBOSE | re.IGNORECASE) - - class Args(argparse.Namespace): version: str dry_run: bool @@ -44,10 +40,8 @@ def parse_args(argv: Sequence[str] | None = None) -> Args: action="store_true", ) args = parser.parse_args(argv, Args()) - if (match := VERSION.fullmatch(args.version)) is None: - msg = f"Version argument {args.version} is not a valid version." - raise ValueError(msg) - if len(match["release"].split(".")) < 3: + # validate the version + if len(Version(args.version).release) != 3: msg = f"Version argument {args.version} must contain major, minor, and patch version." raise ValueError(msg) return args