diff --git a/setup.py b/setup.py index 2ab9c870b..47a9f87a4 100644 --- a/setup.py +++ b/setup.py @@ -37,6 +37,15 @@ _LIB_IMAGING = ( "XbmEncode", "ZipDecode", "ZipEncode", "TiffDecode", "Incremental", "Jpeg2KDecode", "Jpeg2KEncode", "BoxBlur") +DEBUG = False + +def _dbg(s, tp=None): + if DEBUG: + if tp: + print(s % tp) + return + print(s) + def _add_directory(path, subdir, where=None): if subdir is None: @@ -44,14 +53,18 @@ def _add_directory(path, subdir, where=None): subdir = os.path.realpath(subdir) if os.path.isdir(subdir) and subdir not in path: if where is None: + _dbg('Appending path %s', subdir) path.append(subdir) else: + _dbg('Inserting path %s', subdir) path.insert(where, subdir) def _find_include_file(self, include): for directory in self.compiler.include_dirs: + _dbg('Checking for include file %s in %s', (include, directory)) if os.path.isfile(os.path.join(directory, include)): + _dbg('Found %s', include) return 1 return 0 @@ -61,15 +74,22 @@ def _find_library_file(self, library): # lib extension, not the system shared lib extension: e.g. .cpython-33.so # vs .so. See Python bug http://bugs.python.org/16754 if 'cpython' in self.compiler.shared_lib_extension: + _dbg('stripping cpython from shared library extension %s', + self.compiler.shared_lib_extension) existing = self.compiler.shared_lib_extension self.compiler.shared_lib_extension = "." + existing.split('.')[-1] ret = self.compiler.find_library_file(self.compiler.library_dirs, library) self.compiler.shared_lib_extension = existing - return ret else: - return self.compiler.find_library_file(self.compiler.library_dirs, - library) + ret = self.compiler.find_library_file(self.compiler.library_dirs, + library) + if ret: + _dbg('Found library %s at %s', (library, ret)) + else: + _dbg("Couldn't find library %s in %s", + (library, self.compiler.library_dirs)) + return ret def _lib_include(root): @@ -125,7 +145,7 @@ class pil_build_ext(build_ext): ('disable-%s' % x, None, 'Disable support for %s' % x) for x in feature ] + [ ('enable-%s' % x, None, 'Enable support for %s' % x) for x in feature - ] + ] + [('debug', None, 'Debug logging')] def initialize_options(self): build_ext.initialize_options(self) @@ -135,15 +155,20 @@ class pil_build_ext(build_ext): def finalize_options(self): build_ext.finalize_options(self) + if self.debug: + global DEBUG + DEBUG = True for x in self.feature: if getattr(self, 'disable_%s' % x): setattr(self.feature, x, False) self.feature.required.discard(x) + _dbg('Disabling %s', x) if getattr(self, 'enable_%s' % x): raise ValueError( 'Conflicting options: --enable-%s and --disable-%s' % (x, x)) if getattr(self, 'enable_%s' % x): + _dbg('Requiring %s', x) self.feature.required.add(x) def build_extensions(self): @@ -318,6 +343,7 @@ class pil_build_ext(build_ext): if _tkinter: TCL_VERSION = _tkinter.TCL_VERSION[:3] + _dbg('Tkinter found, will check for Tcl/Tk') if _tkinter and not TCL_ROOT: # we have Tkinter but the TCL_ROOT variable was not set; @@ -346,6 +372,7 @@ class pil_build_ext(build_ext): break else: TCL_ROOT = None + _dbg('Tcl/tk not found') # add standard directories @@ -394,6 +421,7 @@ class pil_build_ext(build_ext): feature = self.feature if feature.want('zlib'): + _dbg('Looking for zlib') if _find_include_file(self, "zlib.h"): if _find_library_file(self, "z"): feature.zlib = "z" @@ -402,6 +430,7 @@ class pil_build_ext(build_ext): feature.zlib = "zlib" # alternative name if feature.want('jpeg'): + _dbg('Looking for jpeg') if _find_include_file(self, "jpeglib.h"): if _find_library_file(self, "jpeg"): feature.jpeg = "jpeg" @@ -411,11 +440,13 @@ class pil_build_ext(build_ext): feature.openjpeg_version = None if feature.want('jpeg2000'): + _dbg('Looking for jpeg2000') best_version = None best_path = None # Find the best version for directory in self.compiler.include_dirs: + _dbg('Checking for openjpeg-#.# in %s', directory) try: listdir = os.listdir(directory) except Exception: @@ -425,10 +456,12 @@ class pil_build_ext(build_ext): if name.startswith('openjpeg-') and \ os.path.isfile(os.path.join(directory, name, 'openjpeg.h')): + _dbg('Found openjpeg.h in %s/%s',(directory, name)) version = tuple([int(x) for x in name[9:].split('.')]) if best_version is None or version > best_version: best_version = version best_path = os.path.join(directory, name) + _dbg('Best openjpeg version %s so far in %s', (best_version, best_path)) if best_version and _find_library_file(self, 'openjp2'): # Add the directory to the include path so we can include @@ -440,6 +473,7 @@ class pil_build_ext(build_ext): best_version]) if feature.want('tiff'): + _dbg('Looking for tiff') if _find_library_file(self, "tiff"): feature.tiff = "tiff" if sys.platform == "win32" and _find_library_file(self, "libtiff"): @@ -449,6 +483,7 @@ class pil_build_ext(build_ext): feature.tiff = "libtiff" if feature.want('freetype'): + _dbg('Looking for freetype') if _find_library_file(self, "freetype"): # look for freetype2 include files freetype_version = 0 @@ -468,6 +503,7 @@ class pil_build_ext(build_ext): _add_directory(self.compiler.include_dirs, subdir, 0) if feature.want('lcms'): + _dbg('Looking for lcms') if _find_include_file(self, "lcms2.h"): if _find_library_file(self, "lcms2"): feature.lcms = "lcms2" @@ -490,6 +526,7 @@ class pil_build_ext(build_ext): feature.tk = "tk" + TCL_VERSION if feature.want('webp'): + _dbg('Looking for webp') if (_find_include_file(self, "webp/encode.h") and _find_include_file(self, "webp/decode.h")): # In Google's precompiled zip it is call "libwebp": @@ -499,6 +536,7 @@ class pil_build_ext(build_ext): feature.webp = "libwebp" if feature.want('webpmux'): + _dbg('Looking for webpmux') if (_find_include_file(self, "webp/mux.h") and _find_include_file(self, "webp/demux.h")): if (_find_library_file(self, "webpmux") and