Skip to content

Commit f50d219

Browse files
committed
Workaround for Jython 2.7a2; it has no ctypes.util
Related issue: #9 See also: http://bugs.jython.org/issue1916
1 parent 6c36156 commit f50d219

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

wand/api.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
88
"""
99
import ctypes
10-
import ctypes.util
10+
try:
11+
import ctypes.util
12+
except ImportError:
13+
pass
1114
import os
1215
import os.path
1316
import platform
@@ -23,7 +26,6 @@ def load_library():
2326
"""
2427
libpath = None
2528
system = platform.system()
26-
2729
magick_home = os.environ.get('MAGICK_HOME')
2830
if magick_home:
2931
if system == 'Windows':
@@ -33,25 +35,29 @@ def load_library():
3335
else:
3436
libpath = 'lib', 'libMagickWand.so',
3537
libpath = os.path.join(magick_home, *libpath)
36-
else:
38+
elif hasattr(ctypes, 'util'):
3739
if system == 'Windows':
3840
libpath = ctypes.util.find_library('CORE_RL_wand_')
3941
else:
4042
libpath = ctypes.util.find_library('MagickWand')
43+
else:
44+
raise ImportError('cannot find MagickWand library; explicitly set '
45+
'MAGICK_HOME environment variable')
4146
libwand = ctypes.CDLL(libpath)
42-
4347
if system == 'Windows':
4448
# On Windows, the API is split between two libs. On other platforms,
4549
# it's all contained in one.
4650
libmagick_filename = 'CORE_RL_magick_'
4751
if magick_home:
4852
libmagick_path = os.path.join(magick_home,
4953
libmagick_filename + '.dll')
50-
else:
54+
elif hasattr(ctypes, 'util'):
5155
libmagick_path = ctypes.util.find_library(libmagick_filename)
56+
else:
57+
raise ImportError('cannot find MagickWand library; explicitly set '
58+
'MAGICK_HOME environment variable')
5259
libmagick = ctypes.CDLL(libmagick_path)
5360
return libwand, libmagick
54-
5561
return libwand, libwand
5662

5763

0 commit comments

Comments
 (0)