version.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. """PyZMQ and 0MQ version functions."""
  2. # Copyright (C) PyZMQ Developers
  3. # Distributed under the terms of the Modified BSD License.
  4. from __future__ import annotations
  5. import re
  6. from typing import Match, cast
  7. from zmq.backend import zmq_version_info
  8. __version__: str = "27.1.0"
  9. _version_pat = re.compile(r"(\d+)\.(\d+)\.(\d+)(.*)")
  10. _match = cast(Match, _version_pat.match(__version__))
  11. _version_groups = _match.groups()
  12. VERSION_MAJOR = int(_version_groups[0])
  13. VERSION_MINOR = int(_version_groups[1])
  14. VERSION_PATCH = int(_version_groups[2])
  15. VERSION_EXTRA = _version_groups[3].lstrip(".")
  16. version_info: tuple[int, int, int] | tuple[int, int, int, float] = (
  17. VERSION_MAJOR,
  18. VERSION_MINOR,
  19. VERSION_PATCH,
  20. )
  21. if VERSION_EXTRA:
  22. version_info = (
  23. VERSION_MAJOR,
  24. VERSION_MINOR,
  25. VERSION_PATCH,
  26. float('inf'),
  27. )
  28. __revision__: str = ''
  29. def pyzmq_version() -> str:
  30. """return the version of pyzmq as a string"""
  31. if __revision__:
  32. return '+'.join([__version__, __revision__[:6]])
  33. else:
  34. return __version__
  35. def pyzmq_version_info() -> tuple[int, int, int] | tuple[int, int, int, float]:
  36. """return the pyzmq version as a tuple of at least three numbers
  37. If pyzmq is a development version, `inf` will be appended after the third integer.
  38. """
  39. return version_info
  40. def zmq_version() -> str:
  41. """return the version of libzmq as a string"""
  42. return "{}.{}.{}".format(*zmq_version_info())
  43. __all__ = [
  44. 'zmq_version',
  45. 'zmq_version_info',
  46. 'pyzmq_version',
  47. 'pyzmq_version_info',
  48. '__version__',
  49. '__revision__',
  50. ]