1
0

config.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from enum import auto, Enum
  2. import platform
  3. from typing import NamedTuple, Union
  4. __all__ = ['Arch', 'PythonImpl', 'PythonVersion']
  5. class Arch(Enum):
  6. '''Supported platform architectures.'''
  7. AARCH64 = auto()
  8. I686 = auto()
  9. X86_64 = auto()
  10. def __str__(self):
  11. return self.name.lower()
  12. @classmethod
  13. def from_host(cls) -> 'Arch':
  14. return cls.from_str(platform.machine())
  15. @classmethod
  16. def from_str(cls, value) -> 'Arch':
  17. for arch in cls:
  18. if value == str(arch):
  19. return arch
  20. else:
  21. raise NotImplementedError(value)
  22. class LinuxTag(Enum):
  23. '''Supported platform tags.'''
  24. MANYLINUX_1 = auto()
  25. MANYLINUX_2010 = auto()
  26. MANYLINUX_2014 = auto()
  27. MANYLINUX_2_24 = auto()
  28. MANYLINUX_2_28 = auto()
  29. def __str__(self):
  30. tag = self.name.lower()
  31. if self in (LinuxTag.MANYLINUX_1, LinuxTag.MANYLINUX_2010,
  32. LinuxTag.MANYLINUX_2014):
  33. return tag.replace('_', '')
  34. else:
  35. return tag
  36. @classmethod
  37. def from_str(cls, value) -> 'LinuxTag':
  38. for tag in cls:
  39. if value == str(tag):
  40. return tag
  41. else:
  42. raise NotImplementedError(value)
  43. class PythonImpl(Enum):
  44. '''Supported Python implementations.'''
  45. CPYTHON = auto()
  46. class PythonVersion(NamedTuple):
  47. ''''''
  48. major: int
  49. minor: int
  50. patch: Union[int, str]
  51. @classmethod
  52. def from_str(cls, value: str) -> 'PythonVersion':
  53. major, minor, patch = value.split('.', 2)
  54. try:
  55. patch = int(patch)
  56. except ValueError:
  57. pass
  58. return cls(int(major), int(minor), patch)
  59. def long(self) -> str:
  60. return f'{self.major}.{self.minor}.{self.patch}'
  61. def short(self) -> str:
  62. return f'{self.major}.{self.minor}'