pyversion.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2023 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen
  9. # https://gitlab.com/mmgen/mmgen
  10. """
  11. pyversion: Python version string operations
  12. """
  13. class PythonVersion(str):
  14. def __new__(cls,arg=None):
  15. if isinstance(arg,PythonVersion):
  16. return arg
  17. if arg:
  18. major,minor = arg.split('.')
  19. else:
  20. import platform
  21. major,minor = platform.python_version_tuple()[:2]
  22. me = str.__new__( cls, f'{major}.{minor}' )
  23. me.major = int(major)
  24. me.minor = int(minor)
  25. return me
  26. def __lt__(self,other):
  27. other = type(self)(other)
  28. return self.major < other.major or (self.major == other.major and self.minor < other.minor)
  29. def __le__(self,other):
  30. other = type(self)(other)
  31. return self.major < other.major or (self.major == other.major and self.minor <= other.minor)
  32. def __eq__(self,other):
  33. other = type(self)(other)
  34. return self.major == other.major and self.minor == other.minor
  35. def __ne__(self,other):
  36. other = type(self)(other)
  37. return not (self.major == other.major and self.minor == other.minor)
  38. def __gt__(self,other):
  39. other = type(self)(other)
  40. return self.major > other.major or (self.major == other.major and self.minor > other.minor)
  41. def __ge__(self,other):
  42. other = type(self)(other)
  43. return self.major > other.major or (self.major == other.major and self.minor >= other.minor)
  44. python_version = PythonVersion()