mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
formatting for new style versions
This commit is contained in:
parent
f21c0f1d0f
commit
b07edc9c8a
12 changed files with 288 additions and 261 deletions
|
|
@ -97,7 +97,7 @@ def _parse_field_values(field_values: FieldValues) -> version.V1VersionInfo:
|
|||
tag = fvals.get('tag')
|
||||
if tag is None:
|
||||
tag = "final"
|
||||
tag = version.TAG_BY_PEP440_TAG.get(tag, tag)
|
||||
tag = version.RELEASE_BY_PEP440_TAG.get(tag, tag)
|
||||
assert tag is not None
|
||||
|
||||
bid = fvals['bid'] if 'bid' in fvals else "0001"
|
||||
|
|
@ -338,15 +338,15 @@ def format_version(vinfo: version.V1VersionInfo, raw_pattern: str) -> str:
|
|||
|
||||
kwargs: typ.Dict[str, typ.Union[str, int, None]] = vinfo._asdict()
|
||||
|
||||
tag = vinfo.tag
|
||||
if tag == 'final':
|
||||
release_tag = vinfo.tag
|
||||
if release_tag == 'final':
|
||||
kwargs['release' ] = ""
|
||||
kwargs['pep440_tag'] = ""
|
||||
else:
|
||||
kwargs['release' ] = "-" + tag
|
||||
kwargs['pep440_tag'] = version.PEP440_TAG_BY_TAG[tag] + "0"
|
||||
kwargs['release' ] = "-" + release_tag
|
||||
kwargs['pep440_tag'] = version.PEP440_TAG_BY_RELEASE[release_tag] + "0"
|
||||
|
||||
kwargs['release_tag'] = tag
|
||||
kwargs['release_tag'] = release_tag
|
||||
|
||||
year = vinfo.year
|
||||
if year:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
"""Compose Regular Expressions from Patterns.
|
||||
|
||||
>>> pattern = compile_pattern("vYYYY0M.BUILD[-TAG]")
|
||||
>>> pattern = compile_pattern("vYYYY0M.BUILD[-RELEASE]")
|
||||
>>> version_info = pattern.regexp.match("v201712.0123-alpha")
|
||||
>>> assert version_info.groupdict() == {
|
||||
... "version": "v201712.0123-alpha",
|
||||
|
|
@ -80,45 +80,57 @@ PART_PATTERNS = {
|
|||
'VV': r"(?:5[0-3]|[1-4][0-9]|[1-9])",
|
||||
'0V': r"(?:5[0-3]|[1-4][0-9]|0[1-9])",
|
||||
# non calver parts
|
||||
'MAJOR': r"[0-9]+",
|
||||
'MINOR': r"[0-9]+",
|
||||
'PATCH': r"[0-9]+",
|
||||
'BUILD': r"[0-9]+",
|
||||
'BLD' : r"[1-9][0-9]*",
|
||||
'TAG' : r"(?:preview|final|alpha|beta|post|pre|dev|rc|a|b|c|r)",
|
||||
'PYTAG': r"(?:post|dev|rc|a|b)",
|
||||
'NUM' : r"[0-9]+",
|
||||
'MAJOR' : r"[0-9]+",
|
||||
'MINOR' : r"[0-9]+",
|
||||
'PATCH' : r"[0-9]+",
|
||||
'BUILD' : r"[0-9]+",
|
||||
'BLD' : r"[1-9][0-9]*",
|
||||
'RELEASE': r"(?:preview|final|alpha|beta|post|pre|dev|rc|a|b|c|r)",
|
||||
'PYTAG' : r"(?:post|dev|rc|a|b)",
|
||||
'NUM' : r"[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',
|
||||
'BUILD': 'bid',
|
||||
'BLD' : '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',
|
||||
'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',
|
||||
'BUILD' : 'bid',
|
||||
'BLD' : 'bid',
|
||||
'RELEASE': 'tag',
|
||||
'PYTAG' : 'pytag',
|
||||
'NUM' : 'num',
|
||||
'WW' : 'week_w',
|
||||
'0W' : 'week_w',
|
||||
'UU' : 'week_u',
|
||||
'0U' : 'week_u',
|
||||
'VV' : 'week_v',
|
||||
'0V' : 'week_v',
|
||||
}
|
||||
|
||||
|
||||
PEP440_PART_SUBSTITUTIONS = {
|
||||
'0W' : "WW",
|
||||
'0U' : "UU",
|
||||
'0V' : "VV",
|
||||
'0M' : "MM",
|
||||
'0D' : "DD",
|
||||
'00J' : "JJJ",
|
||||
'BUILD' : "BLD",
|
||||
'RELEASE': "PYTAG",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -174,33 +186,33 @@ def _fmt_0v(week_v: FieldValue) -> str:
|
|||
|
||||
|
||||
PART_FORMATS: typ.Dict[str, typ.Callable[[FieldValue], str]] = {
|
||||
'YYYY' : _fmt_num,
|
||||
'YY' : _fmt_yy,
|
||||
'0Y' : _fmt_0y,
|
||||
'GGGG' : _fmt_num,
|
||||
'GG' : _fmt_gg,
|
||||
'0G' : _fmt_0g,
|
||||
'Q' : _fmt_num,
|
||||
'MM' : _fmt_num,
|
||||
'0M' : _fmt_0m,
|
||||
'DD' : _fmt_num,
|
||||
'0D' : _fmt_0d,
|
||||
'JJJ' : _fmt_num,
|
||||
'00J' : _fmt_00j,
|
||||
'MAJOR': _fmt_num,
|
||||
'MINOR': _fmt_num,
|
||||
'PATCH': _fmt_num,
|
||||
'BUILD': _fmt_num,
|
||||
'BLD' : _fmt_bld,
|
||||
'TAG' : _fmt_num,
|
||||
'PYTAG': _fmt_num,
|
||||
'NUM' : _fmt_num,
|
||||
'WW' : _fmt_num,
|
||||
'0W' : _fmt_0w,
|
||||
'UU' : _fmt_num,
|
||||
'0U' : _fmt_0u,
|
||||
'VV' : _fmt_num,
|
||||
'0V' : _fmt_0v,
|
||||
'YYYY' : _fmt_num,
|
||||
'YY' : _fmt_yy,
|
||||
'0Y' : _fmt_0y,
|
||||
'GGGG' : _fmt_num,
|
||||
'GG' : _fmt_gg,
|
||||
'0G' : _fmt_0g,
|
||||
'Q' : _fmt_num,
|
||||
'MM' : _fmt_num,
|
||||
'0M' : _fmt_0m,
|
||||
'DD' : _fmt_num,
|
||||
'0D' : _fmt_0d,
|
||||
'JJJ' : _fmt_num,
|
||||
'00J' : _fmt_00j,
|
||||
'MAJOR' : _fmt_num,
|
||||
'MINOR' : _fmt_num,
|
||||
'PATCH' : _fmt_num,
|
||||
'BUILD' : _fmt_num,
|
||||
'BLD' : _fmt_bld,
|
||||
'RELEASE': _fmt_num,
|
||||
'PYTAG' : _fmt_num,
|
||||
'NUM' : _fmt_num,
|
||||
'WW' : _fmt_num,
|
||||
'0W' : _fmt_0w,
|
||||
'UU' : _fmt_num,
|
||||
'0U' : _fmt_0u,
|
||||
'VV' : _fmt_num,
|
||||
'0V' : _fmt_0v,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -209,15 +221,37 @@ def _convert_to_pep440(version_pattern: str) -> str:
|
|||
# corner cases as specified in PEP440, in particular
|
||||
# related to post and dev releases.
|
||||
|
||||
version_pattern = version_pattern.lstrip("v")
|
||||
pep440_pattern = version_pattern
|
||||
|
||||
if pep440_pattern.startswith("v"):
|
||||
pep440_pattern = pep440_pattern[1:]
|
||||
|
||||
pep440_pattern = pep440_pattern.replace(r"\[", "")
|
||||
pep440_pattern = pep440_pattern.replace(r"\]", "")
|
||||
|
||||
pep440_pattern, _ = re.subn(r"[^a-zA-Z0-9\.\[\]]", "", pep440_pattern)
|
||||
|
||||
part_names = list(PATTERN_PART_FIELDS.keys())
|
||||
part_names.sort(key=len, reverse=True)
|
||||
if version_pattern == "vYYYY0M.BUILD[-TAG]":
|
||||
return "YYYY0M.BLD[PYTAGNUM]"
|
||||
|
||||
# TODO (mb 2020-09-20)
|
||||
raise NotImplementedError
|
||||
for part_name in part_names:
|
||||
if part_name not in version_pattern:
|
||||
continue
|
||||
if part_name not in PEP440_PART_SUBSTITUTIONS:
|
||||
continue
|
||||
|
||||
substitution = PEP440_PART_SUBSTITUTIONS[part_name]
|
||||
|
||||
is_numerical_part = part_name not in ('RELEASE', 'PYTAG')
|
||||
if is_numerical_part:
|
||||
part_index = pep440_pattern.find(part_name)
|
||||
is_zero_truncation_part = part_index == 0 or pep440_pattern[part_index - 1] == "."
|
||||
if is_zero_truncation_part:
|
||||
pep440_pattern = pep440_pattern.replace(part_name, substitution)
|
||||
else:
|
||||
pep440_pattern = pep440_pattern.replace(part_name, substitution)
|
||||
|
||||
return pep440_pattern
|
||||
|
||||
|
||||
def normalize_pattern(version_pattern: str, raw_pattern: str) -> str:
|
||||
|
|
@ -236,10 +270,10 @@ def _replace_pattern_parts(pattern: str) -> str:
|
|||
# The pattern is escaped, so that everything besides the format
|
||||
# string variables is treated literally.
|
||||
while True:
|
||||
new_pattern, n = re.subn(r"([^\\]|^)\[", r"\1(?:", pattern)
|
||||
new_pattern, m = re.subn(r"([^\\]|^)\]", r"\1)?" , new_pattern)
|
||||
new_pattern, _n = re.subn(r"([^\\]|^)\[", r"\1(?:", pattern)
|
||||
new_pattern, _m = re.subn(r"([^\\]|^)\]", r"\1)?" , new_pattern)
|
||||
pattern = new_pattern
|
||||
if n + m == 0:
|
||||
if _n + _m == 0:
|
||||
break
|
||||
|
||||
SortKey = typ.Tuple[int, int]
|
||||
|
|
@ -274,7 +308,7 @@ def _compile_pattern_re(version_pattern: str, raw_pattern: str) -> typ.Pattern[s
|
|||
normalized_pattern = normalize_pattern(version_pattern, raw_pattern)
|
||||
escaped_pattern = normalized_pattern
|
||||
for char, escaped in RE_PATTERN_ESCAPES:
|
||||
# [] braces are used for optional parts, such as [-TAG]/[-beta]
|
||||
# [] braces are used for optional parts, such as [-RELEASE]/[-beta]
|
||||
# and need to be escaped manually.
|
||||
is_semantic_char = char in "[]\\"
|
||||
if not is_semantic_char:
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ def rewrite_lines(
|
|||
"""Replace occurances of patterns in old_lines with new_vinfo.
|
||||
|
||||
>>> from .v2patterns import compile_pattern
|
||||
>>> version_pattern = "vYYYY0M.BUILD[-TAG]"
|
||||
>>> version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||
>>> new_vinfo = v2version.parse_version_info("v201811.0123-beta", version_pattern)
|
||||
>>> patterns = [compile_pattern(version_pattern, '__version__ = "{version}"')]
|
||||
>>> rewrite_lines(patterns, new_vinfo, ['__version__ = "v201809.0002-alpha" '])
|
||||
|
|
@ -73,9 +73,9 @@ def rfd_from_content(
|
|||
) -> rewrite.RewrittenFileData:
|
||||
r"""Rewrite pattern occurrences with version string.
|
||||
|
||||
>>> version_pattern = "vYYYY0M.BUILD[-TAG]"
|
||||
>>> version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||
>>> new_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
||||
>>> raw_patterns = ['__version__ = "vYYYY0M.BUILD[-TAG]"']
|
||||
>>> raw_patterns = ['__version__ = "vYYYY0M.BUILD[-RELEASE]"']
|
||||
>>> patterns =
|
||||
>>> content = '__version__ = "v201809.0001-alpha"'
|
||||
>>> rfd = rfd_from_content(patterns, new_vinfo, content)
|
||||
|
|
@ -115,8 +115,8 @@ def iter_rewritten(
|
|||
) -> typ.Iterable[rewrite.RewrittenFileData]:
|
||||
r'''Iterate over files with version string replaced.
|
||||
|
||||
>>> version_pattern = "vYYYY0M.BUILD[-TAG]"
|
||||
>>> file_patterns = {"src/pycalver/__init__.py": ['__version__ = "vYYYY0M.BUILD[-TAG]"']}
|
||||
>>> version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||
>>> file_patterns = {"src/pycalver/__init__.py": ['__version__ = "vYYYY0M.BUILD[-RELEASE]"']}
|
||||
>>> new_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
||||
>>> rewritten_datas = iter_rewritten(file_patterns, new_vinfo)
|
||||
>>> rfd = list(rewritten_datas)[0]
|
||||
|
|
@ -153,7 +153,7 @@ def diff(
|
|||
|
||||
>>> old_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
||||
>>> new_vinfo = v2version.parse_version_info("v201810.1124", version_pattern)
|
||||
>>> file_patterns = {"src/pycalver/__init__.py": ['__version__ = "vYYYY0M.BUILD[-TAG]"']}
|
||||
>>> file_patterns = {"src/pycalver/__init__.py": ['__version__ = "vYYYY0M.BUILD[-RELEASE]"']}
|
||||
>>> diff_str = diff(old_vinfo, new_vinfo, file_patterns)
|
||||
>>> lines = diff_str.split("\n")
|
||||
>>> lines[:2]
|
||||
|
|
|
|||
|
|
@ -149,9 +149,9 @@ def _parse_version_info(field_values: FieldValues) -> version.V2VersionInfo:
|
|||
pytag = fvals.get('pytag') or ""
|
||||
|
||||
if tag and not pytag:
|
||||
pytag = version.PEP440_TAG_BY_TAG[tag]
|
||||
pytag = version.PEP440_TAG_BY_RELEASE[tag]
|
||||
elif pytag and not tag:
|
||||
tag = version.TAG_BY_PEP440_TAG[pytag]
|
||||
tag = version.RELEASE_BY_PEP440_TAG[pytag]
|
||||
|
||||
date: typ.Optional[dt.date] = None
|
||||
|
||||
|
|
@ -221,19 +221,19 @@ def _parse_version_info(field_values: FieldValues) -> version.V2VersionInfo:
|
|||
|
||||
|
||||
def parse_version_info(
|
||||
version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-TAG[NUM]]"
|
||||
version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-RELEASE[NUM]]"
|
||||
) -> version.V2VersionInfo:
|
||||
"""Parse normalized V2VersionInfo.
|
||||
|
||||
>>> vinfo = parse_version_info("v201712.0033-beta0", raw_pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
||||
>>> vinfo = parse_version_info("v201712.0033-beta0", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||
>>> fvals = {'year_y': 2017, 'month': 12, 'bid': "0033", 'tag': "beta", 'num': 0}
|
||||
>>> assert vinfo == _parse_version_info(fvals)
|
||||
|
||||
>>> vinfo = parse_version_info("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
||||
>>> vinfo = parse_version_info("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||
>>> fvals = {'year_y': 2017, 'month': 12, 'bid': "0033", 'tag': "beta"}
|
||||
>>> assert vinfo == _parse_version_info(fvals)
|
||||
|
||||
>>> vinfo = parse_version_info("v201712.0033", raw_pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
||||
>>> vinfo = parse_version_info("v201712.0033", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||
>>> fvals = {'year_y': 2017, 'month': 12, 'bid': "0033"}
|
||||
>>> assert vinfo == _parse_version_info(fvals)
|
||||
|
||||
|
|
@ -254,10 +254,10 @@ def parse_version_info(
|
|||
return _parse_version_info(field_values)
|
||||
|
||||
|
||||
def is_valid(version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-TAG]") -> bool:
|
||||
def is_valid(version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-RELEASE[NUM]]") -> bool:
|
||||
"""Check if a version matches a pattern.
|
||||
|
||||
>>> is_valid("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-TAG]")
|
||||
>>> is_valid("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||
True
|
||||
>>> is_valid("v201712.0033-beta", raw_pattern="MAJOR.MINOR.PATCH")
|
||||
False
|
||||
|
|
@ -274,7 +274,7 @@ def is_valid(version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-TAG]") -> bool
|
|||
|
||||
|
||||
TemplateKwargs = typ.Dict[str, typ.Union[str, int, None]]
|
||||
PartValues = typ.List[typ.Tuple[str, str]]
|
||||
PartValues = typ.List[typ.Tuple[str, str]]
|
||||
|
||||
|
||||
def _format_part_values(vinfo: version.V2VersionInfo) -> PartValues:
|
||||
|
|
@ -285,9 +285,9 @@ def _format_part_values(vinfo: version.V2VersionInfo) -> PartValues:
|
|||
It may for example have month=9, but not the formatted
|
||||
representation '09' for '0M'.
|
||||
|
||||
>>> vinfo = parse_version_info("v200709.1033-beta", pattern="vYYYY0M.BUILD[-TAG]")
|
||||
>>> vinfo = parse_version_info("v200709.1033-beta", pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||
>>> kwargs = dict(_format_part_values(vinfo))
|
||||
>>> (kwargs['YYYY'], kwargs['0M'], kwargs['BUILD'], kwargs['TAG'])
|
||||
>>> (kwargs['YYYY'], kwargs['0M'], kwargs['BUILD'], kwargs['RELEASE[NUM]'])
|
||||
('2007', '09', '1033', 'beta')
|
||||
>>> (kwargs['YY'], kwargs['0Y'], kwargs['MM'], kwargs['PYTAG'])
|
||||
('7', '07', '9', 'b')
|
||||
|
|
@ -381,8 +381,8 @@ FormattedSegmentParts = typ.List[str]
|
|||
|
||||
|
||||
def _format_segment_tree(
|
||||
seg_tree: SegmentTree,
|
||||
part_values : PartValues,
|
||||
seg_tree : SegmentTree,
|
||||
part_values: PartValues,
|
||||
) -> FormattedSegmentParts:
|
||||
result_parts = []
|
||||
for seg in seg_tree:
|
||||
|
|
@ -391,7 +391,7 @@ def _format_segment_tree(
|
|||
else:
|
||||
# NOTE (mb 2020-09-24): If a segment has any zero parts,
|
||||
# the whole segment is skipped.
|
||||
is_zero_seg = False
|
||||
is_zero_seg = False
|
||||
formatted_seg = seg
|
||||
# unescape braces
|
||||
formatted_seg = formatted_seg.replace(r"\[", r"[")
|
||||
|
|
@ -400,8 +400,7 @@ def _format_segment_tree(
|
|||
for part, part_value in part_values:
|
||||
if part in formatted_seg:
|
||||
is_zero_part = (
|
||||
part in version.ZERO_VALUES
|
||||
and str(part_value) == version.ZERO_VALUES[part]
|
||||
part in version.ZERO_VALUES and str(part_value) == version.ZERO_VALUES[part]
|
||||
)
|
||||
if is_zero_part:
|
||||
is_zero_seg = True
|
||||
|
|
@ -418,7 +417,7 @@ def format_version(vinfo: version.V2VersionInfo, raw_pattern: str) -> str:
|
|||
"""Generate version string.
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> vinfo = parse_version_info("v200712.0033-beta", pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
||||
>>> vinfo = parse_version_info("v200712.0033-beta", pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||
>>> vinfo_a = vinfo._replace(**cal_info(date=dt.date(2007, 1, 1))._asdict())
|
||||
>>> vinfo_b = vinfo._replace(**cal_info(date=dt.date(2007, 12, 31))._asdict())
|
||||
|
||||
|
|
@ -429,86 +428,86 @@ def format_version(vinfo: version.V2VersionInfo, raw_pattern: str) -> str:
|
|||
'200701.0033b'
|
||||
>>> format_version(vinfo_a, pattern="vYY.BLD[-PYTAGNUM]")
|
||||
'v7.33-b0'
|
||||
>>> format_version(vinfo_a, pattern="v0Y.BLD[-TAG]")
|
||||
>>> format_version(vinfo_a, pattern="v0Y.BLD[-RELEASE[NUM]]")
|
||||
'v07.33-beta'
|
||||
|
||||
>>> format_version(vinfo_a, pattern="vYYYY0M.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_a, pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||
'v200701.0033-beta'
|
||||
>>> format_version(vinfo_b, pattern="vYYYY0M.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_b, pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
||||
'v200712.0033-beta'
|
||||
|
||||
>>> format_version(vinfo_a, pattern="vYYYYw0W.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_a, pattern="vYYYYw0W.BUILD[-RELEASE[NUM]]")
|
||||
'v2007w01.0033-beta'
|
||||
>>> format_version(vinfo_a, pattern="vYYYYwWW.BLD[-TAG]")
|
||||
>>> format_version(vinfo_a, pattern="vYYYYwWW.BLD[-RELEASE[NUM]]")
|
||||
'v2007w1.33-beta'
|
||||
>>> format_version(vinfo_b, pattern="vYYYYw0W.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_b, pattern="vYYYYw0W.BUILD[-RELEASE[NUM]]")
|
||||
'v2007w53.0033-beta'
|
||||
|
||||
>>> format_version(vinfo_a, pattern="vYYYYd00J.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_a, pattern="vYYYYd00J.BUILD[-RELEASE[NUM]]")
|
||||
'v2007d001.0033-beta'
|
||||
>>> format_version(vinfo_a, pattern="vYYYYdJJJ.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_a, pattern="vYYYYdJJJ.BUILD[-RELEASE[NUM]]")
|
||||
'v2007d1.0033-beta'
|
||||
>>> format_version(vinfo_b, pattern="vYYYYd00J.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_b, pattern="vYYYYd00J.BUILD[-RELEASE[NUM]]")
|
||||
'v2007d365.0033-beta'
|
||||
|
||||
>>> format_version(vinfo_a, pattern="vGGGGwVV.BLD[PYTAGNUM]")
|
||||
'v2007w1.33b0'
|
||||
>>> format_version(vinfo_a, pattern="vGGGGw0V.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_a, pattern="vGGGGw0V.BUILD[-RELEASE[NUM]]")
|
||||
'v2007w01.0033-beta'
|
||||
>>> format_version(vinfo_b, pattern="vGGGGw0V.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_b, pattern="vGGGGw0V.BUILD[-RELEASE[NUM]]")
|
||||
'v2008w01.0033-beta'
|
||||
|
||||
>>> vinfo_c = vinfo_b._replace(major=1, minor=2, patch=34, tag='final')
|
||||
|
||||
>>> format_version(vinfo_c, pattern="vYYYYwWW.BUILD-TAG")
|
||||
>>> format_version(vinfo_c, pattern="vYYYYwWW.BUILD-RELEASE")
|
||||
'v2007w53.0033-final'
|
||||
>>> format_version(vinfo_c, pattern="vYYYYwWW.BUILD[-TAG]")
|
||||
>>> format_version(vinfo_c, pattern="vYYYYwWW.BUILD[-RELEASE[NUM]]")
|
||||
'v2007w53.0033'
|
||||
|
||||
>>> format_version(vinfo_c, pattern="vMAJOR.MINOR.PATCH")
|
||||
'v1.2.34'
|
||||
|
||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='final')
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-TAGNUM")
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-RELEASENUM")
|
||||
'v1.0.0-final0'
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-TAG[NUM]")
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-RELEASE[NUM]")
|
||||
'v1.0.0-final'
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-TAG")
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH-RELEASE")
|
||||
'v1.0.0-final'
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH[-TAG]")
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR.PATCH[-RELEASE[NUM]]")
|
||||
'v1.0.0'
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR[.PATCH[-TAG]]")
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR.MINOR[.PATCH[-RELEASE[NUM]]]")
|
||||
'v1.0'
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-TAG]]]")
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]")
|
||||
'v1'
|
||||
|
||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=1, tag='rc', num=0)
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH]]")
|
||||
'v1.0.1'
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-TAG[NUM]]]]")
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]")
|
||||
'v1.0.1-rc'
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-TAGNUM]]]")
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-RELEASENUM]]]")
|
||||
'v1.0.1-rc0'
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH]]")
|
||||
'v1.0.1'
|
||||
|
||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-TAG[NUM]]]]")
|
||||
>>> format_version(vinfo_d, pattern="vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]")
|
||||
'v1.0.0-rc2'
|
||||
|
||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
||||
>>> format_version(vinfo_d, pattern='__version__ = "vMAJOR[.MINOR[.PATCH[-TAG[NUM]]]]"')
|
||||
>>> format_version(vinfo_d, pattern='__version__ = "vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]"')
|
||||
'__version__ = "v1.0.0-rc2"'
|
||||
"""
|
||||
part_values = _format_part_values(vinfo)
|
||||
seg_tree = _parse_segment_tree(raw_pattern)
|
||||
part_values = _format_part_values(vinfo)
|
||||
seg_tree = _parse_segment_tree(raw_pattern)
|
||||
version_str_parts = _format_segment_tree(seg_tree, part_values)
|
||||
return "".join(version_str_parts)
|
||||
|
||||
|
||||
def incr(
|
||||
old_version: str,
|
||||
raw_pattern: str = "vYYYY0M.BUILD[-TAG]",
|
||||
raw_pattern: str = "vYYYY0M.BUILD[-RELEASE]",
|
||||
*,
|
||||
release : typ.Optional[str] = None,
|
||||
major : bool = False,
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class V2VersionInfo(typ.NamedTuple):
|
|||
TODAY = dt.datetime.utcnow().date()
|
||||
|
||||
|
||||
TAG_BY_PEP440_TAG = {
|
||||
RELEASE_BY_PEP440_TAG = {
|
||||
'a' : 'alpha',
|
||||
'b' : 'beta',
|
||||
'' : 'final',
|
||||
|
|
@ -89,7 +89,7 @@ TAG_BY_PEP440_TAG = {
|
|||
}
|
||||
|
||||
|
||||
PEP440_TAG_BY_TAG = {
|
||||
PEP440_TAG_BY_RELEASE = {
|
||||
'a' : 'a',
|
||||
'b' : 'b',
|
||||
'dev' : 'dev',
|
||||
|
|
@ -105,17 +105,17 @@ PEP440_TAG_BY_TAG = {
|
|||
'rev' : 'post',
|
||||
}
|
||||
|
||||
assert set(TAG_BY_PEP440_TAG.keys()) == set(PEP440_TAG_BY_TAG.values())
|
||||
assert set(TAG_BY_PEP440_TAG.values()) < set(PEP440_TAG_BY_TAG.keys())
|
||||
assert set(RELEASE_BY_PEP440_TAG.keys()) == set(PEP440_TAG_BY_RELEASE.values())
|
||||
assert set(RELEASE_BY_PEP440_TAG.values()) < set(PEP440_TAG_BY_RELEASE.keys())
|
||||
|
||||
|
||||
ZERO_VALUES = {
|
||||
'MAJOR': "0",
|
||||
'MINOR': "0",
|
||||
'PATCH': "0",
|
||||
'TAG' : "final",
|
||||
'PYTAG': "",
|
||||
'NUM' : "0",
|
||||
'MAJOR' : "0",
|
||||
'MINOR' : "0",
|
||||
'PATCH' : "0",
|
||||
'RELEASE': "final",
|
||||
'PYTAG' : "",
|
||||
'NUM' : "0",
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue