|
5 | 5 | from collections.abc import Iterable, Sequence |
6 | 6 | from dataclasses import dataclass, field |
7 | 7 | from functools import cached_property |
| 8 | +from itertools import chain |
8 | 9 | from string import Template |
9 | 10 | from typing import TYPE_CHECKING, NamedTuple |
10 | 11 |
|
@@ -88,18 +89,22 @@ class TagRules: |
88 | 89 | ignored_tag_formats: Sequence[str] = field(default_factory=list) |
89 | 90 | merge_prereleases: bool = False |
90 | 91 |
|
| 92 | + @property |
| 93 | + def tag_formats(self) -> Iterable[str]: |
| 94 | + return chain([self.tag_format], self.legacy_tag_formats) |
| 95 | + |
91 | 96 | @cached_property |
92 | 97 | def version_regexes(self) -> list[re.Pattern]: |
93 | 98 | """Regexes for all legit tag formats, current and legacy""" |
94 | | - tag_formats = [self.tag_format, *self.legacy_tag_formats] |
95 | | - regexes = (self._format_regex(p) for p in tag_formats) |
96 | | - return [re.compile(r) for r in regexes] |
| 99 | + return [re.compile(self._format_regex(f)) for f in self.tag_formats] |
97 | 100 |
|
98 | 101 | @cached_property |
99 | 102 | def ignored_regexes(self) -> list[re.Pattern]: |
100 | 103 | """Regexes for known but ignored tag formats""" |
101 | | - regexes = (self._format_regex(p, star=True) for p in self.ignored_tag_formats) |
102 | | - return [re.compile(r) for r in regexes] |
| 104 | + return [ |
| 105 | + re.compile(self._format_regex(f, star=True)) |
| 106 | + for f in self.ignored_tag_formats |
| 107 | + ] |
103 | 108 |
|
104 | 109 | def _format_regex(self, tag_pattern: str, star: bool = False) -> str: |
105 | 110 | """ |
@@ -240,10 +245,7 @@ def find_tag_for( |
240 | 245 | ) -> GitTag | None: |
241 | 246 | """Find the first matching tag for a given version.""" |
242 | 247 | version = self.scheme(version) if isinstance(version, str) else version |
243 | | - possible_tags = set( |
244 | | - self.normalize_tag(version, f) |
245 | | - for f in (self.tag_format, *self.legacy_tag_formats) |
246 | | - ) |
| 248 | + possible_tags = set(self.normalize_tag(version, f) for f in self.tag_formats) |
247 | 249 | candidates = [t for t in tags if t.name in possible_tags] |
248 | 250 | if len(candidates) > 1: |
249 | 251 | warnings.warn( |
|
0 commit comments