at 18.03-beta 6.2 kB view raw
1diff --git a/wand/api.py b/wand/api.py 2index 2c18513..1a1b511 100644 3--- a/wand/api.py 4+++ b/wand/api.py 5@@ -43,98 +43,6 @@ class c_magick_char_p(ctypes.c_char_p): 6 """ 7 library.MagickRelinquishMemory(self) 8 9- 10-def library_paths(): 11- """Iterates for library paths to try loading. The result paths are not 12- guaranteed that they exist. 13- 14- :returns: a pair of libwand and libmagick paths. they can be the same. 15- path can be ``None`` as well 16- :rtype: :class:`tuple` 17- 18- """ 19- libwand = None 20- libmagick = None 21- versions = '', '-6', '-Q16', '-Q8', '-6.Q16' 22- options = '', 'HDRI', 'HDRI-2' 23- system = platform.system() 24- magick_home = os.environ.get('MAGICK_HOME') 25- 26- if system == 'Windows': 27- # ImageMagick installers normally install coder and filter DLLs in 28- # subfolders, we need to add those folders to PATH, otherwise loading 29- # the DLL later will fail. 30- try: 31- with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 32- r"SOFTWARE\ImageMagick\Current") as reg_key: 33- libPath = winreg.QueryValueEx(reg_key, "LibPath") 34- coderPath = winreg.QueryValueEx(reg_key, "CoderModulesPath") 35- filterPath = winreg.QueryValueEx(reg_key, "FilterModulesPath") 36- magick_home = libPath[0] 37- os.environ['PATH'] += (';' + libPath[0] + ";" + 38- coderPath[0] + ";" + filterPath[0]) 39- except OSError: 40- # otherwise use MAGICK_HOME, and we assume the coder and 41- # filter DLLs are in the same directory 42- pass 43- 44- def magick_path(path): 45- return os.path.join(magick_home, *path) 46- combinations = itertools.product(versions, options) 47- for suffix in (version + option for version, option in combinations): 48- # On Windows, the API is split between two libs. On other platforms, 49- # it's all contained in one. 50- if magick_home: 51- if system == 'Windows': 52- libwand = 'CORE_RL_wand_{0}.dll'.format(suffix), 53- libmagick = 'CORE_RL_magick_{0}.dll'.format(suffix), 54- yield magick_path(libwand), magick_path(libmagick) 55- libwand = 'libMagickWand{0}.dll'.format(suffix), 56- libmagick = 'libMagickCore{0}.dll'.format(suffix), 57- yield magick_path(libwand), magick_path(libmagick) 58- elif system == 'Darwin': 59- libwand = 'lib', 'libMagickWand{0}.dylib'.format(suffix), 60- yield magick_path(libwand), magick_path(libwand) 61- else: 62- libwand = 'lib', 'libMagickWand{0}.so'.format(suffix), 63- yield magick_path(libwand), magick_path(libwand) 64- if system == 'Windows': 65- libwand = ctypes.util.find_library('CORE_RL_wand_' + suffix) 66- libmagick = ctypes.util.find_library('CORE_RL_magick_' + suffix) 67- yield libwand, libmagick 68- libwand = ctypes.util.find_library('libMagickWand' + suffix) 69- libmagick = ctypes.util.find_library('libMagickCore' + suffix) 70- yield libwand, libmagick 71- else: 72- libwand = ctypes.util.find_library('MagickWand' + suffix) 73- yield libwand, libwand 74- 75- 76-def load_library(): 77- """Loads the MagickWand library. 78- 79- :returns: the MagickWand library and the ImageMagick library 80- :rtype: :class:`ctypes.CDLL` 81- 82- """ 83- tried_paths = [] 84- for libwand_path, libmagick_path in library_paths(): 85- if libwand_path is None or libmagick_path is None: 86- continue 87- try: 88- tried_paths.append(libwand_path) 89- libwand = ctypes.CDLL(libwand_path) 90- if libwand_path == libmagick_path: 91- libmagick = libwand 92- else: 93- tried_paths.append(libmagick_path) 94- libmagick = ctypes.CDLL(libmagick_path) 95- except (IOError, OSError): 96- continue 97- return libwand, libmagick 98- raise IOError('cannot find library; tried paths: ' + repr(tried_paths)) 99- 100- 101 if not hasattr(ctypes, 'c_ssize_t'): 102 if ctypes.sizeof(ctypes.c_uint) == ctypes.sizeof(ctypes.c_void_p): 103 ctypes.c_ssize_t = ctypes.c_int 104@@ -176,43 +84,14 @@ class AffineMatrix(ctypes.Structure): 105 # Preserve the module itself even if it fails to import 106 sys.modules['wand._api'] = sys.modules['wand.api'] 107 108-try: 109- libraries = load_library() 110-except (OSError, IOError): 111- msg = 'http://docs.wand-py.org/en/latest/guide/install.html' 112- if sys.platform.startswith(('dragonfly', 'freebsd')): 113- msg = 'pkg install' 114- elif sys.platform == 'win32': 115- msg += '#install-imagemagick-on-windows' 116- elif sys.platform == 'darwin': 117- mac_pkgmgrs = {'brew': 'brew install freetype imagemagick', 118- 'port': 'port install imagemagick'} 119- for pkgmgr in mac_pkgmgrs: 120- with os.popen('which ' + pkgmgr) as f: 121- if f.read().strip(): 122- msg = mac_pkgmgrs[pkgmgr] 123- break 124- else: 125- msg += '#install-imagemagick-on-mac' 126- else: 127- distname, _, __ = platform.linux_distribution() 128- distname = (distname or '').lower() 129- if distname in ('debian', 'ubuntu'): 130- msg = 'apt-get install libmagickwand-dev' 131- elif distname in ('fedora', 'centos', 'redhat'): 132- msg = 'yum install ImageMagick-devel' 133- raise ImportError('MagickWand shared library not found.\n' 134- 'You probably had not installed ImageMagick library.\n' 135- 'Try to install:\n ' + msg) 136- 137 #: (:class:`ctypes.CDLL`) The MagickWand library. 138-library = libraries[0] 139+library = ctypes.CDLL("@magick_wand_library@") 140 141 #: (:class:`ctypes.CDLL`) The ImageMagick library. It is the same with 142 #: :data:`library` on platforms other than Windows. 143 #: 144 #: .. versionadded:: 0.1.10 145-libmagick = libraries[1] 146+libmagick = ctypes.CDLL("@imagemagick_library@") 147 148 try: 149 library.MagickWandGenesis.argtypes = []