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 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from __future__ import annotations
  2. __all__ = ["tag", "version", "commit"]
  3. # ========= =========== ===================
  4. # release development
  5. # ========= =========== ===================
  6. # tag X.Y X.Y (upcoming)
  7. # version X.Y X.Y.dev1+g5678cde
  8. # commit X.Y 5678cde
  9. # ========= =========== ===================
  10. # When tagging a release, set `released = True`.
  11. # After tagging a release, set `released = False` and increment `tag`.
  12. released = True
  13. tag = version = commit = "11.0.3"
  14. if not released: # pragma: no cover
  15. import pathlib
  16. import re
  17. import subprocess
  18. def get_version(tag: str) -> str:
  19. # Since setup.py executes the contents of src/websockets/version.py,
  20. # __file__ can point to either of these two files.
  21. file_path = pathlib.Path(__file__)
  22. root_dir = file_path.parents[0 if file_path.name == "setup.py" else 2]
  23. # Read version from git if available. This prevents reading stale
  24. # information from src/websockets.egg-info after building a sdist.
  25. try:
  26. description = subprocess.run(
  27. ["git", "describe", "--dirty", "--tags", "--long"],
  28. capture_output=True,
  29. cwd=root_dir,
  30. timeout=1,
  31. check=True,
  32. text=True,
  33. ).stdout.strip()
  34. # subprocess.run raises FileNotFoundError if git isn't on $PATH.
  35. except (FileNotFoundError, subprocess.CalledProcessError):
  36. pass
  37. else:
  38. description_re = r"[0-9.]+-([0-9]+)-(g[0-9a-f]{7,}(?:-dirty)?)"
  39. match = re.fullmatch(description_re, description)
  40. assert match is not None
  41. distance, remainder = match.groups()
  42. remainder = remainder.replace("-", ".") # required by PEP 440
  43. return f"{tag}.dev{distance}+{remainder}"
  44. # Read version from package metadata if it is installed.
  45. try:
  46. import importlib.metadata # move up when dropping Python 3.7
  47. return importlib.metadata.version("websockets")
  48. except ImportError:
  49. pass
  50. # Avoid crashing if the development version cannot be determined.
  51. return f"{tag}.dev0+gunknown"
  52. version = get_version(tag)
  53. def get_commit(tag: str, version: str) -> str:
  54. # Extract commit from version, falling back to tag if not available.
  55. version_re = r"[0-9.]+\.dev[0-9]+\+g([0-9a-f]{7,}|unknown)(?:\.dirty)?"
  56. match = re.fullmatch(version_re, version)
  57. assert match is not None
  58. (commit,) = match.groups()
  59. return tag if commit == "unknown" else commit
  60. commit = get_commit(tag, version)