Skip to content

Commit

Permalink
Update _VersionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Jul 10, 2024
1 parent 11a6cf7 commit eedf9cf
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/hdf5plugin/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,26 @@

class _VersionInfo(NamedTuple):
"""Version information as a namedtuple"""

major: int
minor: int
micro: int
releaselevel: str = "final"
serial: int = 0

@staticmethod
def from_version(version: str) -> "_VersionInfo":
pattern = r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<micro>\d+)((?P<prerelease>a|b|rc)(?P<serial>\d+))?"
match = re.fullmatch(pattern, version, re.ASCII)
fields = {k: v for k, v in match.groupdict().items() if v is not None}
# Remove prerelease and convert it to releaselevel
prerelease = fields.pop("prerelease", None)
releaselevel = {"a": "alpha", "b": "beta", "rc": "candidate", None: "final"}[
prerelease
]
version_fields = {k: int(v) for k, v in fields.items()}

def _version_info(version: str) -> _VersionInfo:
pattern = r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<micro>\d+)((?P<prerelease>a|b|rc)(?P<serial>\d+))?"
match = re.fullmatch(pattern, version, re.ASCII)
fields = {k: v for k, v in match.groupdict().items() if v is not None}
# Remove prerelease and convert it to releaselevel
prerelease = fields.pop("prerelease", None)
releaselevel = {"a": "alpha", "b": "beta", "rc": "candidate", None: "final"}[prerelease]
version_fields = {k: int(v) for k, v in fields.items()}

return _VersionInfo(releaselevel=releaselevel, **version_fields)
return _VersionInfo(releaselevel=releaselevel, **version_fields)


version_info = _version_info(version)
version_info = _VersionInfo.from_version(version)

0 comments on commit eedf9cf

Please sign in to comment.