From e38c48d43c9426cb8ae58e145ff6e3d6c19589f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Mon, 8 May 2023 10:54:45 +0800 Subject: [PATCH] :sparkles: Add version info --- simnet/version.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 simnet/version.py diff --git a/simnet/version.py b/simnet/version.py new file mode 100644 index 0000000..9ef91ca --- /dev/null +++ b/simnet/version.py @@ -0,0 +1,33 @@ +from typing import NamedTuple + +__all__ = ("__version__", "__version_info__") + + +class Version(NamedTuple): + """Copies the behavior of sys.version_info. serial is always 0 for stable releases.""" + + major: int + minor: int + micro: int + release_level: str + serial: int + + def _rl_shorthand(self) -> str: # skipcq: PY-D0003 + return { + "alpha": "a", + "beta": "b", + "candidate": "rc", + }[self.release_level] + + def __str__(self) -> str: + version = f"{self.major}.{self.minor}" + if self.micro != 0: + version = f"{version}.{self.micro}" + if self.release_level != "final": + version = f"{version}{self._rl_shorthand()}{self.serial}" + + return version + + +__version_info__ = Version(major=1, minor=0, micro=0, release_level="beta", serial=0) +__version__ = str(__version_info__)