Skip to content

Commit

Permalink
simpler validation
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Sep 16, 2024
1 parent 4af2f68 commit 10dcfbb
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions ci/scripts/towncrier_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 10dcfbb

Please sign in to comment.