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