Skip to content

Commit

Permalink
no longer bundle libzmq as DLL
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Feb 16, 2024
1 parent 365dd12 commit f51d5da
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 56 deletions.
3 changes: 0 additions & 3 deletions tools/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,3 @@ def test_bundle_msvcp():

for dll in should_bundle:
assert dll in dlls

assert any(dll.startswith("libzmq") for dll in dlls)
assert any(dll.startswith("libsodium") for dll in dlls)
53 changes: 0 additions & 53 deletions zmq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,11 @@
# Copyright (C) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.

# load bundled libzmq, if there is one:

import os
import sys
from contextlib import contextmanager


def _load_libzmq():
"""load bundled libzmq if there is one"""
import platform

dlopen = hasattr(sys, 'getdlopenflags') # unix-only
# RTLD flags are added to os in Python 3
# get values from os because ctypes values are WRONG on pypy
PYPY = platform.python_implementation().lower() == 'pypy'

if dlopen:
import ctypes

dlflags = sys.getdlopenflags()
# set RTLD_GLOBAL, unset RTLD_LOCAL
flags = ctypes.RTLD_GLOBAL | dlflags
# ctypes.RTLD_LOCAL is 0 on pypy, which is *wrong*
flags &= ~getattr(os, 'RTLD_LOCAL', 4)
# pypy on darwin needs RTLD_LAZY for some reason
if PYPY and sys.platform == 'darwin':
flags |= getattr(os, 'RTLD_LAZY', 1)
flags &= ~getattr(os, 'RTLD_NOW', 2)
sys.setdlopenflags(flags)
try:
from . import libzmq
except ImportError:
# raise on failure to load if libzmq is present
from importlib.util import find_spec

if find_spec(".libzmq", "zmq"):
# found libzmq, but failed to load it!
# raise instead of silently moving on
raise
else:
# store libzmq as zmq._libzmq for backward-compat
globals()['_libzmq'] = libzmq
if PYPY:
# should already have been imported above, so reimporting is as cheap as checking
import ctypes

# some versions of pypy (5.3 < ? < 5.8) needs explicit CDLL load for some reason,
# otherwise symbols won't be globally available
# do this unconditionally because it should be harmless (?)
ctypes.CDLL(libzmq.__file__, ctypes.RTLD_GLOBAL)
finally:
if dlopen:
sys.setdlopenflags(dlflags)


_load_libzmq()


@contextmanager
def _libs_on_path():
"""context manager for libs directory on $PATH
Expand Down

0 comments on commit f51d5da

Please sign in to comment.