Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/zmq/__init__.py: 50%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Python bindings for 0MQ"""
3# Copyright (C) PyZMQ Developers
4# Distributed under the terms of the Modified BSD License.
6from __future__ import annotations
8import os
9import sys
10from contextlib import contextmanager
13@contextmanager
14def _libs_on_path():
15 """context manager for libs directory on $PATH
17 Works around mysterious issue where os.add_dll_directory
18 does not resolve imports (conda-forge Python >= 3.8)
19 """
21 if not sys.platform.startswith("win"):
22 yield
23 return
25 libs_dir = os.path.abspath(
26 os.path.join(
27 os.path.dirname(__file__),
28 os.pardir,
29 "pyzmq.libs",
30 )
31 )
32 if not os.path.exists(libs_dir):
33 # no bundled libs
34 yield
35 return
37 path_before = os.environ.get("PATH")
38 try:
39 os.environ["PATH"] = os.pathsep.join([path_before or "", libs_dir])
40 yield
41 finally:
42 if path_before is None:
43 os.environ.pop("PATH")
44 else:
45 os.environ["PATH"] = path_before
48# zmq top-level imports
50# workaround for Windows
51with _libs_on_path():
52 from zmq import backend
54from . import constants # noqa
55from .constants import * # noqa
56from zmq.backend import * # noqa
57from zmq import sugar
58from zmq.sugar import * # noqa
61def get_includes():
62 """Return a list of directories to include for linking against pyzmq with cython."""
63 from os.path import abspath, dirname, exists, join, pardir
65 base = dirname(__file__)
66 parent = abspath(join(base, pardir))
67 includes = [parent] + [join(parent, base, subdir) for subdir in ('utils',)]
68 if exists(join(parent, base, 'include')):
69 includes.append(join(parent, base, 'include'))
70 return includes
73def get_library_dirs():
74 """Return a list of directories used to link against pyzmq's bundled libzmq."""
75 from os.path import abspath, dirname, join, pardir
77 base = dirname(__file__)
78 parent = abspath(join(base, pardir))
79 return [join(parent, base)]
82COPY_THRESHOLD = 65536
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
86DRAFT_API: bool = backend.has('draft') and backend.PYZMQ_DRAFT_API
88__all__ = (
89 [
90 'get_includes',
91 'COPY_THRESHOLD',
92 'DRAFT_API',
93 ]
94 + constants.__all__
95 + sugar.__all__
96 + backend.__all__
97)