mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 06:20:08 +01:00
move PATTERN_PART_FIELDS version -> patterns
This commit is contained in:
parent
fbc92b109b
commit
d4bd8a5931
6 changed files with 86 additions and 83 deletions
|
|
@ -122,6 +122,44 @@ PART_PATTERNS = {
|
|||
}
|
||||
|
||||
|
||||
PATTERN_PART_FIELDS = {
|
||||
'year' : 'year',
|
||||
'month' : 'month',
|
||||
'month_short': 'month',
|
||||
'pep440_tag' : 'tag',
|
||||
'tag' : 'tag',
|
||||
'yy' : 'year',
|
||||
'yyyy' : 'year',
|
||||
'quarter' : 'quarter',
|
||||
'iso_week' : 'iso_week',
|
||||
'us_week' : 'us_week',
|
||||
'dom' : 'dom',
|
||||
'doy' : 'doy',
|
||||
'dom_short' : 'dom',
|
||||
'doy_short' : 'doy',
|
||||
'MAJOR' : 'major',
|
||||
'MINOR' : 'minor',
|
||||
'MM' : 'minor',
|
||||
'MMM' : 'minor',
|
||||
'MMMM' : 'minor',
|
||||
'MMMMM' : 'minor',
|
||||
'PP' : 'patch',
|
||||
'PPP' : 'patch',
|
||||
'PPPP' : 'patch',
|
||||
'PPPPP' : 'patch',
|
||||
'PATCH' : 'patch',
|
||||
'build_no' : 'bid',
|
||||
'bid' : 'bid',
|
||||
'BID' : 'bid',
|
||||
'BB' : 'bid',
|
||||
'BBB' : 'bid',
|
||||
'BBBB' : 'bid',
|
||||
'BBBBB' : 'bid',
|
||||
'BBBBBB' : 'bid',
|
||||
'BBBBBBB' : 'bid',
|
||||
}
|
||||
|
||||
|
||||
FULL_PART_FORMATS = {
|
||||
'pep440_pycalver': "{year}{month:02}.{BID}{pep440_tag}",
|
||||
'pycalver' : "v{year}{month:02}.{bid}{release}",
|
||||
|
|
|
|||
|
|
@ -21,44 +21,6 @@ logger = logging.getLogger("pycalver.version")
|
|||
TODAY = dt.datetime.utcnow().date()
|
||||
|
||||
|
||||
PATTERN_PART_FIELDS = {
|
||||
'year' : 'year',
|
||||
'month' : 'month',
|
||||
'month_short': 'month',
|
||||
'pep440_tag' : 'tag',
|
||||
'tag' : 'tag',
|
||||
'yy' : 'year',
|
||||
'yyyy' : 'year',
|
||||
'quarter' : 'quarter',
|
||||
'iso_week' : 'iso_week',
|
||||
'us_week' : 'us_week',
|
||||
'dom' : 'dom',
|
||||
'doy' : 'doy',
|
||||
'dom_short' : 'dom',
|
||||
'doy_short' : 'doy',
|
||||
'MAJOR' : 'major',
|
||||
'MINOR' : 'minor',
|
||||
'MM' : 'minor',
|
||||
'MMM' : 'minor',
|
||||
'MMMM' : 'minor',
|
||||
'MMMMM' : 'minor',
|
||||
'PP' : 'patch',
|
||||
'PPP' : 'patch',
|
||||
'PPPP' : 'patch',
|
||||
'PPPPP' : 'patch',
|
||||
'PATCH' : 'patch',
|
||||
'build_no' : 'bid',
|
||||
'bid' : 'bid',
|
||||
'BID' : 'bid',
|
||||
'BB' : 'bid',
|
||||
'BBB' : 'bid',
|
||||
'BBBB' : 'bid',
|
||||
'BBBBB' : 'bid',
|
||||
'BBBBBB' : 'bid',
|
||||
'BBBBBBB' : 'bid',
|
||||
}
|
||||
|
||||
|
||||
class CalendarInfo(typ.NamedTuple):
|
||||
"""Container for calendar components of version strings."""
|
||||
|
||||
|
|
@ -263,7 +225,8 @@ class PatternError(Exception):
|
|||
def _parse_pattern_groups(pattern_groups: PatternGroups) -> FieldValues:
|
||||
for part_name in pattern_groups.keys():
|
||||
is_valid_part_name = (
|
||||
part_name in v1patterns.COMPOSITE_PART_PATTERNS or part_name in PATTERN_PART_FIELDS
|
||||
part_name in v1patterns.COMPOSITE_PART_PATTERNS
|
||||
or part_name in v1patterns.PATTERN_PART_FIELDS
|
||||
)
|
||||
if not is_valid_part_name:
|
||||
err_msg = f"Invalid part '{part_name}'"
|
||||
|
|
@ -271,7 +234,7 @@ def _parse_pattern_groups(pattern_groups: PatternGroups) -> FieldValues:
|
|||
|
||||
field_value_items = [
|
||||
(field_name, pattern_groups[part_name])
|
||||
for part_name, field_name in PATTERN_PART_FIELDS.items()
|
||||
for part_name, field_name in v1patterns.PATTERN_PART_FIELDS.items()
|
||||
if part_name in pattern_groups.keys()
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,36 @@ PART_PATTERNS = {
|
|||
'BUILD': r"[0-9]+",
|
||||
'TAG' : r"(?:alpha|beta|dev|rc|post|final)",
|
||||
'PYTAG': r"(?:a|b|dev|rc|post)?[0-9]*",
|
||||
|
||||
PATTERN_PART_FIELDS = {
|
||||
'YYYY' : 'year_y',
|
||||
'YY' : 'year_y',
|
||||
'0Y' : 'year_y',
|
||||
'GGGG' : 'year_g',
|
||||
'GG' : 'year_g',
|
||||
'0G' : 'year_g',
|
||||
'Q' : 'quarter',
|
||||
'MM' : 'month',
|
||||
'0M' : 'month',
|
||||
'DD' : 'dom',
|
||||
'0D' : 'dom',
|
||||
'JJJ' : 'doy',
|
||||
'00J' : 'doy',
|
||||
'MAJOR': 'major',
|
||||
'MINOR': 'minor',
|
||||
'PATCH': 'patch',
|
||||
'MICRO': 'patch',
|
||||
'BUILD': 'bid',
|
||||
'TAG' : 'tag',
|
||||
'PYTAG': 'pytag',
|
||||
'NUM' : 'num',
|
||||
'WW' : 'week_w',
|
||||
'0W' : 'week_w',
|
||||
'UU' : 'week_u',
|
||||
'0U' : 'week_u',
|
||||
'VV' : 'week_v',
|
||||
'0V' : 'week_v',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,35 +22,6 @@ logger = logging.getLogger("pycalver.version")
|
|||
TODAY = dt.datetime.utcnow().date()
|
||||
|
||||
|
||||
PATTERN_PART_FIELDS = {
|
||||
'YYYY' : 'year_y',
|
||||
'YY' : 'year_y',
|
||||
'0Y' : 'year_y',
|
||||
'Q' : 'quarter',
|
||||
'MM' : 'month',
|
||||
'0M' : 'month',
|
||||
'DD' : 'dom',
|
||||
'0D' : 'dom',
|
||||
'JJJ' : 'doy',
|
||||
'00J' : 'doy',
|
||||
'MAJOR': 'major',
|
||||
'MINOR': 'minor',
|
||||
'PATCH': 'patch',
|
||||
'MICRO': 'patch',
|
||||
'BUILD': 'bid',
|
||||
'TAG' : 'tag',
|
||||
'PYTAG': 'pytag',
|
||||
'WW' : 'week_w',
|
||||
'0W' : 'week_w',
|
||||
'UU' : 'week_u',
|
||||
'0U' : 'week_u',
|
||||
'VV' : 'week_v',
|
||||
'0V' : 'week_v',
|
||||
'GGGG' : 'year_g',
|
||||
'GG' : 'year_g',
|
||||
'0G' : 'year_g',
|
||||
}
|
||||
|
||||
ID_FIELDS_BY_PART = {
|
||||
'MAJOR': 'major',
|
||||
'MINOR': 'minor',
|
||||
|
|
|
|||
|
|
@ -236,3 +236,13 @@ def test_curly_escapes():
|
|||
match = pattern.regexp.search(CURLY_BRACE_FIXTURE)
|
||||
expected = 'package_metadata = {"name": "mypackage", "version": "v201812.0123-beta"}'
|
||||
assert match.group(0) == expected
|
||||
|
||||
|
||||
def test_part_field_mapping_v2():
|
||||
a_names = set(v2patterns.PATTERN_PART_FIELDS.keys())
|
||||
b_names = set(v2patterns.PART_PATTERNS.keys())
|
||||
|
||||
a_extra_names = a_names - b_names
|
||||
assert not any(a_extra_names), sorted(a_extra_names)
|
||||
b_extra_names = b_names - a_names
|
||||
assert not any(b_extra_names), sorted(b_extra_names)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ import datetime as dt
|
|||
import pytest
|
||||
|
||||
import pycalver.version as v1version
|
||||
import pycalver2.version as v2version
|
||||
import pycalver.patterns as v1patterns
|
||||
import pycalver2.patterns as v2patterns
|
||||
|
||||
# import pycalver2.version as v2version
|
||||
# import pycalver2.patterns as v2patterns
|
||||
|
||||
# pylint:disable=protected-access ; allowed for test code
|
||||
|
||||
|
|
@ -140,7 +141,7 @@ def test_parse_error_nopadding():
|
|||
|
||||
|
||||
def test_part_field_mapping_v1():
|
||||
a_names = set(v1version.PATTERN_PART_FIELDS.keys())
|
||||
a_names = set(v1patterns.PATTERN_PART_FIELDS.keys())
|
||||
b_names = set(v1patterns.PART_PATTERNS.keys())
|
||||
c_names = set(v1patterns.COMPOSITE_PART_PATTERNS.keys())
|
||||
|
||||
|
|
@ -149,7 +150,7 @@ def test_part_field_mapping_v1():
|
|||
b_extra_names = b_names - (a_names | c_names)
|
||||
assert not any(b_extra_names), sorted(b_extra_names)
|
||||
|
||||
a_fields = set(v1version.PATTERN_PART_FIELDS.values())
|
||||
a_fields = set(v1patterns.PATTERN_PART_FIELDS.values())
|
||||
b_fields = set(v1version.VersionInfo._fields)
|
||||
|
||||
a_extra_fields = a_fields - b_fields
|
||||
|
|
@ -158,16 +159,6 @@ def test_part_field_mapping_v1():
|
|||
assert not any(b_extra_fields), sorted(b_extra_fields)
|
||||
|
||||
|
||||
def test_part_field_mapping_v2():
|
||||
a_names = set(v2version.PATTERN_PART_FIELDS.keys())
|
||||
b_names = set(v2patterns.PART_PATTERNS.keys())
|
||||
|
||||
a_extra_names = a_names - b_names
|
||||
assert not any(a_extra_names), sorted(a_extra_names)
|
||||
b_extra_names = b_names - a_names
|
||||
assert not any(b_extra_names), sorted(b_extra_names)
|
||||
|
||||
|
||||
def vnfo(**field_values):
|
||||
return v1version._parse_field_values(field_values)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue