Optional GITHASH directive for version_pattern

Optionally add GIT hash to your version number.
This commit is contained in:
Michał Pasternak 2022-04-19 13:26:27 +02:00 committed by mbarkhau
parent e96904438b
commit da44922261
5 changed files with 34 additions and 0 deletions

View file

@ -82,6 +82,7 @@ PART_PATTERNS = {
'BLD' : r"[1-9][0-9]*",
'TAG' : r"preview|final|alpha|beta|post|rc",
'PYTAG': r"post|rc|a|b",
'GITHASH' : r"\.[0-9]+\+.*",
'NUM' : r"[0-9]+",
'INC0' : r"[0-9]+",
'INC1' : r"[1-9][0-9]*",
@ -109,6 +110,7 @@ PATTERN_PART_FIELDS = {
'BLD' : 'bid',
'TAG' : 'tag',
'PYTAG': 'pytag',
'GITHASH' : 'githash',
'NUM' : 'num',
'INC0' : 'inc0',
'INC1' : 'inc1',
@ -208,6 +210,7 @@ PART_FORMATS: typ.Dict[str, FormatterFunc] = {
'BLD' : _fmt_bld,
'TAG' : _fmt_num,
'PYTAG': _fmt_num,
'GITHASH' : _fmt_num,
'NUM' : _fmt_num,
'INC0' : _fmt_num,
'INC1' : _fmt_num,

View file

@ -223,6 +223,7 @@ def parse_field_values_to_vinfo(field_values: FieldValues) -> version.V2VersionI
tag = fvals.get('tag' ) or ""
pytag = fvals.get('pytag') or ""
githash = fvals.get('githash') or ""
if tag and not pytag:
pytag = version.PEP440_TAG_BY_TAG[tag]
@ -257,6 +258,7 @@ def parse_field_values_to_vinfo(field_values: FieldValues) -> version.V2VersionI
bid=bid,
tag=tag,
pytag=pytag,
githash=githash,
num=num,
inc0=inc0,
inc1=inc1,

View file

@ -77,6 +77,7 @@ class V2VersionInfo(typ.NamedTuple):
bid : str
tag : str
pytag : str
githash : str
num : int
inc0 : int
inc1 : int