add build_no and release_tag placeholders

This commit is contained in:
Manuel Barkhau 2018-12-22 00:15:01 +01:00
parent b835a5912f
commit fe019fa546
3 changed files with 46 additions and 32 deletions

View file

@ -41,7 +41,9 @@ RE_PATTERN_PARTS = {
'version' : r"v\d{6}\.\d{4,}(\-(alpha|beta|dev|rc|post))?", 'version' : r"v\d{6}\.\d{4,}(\-(alpha|beta|dev|rc|post))?",
'calver' : r"v\d{6}", 'calver' : r"v\d{6}",
'build' : r"\.\d{4,}", 'build' : r"\.\d{4,}",
'build_no' : r"\d{4,}",
'release' : r"(\-(alpha|beta|dev|rc|post))?", 'release' : r"(\-(alpha|beta|dev|rc|post))?",
'release_tag' : r"(alpha|beta|dev|rc|post)?",
} }

View file

@ -7,22 +7,26 @@
>>> version_info = PYCALVER_RE.match("v201712.0123-alpha").groupdict() >>> version_info = PYCALVER_RE.match("v201712.0123-alpha").groupdict()
>>> assert version_info == { >>> assert version_info == {
... "version" : "v201712.0123-alpha", ... "version" : "v201712.0123-alpha",
... "calver" : "v201712", ... "calver" : "v201712",
... "year" : "2017", ... "year" : "2017",
... "month" : "12", ... "month" : "12",
... "build" : ".0123", ... "build" : ".0123",
... "release" : "-alpha", ... "build_no" : "0123",
... "release" : "-alpha",
... "release_tag" : "alpha",
... } ... }
>>> >>>
>>> version_info = PYCALVER_RE.match("v201712.0033").groupdict() >>> version_info = PYCALVER_RE.match("v201712.0033").groupdict()
>>> assert version_info == { >>> assert version_info == {
... "version" : "v201712.0033", ... "version" : "v201712.0033",
... "calver" : "v201712", ... "calver" : "v201712",
... "year" : "2017", ... "year" : "2017",
... "month" : "12", ... "month" : "12",
... "build" : ".0033", ... "build" : ".0033",
... "release" : None, ... "build_no" : "0033",
... "release" : None,
... "release_tag": None,
... } ... }
""" """
@ -48,11 +52,11 @@ PYCALVER_PATTERN = r"""
) )
(?P<build> (?P<build>
\. # "." build nr prefix \. # "." build nr prefix
\d{4,} (?P<build_no>\d{4,})
) )
(?P<release> (?P<release>
\- # "-" release prefix \- # "-" release prefix
(?:alpha|beta|dev|rc|post) (?P<release_tag>alpha|beta|dev|rc|post)
)? )?
)(?:\s|$) )(?:\s|$)
""" """
@ -69,7 +73,9 @@ class VersionInfo(typ.NamedTuple):
year : str year : str
month : str month : str
build : str build : str
build_no : str
release : typ.Optional[str] release : typ.Optional[str]
release_tag : typ.Optional[str]
def parse_version_info(version_str: str) -> VersionInfo: def parse_version_info(version_str: str) -> VersionInfo:
@ -77,13 +83,15 @@ def parse_version_info(version_str: str) -> VersionInfo:
>>> vnfo = parse_version_info("v201712.0033-beta") >>> vnfo = parse_version_info("v201712.0033-beta")
>>> assert vnfo == VersionInfo( >>> assert vnfo == VersionInfo(
... version="v201712.0033-beta", ... version ="v201712.0033-beta",
... pep440_version="201712.33b0", ... pep440_version="201712.33b0",
... calver="v201712", ... calver ="v201712",
... year="2017", ... year ="2017",
... month="12", ... month ="12",
... build=".0033", ... build =".0033",
... release="-beta", ... build_no ="0033",
... release ="-beta",
... release_tag ="beta",
... ) ... )
""" """
match = PYCALVER_RE.match(version_str) match = PYCALVER_RE.match(version_str)

View file

@ -83,12 +83,14 @@ def test_readme_pycalver1():
version_info = version.PYCALVER_RE.match(version_str).groupdict() version_info = version.PYCALVER_RE.match(version_str).groupdict()
assert version_info == { assert version_info == {
'version': "v201712.0001-alpha", 'version' : "v201712.0001-alpha",
'calver' : "v201712", 'calver' : "v201712",
'year' : "2017", 'year' : "2017",
'month' : "12", 'month' : "12",
'build' : ".0001", 'build' : ".0001",
'release': "-alpha", 'build_no' : "0001",
'release' : "-alpha",
'release_tag': "alpha",
} }
@ -97,12 +99,14 @@ def test_readme_pycalver2():
version_info = version.PYCALVER_RE.match(version_str).groupdict() version_info = version.PYCALVER_RE.match(version_str).groupdict()
assert version_info == { assert version_info == {
'version': "v201712.0033", 'version' : "v201712.0033",
'calver' : "v201712", 'calver' : "v201712",
'year' : "2017", 'year' : "2017",
'month' : "12", 'month' : "12",
'build' : ".0033", 'build' : ".0033",
'release': None, 'build_no' : "0033",
'release' : None,
'release_tag': None,
} }