Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

version.py 3.5KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import datetime
  2. import functools
  3. import os
  4. import subprocess
  5. import sys
  6. from django.utils.regex_helper import _lazy_re_compile
  7. # Private, stable API for detecting the Python version. PYXY means "Python X.Y
  8. # or later". So that third-party apps can use these values, each constant
  9. # should remain as long as the oldest supported Django version supports that
  10. # Python version.
  11. PY36 = sys.version_info >= (3, 6)
  12. PY37 = sys.version_info >= (3, 7)
  13. PY38 = sys.version_info >= (3, 8)
  14. PY39 = sys.version_info >= (3, 9)
  15. PY310 = sys.version_info >= (3, 10)
  16. PY311 = sys.version_info >= (3, 11)
  17. def get_version(version=None):
  18. """Return a PEP 440-compliant version number from VERSION."""
  19. version = get_complete_version(version)
  20. # Now build the two parts of the version number:
  21. # main = X.Y[.Z]
  22. # sub = .devN - for pre-alpha releases
  23. # | {a|b|rc}N - for alpha, beta, and rc releases
  24. main = get_main_version(version)
  25. sub = ""
  26. if version[3] == "alpha" and version[4] == 0:
  27. git_changeset = get_git_changeset()
  28. if git_changeset:
  29. sub = ".dev%s" % git_changeset
  30. elif version[3] != "final":
  31. mapping = {"alpha": "a", "beta": "b", "rc": "rc"}
  32. sub = mapping[version[3]] + str(version[4])
  33. return main + sub
  34. def get_main_version(version=None):
  35. """Return main version (X.Y[.Z]) from VERSION."""
  36. version = get_complete_version(version)
  37. parts = 2 if version[2] == 0 else 3
  38. return ".".join(str(x) for x in version[:parts])
  39. def get_complete_version(version=None):
  40. """
  41. Return a tuple of the django version. If version argument is non-empty,
  42. check for correctness of the tuple provided.
  43. """
  44. if version is None:
  45. from django import VERSION as version
  46. else:
  47. assert len(version) == 5
  48. assert version[3] in ("alpha", "beta", "rc", "final")
  49. return version
  50. def get_docs_version(version=None):
  51. version = get_complete_version(version)
  52. if version[3] != "final":
  53. return "dev"
  54. else:
  55. return "%d.%d" % version[:2]
  56. @functools.lru_cache
  57. def get_git_changeset():
  58. """Return a numeric identifier of the latest git changeset.
  59. The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
  60. This value isn't guaranteed to be unique, but collisions are very unlikely,
  61. so it's sufficient for generating the development version numbers.
  62. """
  63. # Repository may not be found if __file__ is undefined, e.g. in a frozen
  64. # module.
  65. if "__file__" not in globals():
  66. return None
  67. repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  68. git_log = subprocess.run(
  69. "git log --pretty=format:%ct --quiet -1 HEAD",
  70. capture_output=True,
  71. shell=True,
  72. cwd=repo_dir,
  73. text=True,
  74. )
  75. timestamp = git_log.stdout
  76. tz = datetime.timezone.utc
  77. try:
  78. timestamp = datetime.datetime.fromtimestamp(int(timestamp), tz=tz)
  79. except ValueError:
  80. return None
  81. return timestamp.strftime("%Y%m%d%H%M%S")
  82. version_component_re = _lazy_re_compile(r"(\d+|[a-z]+|\.)")
  83. def get_version_tuple(version):
  84. """
  85. Return a tuple of version numbers (e.g. (1, 2, 3)) from the version
  86. string (e.g. '1.2.3').
  87. """
  88. version_numbers = []
  89. for item in version_component_re.split(version):
  90. if item and item != ".":
  91. try:
  92. component = int(item)
  93. except ValueError:
  94. break
  95. else:
  96. version_numbers.append(component)
  97. return tuple(version_numbers)