Skip to content

Commit 17b9ce8

Browse files
authored
Merge pull request #2126 from minrk/compile-time-drafts
restore zmq.DRAFT_API meaning drafts are actually available
2 parents e21dcd8 + 83040f7 commit 17b9ce8

File tree

9 files changed

+29
-10
lines changed

9 files changed

+29
-10
lines changed

tests/test_asyncio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ async def test_poll_leak():
406406

407407

408408
async def test_draft_asyncio():
409-
if not zmq.has("draft"):
409+
if not zmq.DRAFT_API:
410410
pytest.skip("draft API")
411411
if zmq.zmq_version_info() < (4, 3, 2):
412412
pytest.skip("requires libzmq 4.3.2 for zmq_poller_fd")

zmq/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ def get_library_dirs():
8080

8181

8282
COPY_THRESHOLD = 65536
83-
DRAFT_API = backend.has("draft")
83+
# zmq.DRAFT_API represents _both_ the current runtime-loaded libzmq
84+
# and pyzmq were built with drafts,
85+
# which is required for pyzmq draft support
86+
DRAFT_API: bool = backend.has('draft') and backend.PYZMQ_DRAFT_API
8487

8588
__all__ = (
8689
[

zmq/backend/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class Context:
100100
def term(self) -> None: ...
101101

102102
IPC_PATH_MAX_LEN: int
103+
PYZMQ_DRAFT_API: bool
103104

104105
def has(capability: str) -> bool: ...
105106
def curve_keypair() -> tuple[bytes, bytes]: ...

zmq/backend/cffi/_cdefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,5 @@ int zmq_wrap_msg_init_data(zmq_msg_t *msg,
9494
void *data,
9595
size_t size,
9696
void *hint);
97+
98+
#define PYZMQ_DRAFT_API ...

zmq/backend/cffi/socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def get(self, option):
273273
and self.get(SocketOption.THREAD_SAFE)
274274
):
275275
_check_version((4, 3, 2), "draft socket FD support via zmq_poller_fd")
276-
if not zmq.has('draft'):
276+
if not zmq.DRAFT_API:
277277
raise RuntimeError("libzmq must be built with draft support")
278278
warnings.warn(zmq.error.DraftFDWarning(), stacklevel=2)
279279

zmq/backend/cffi/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ def _retry_sys_call(f, *args, **kwargs):
7575
return rc
7676

7777

78-
__all__ = ['has', 'curve_keypair', 'curve_public']
78+
PYZMQ_DRAFT_API: bool = bool(C.PYZMQ_DRAFT_API)
79+
80+
__all__ = ['has', 'curve_keypair', 'curve_public', 'PYZMQ_DRAFT_API']

zmq/backend/cython/_zmq.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
from cython.cimports.libc.stdio import stderr as cstderr
7777
from cython.cimports.libc.stdlib import free, malloc
7878
from cython.cimports.libc.string import memcpy
79+
from cython.cimports.zmq.backend.cython import libzmq
7980
from cython.cimports.zmq.backend.cython._externs import (
8081
get_ipc_path_max_len,
8182
getpid,
@@ -163,6 +164,8 @@
163164

164165
IPC_PATH_MAX_LEN: int = get_ipc_path_max_len()
165166

167+
PYZMQ_DRAFT_API: bool = bool(libzmq.PYZMQ_DRAFT_API)
168+
166169

167170
@cfunc
168171
@inline
@@ -929,8 +932,10 @@ def get(self, option: C.int):
929932
_check_version(
930933
(4, 3, 2), "draft socket FD support via zmq_poller_fd"
931934
)
932-
if not zmq.has('draft'):
933-
raise RuntimeError("libzmq must be built with draft support")
935+
if not zmq.DRAFT_API:
936+
raise RuntimeError(
937+
"libzmq and pyzmq must be built with draft support"
938+
)
934939
warnings.warn(zmq.error.DraftFDWarning(), stacklevel=2)
935940

936941
# create a poller and retrieve its fd
@@ -1120,8 +1125,8 @@ def join(self, group: str | bytes):
11201125
.. versionadded:: 17
11211126
"""
11221127
_check_version((4, 2), "RADIO-DISH")
1123-
if not zmq.has('draft'):
1124-
raise RuntimeError("libzmq must be built with draft support")
1128+
if not zmq.DRAFT_API:
1129+
raise RuntimeError("libzmq and pyzmq must be built with draft support")
11251130
if isinstance(group, str):
11261131
group = group.encode('utf8')
11271132
c_group: bytes = group
@@ -1139,8 +1144,8 @@ def leave(self, group):
11391144
.. versionadded:: 17
11401145
"""
11411146
_check_version((4, 2), "RADIO-DISH")
1142-
if not zmq.has('draft'):
1143-
raise RuntimeError("libzmq must be built with draft support")
1147+
if not zmq.DRAFT_API:
1148+
raise RuntimeError("libzmq and pyzmq must be built with draft support")
11441149
rc: C.int = zmq_leave(self.handle, group)
11451150
_check_rc(rc)
11461151

@@ -2027,6 +2032,7 @@ def monitored_queue(
20272032

20282033
__all__ = [
20292034
'IPC_PATH_MAX_LEN',
2035+
'PYZMQ_DRAFT_API',
20302036
'Context',
20312037
'Socket',
20322038
'Frame',

zmq/backend/select.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'curve_public',
2222
'zmq_version_info',
2323
'IPC_PATH_MAX_LEN',
24+
'PYZMQ_DRAFT_API',
2425
]
2526

2627

zmq/utils/zmq_compat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@
5757

5858
// libzmq 4.2 draft API
5959
#ifdef ZMQ_BUILD_DRAFT_API
60+
#define PYZMQ_DRAFT_API 1
6061
#if ZMQ_VERSION >= 40200
6162
#define PYZMQ_DRAFT_42
6263
#endif
6364
#if ZMQ_VERSION >= 40302
6465
#define PYZMQ_DRAFT_432
6566
#endif
67+
#else
68+
#define PYZMQ_DRAFT_API 0
6669
#endif
70+
6771
#ifndef PYZMQ_DRAFT_42
6872
#define zmq_join(s, group) _missing
6973
#define zmq_leave(s, group) _missing

0 commit comments

Comments
 (0)