mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-14 09:14:45 +03:00
Merge cb1bfc5fad
into 4d234fb54d
This commit is contained in:
commit
dbc513c0dc
108
setup.py
108
setup.py
|
@ -37,21 +37,35 @@ _LIB_IMAGING = (
|
||||||
"XbmEncode", "ZipDecode", "ZipEncode", "TiffDecode", "Incremental",
|
"XbmEncode", "ZipDecode", "ZipEncode", "TiffDecode", "Incremental",
|
||||||
"Jpeg2KDecode", "Jpeg2KEncode", "BoxBlur")
|
"Jpeg2KDecode", "Jpeg2KEncode", "BoxBlur")
|
||||||
|
|
||||||
|
DEBUG = False
|
||||||
|
|
||||||
def _add_directory(path, dir, where=None):
|
|
||||||
if dir is None:
|
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:
|
||||||
return
|
return
|
||||||
dir = os.path.realpath(dir)
|
subdir = os.path.realpath(subdir)
|
||||||
if os.path.isdir(dir) and dir not in path:
|
if os.path.isdir(subdir) and subdir not in path:
|
||||||
if where is None:
|
if where is None:
|
||||||
path.append(dir)
|
_dbg('Appending path %s', subdir)
|
||||||
|
path.append(subdir)
|
||||||
else:
|
else:
|
||||||
path.insert(where, dir)
|
_dbg('Inserting path %s', subdir)
|
||||||
|
path.insert(where, subdir)
|
||||||
|
|
||||||
|
|
||||||
def _find_include_file(self, include):
|
def _find_include_file(self, include):
|
||||||
for directory in self.compiler.include_dirs:
|
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)):
|
if os.path.isfile(os.path.join(directory, include)):
|
||||||
|
_dbg('Found %s', include)
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -61,15 +75,22 @@ def _find_library_file(self, library):
|
||||||
# lib extension, not the system shared lib extension: e.g. .cpython-33.so
|
# lib extension, not the system shared lib extension: e.g. .cpython-33.so
|
||||||
# vs .so. See Python bug http://bugs.python.org/16754
|
# vs .so. See Python bug http://bugs.python.org/16754
|
||||||
if 'cpython' in self.compiler.shared_lib_extension:
|
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
|
existing = self.compiler.shared_lib_extension
|
||||||
self.compiler.shared_lib_extension = "." + existing.split('.')[-1]
|
self.compiler.shared_lib_extension = "." + existing.split('.')[-1]
|
||||||
ret = self.compiler.find_library_file(self.compiler.library_dirs,
|
ret = self.compiler.find_library_file(self.compiler.library_dirs,
|
||||||
library)
|
library)
|
||||||
self.compiler.shared_lib_extension = existing
|
self.compiler.shared_lib_extension = existing
|
||||||
return ret
|
|
||||||
else:
|
else:
|
||||||
return self.compiler.find_library_file(self.compiler.library_dirs,
|
ret = self.compiler.find_library_file(self.compiler.library_dirs,
|
||||||
library)
|
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):
|
def _lib_include(root):
|
||||||
|
@ -100,10 +121,15 @@ LCMS_ROOT = None
|
||||||
|
|
||||||
class pil_build_ext(build_ext):
|
class pil_build_ext(build_ext):
|
||||||
class feature:
|
class feature:
|
||||||
zlib = jpeg = tiff = freetype = tcl = tk = lcms = webp = webpmux = None
|
features = ['zlib', 'jpeg', 'tiff', 'freetype', 'tcl', 'tk', 'lcms',
|
||||||
jpeg2000 = None
|
'webp', 'webpmux', 'jpeg2000']
|
||||||
|
|
||||||
required = set(['jpeg', 'zlib'])
|
required = set(['jpeg', 'zlib'])
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
for f in self.features:
|
||||||
|
setattr(self, f, None)
|
||||||
|
|
||||||
def require(self, feat):
|
def require(self, feat):
|
||||||
return feat in self.required
|
return feat in self.required
|
||||||
|
|
||||||
|
@ -111,9 +137,8 @@ class pil_build_ext(build_ext):
|
||||||
return getattr(self, feat) is None
|
return getattr(self, feat) is None
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for x in dir(self):
|
for x in self.features:
|
||||||
if x[1] != '_':
|
yield x
|
||||||
yield x
|
|
||||||
|
|
||||||
feature = feature()
|
feature = feature()
|
||||||
|
|
||||||
|
@ -121,7 +146,7 @@ class pil_build_ext(build_ext):
|
||||||
('disable-%s' % x, None, 'Disable support for %s' % x) for x in feature
|
('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
|
('enable-%s' % x, None, 'Enable support for %s' % x) for x in feature
|
||||||
]
|
] + [('debug', None, 'Debug logging')]
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
build_ext.initialize_options(self)
|
build_ext.initialize_options(self)
|
||||||
|
@ -131,15 +156,20 @@ class pil_build_ext(build_ext):
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
build_ext.finalize_options(self)
|
build_ext.finalize_options(self)
|
||||||
|
if self.debug:
|
||||||
|
global DEBUG
|
||||||
|
DEBUG = True
|
||||||
for x in self.feature:
|
for x in self.feature:
|
||||||
if getattr(self, 'disable_%s' % x):
|
if getattr(self, 'disable_%s' % x):
|
||||||
setattr(self.feature, x, False)
|
setattr(self.feature, x, False)
|
||||||
self.feature.required.discard(x)
|
self.feature.required.discard(x)
|
||||||
|
_dbg('Disabling %s', x)
|
||||||
if getattr(self, 'enable_%s' % x):
|
if getattr(self, 'enable_%s' % x):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Conflicting options: --enable-%s and --disable-%s' %
|
'Conflicting options: --enable-%s and --disable-%s' %
|
||||||
(x, x))
|
(x, x))
|
||||||
if getattr(self, 'enable_%s' % x):
|
if getattr(self, 'enable_%s' % x):
|
||||||
|
_dbg('Requiring %s', x)
|
||||||
self.feature.required.add(x)
|
self.feature.required.add(x)
|
||||||
|
|
||||||
def build_extensions(self):
|
def build_extensions(self):
|
||||||
|
@ -314,6 +344,7 @@ class pil_build_ext(build_ext):
|
||||||
|
|
||||||
if _tkinter:
|
if _tkinter:
|
||||||
TCL_VERSION = _tkinter.TCL_VERSION[:3]
|
TCL_VERSION = _tkinter.TCL_VERSION[:3]
|
||||||
|
_dbg('Tkinter found, will check for Tcl/Tk')
|
||||||
|
|
||||||
if _tkinter and not TCL_ROOT:
|
if _tkinter and not TCL_ROOT:
|
||||||
# we have Tkinter but the TCL_ROOT variable was not set;
|
# we have Tkinter but the TCL_ROOT variable was not set;
|
||||||
|
@ -342,6 +373,7 @@ class pil_build_ext(build_ext):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
TCL_ROOT = None
|
TCL_ROOT = None
|
||||||
|
_dbg('Tcl/tk not found')
|
||||||
|
|
||||||
# add standard directories
|
# add standard directories
|
||||||
|
|
||||||
|
@ -390,6 +422,7 @@ class pil_build_ext(build_ext):
|
||||||
feature = self.feature
|
feature = self.feature
|
||||||
|
|
||||||
if feature.want('zlib'):
|
if feature.want('zlib'):
|
||||||
|
_dbg('Looking for zlib')
|
||||||
if _find_include_file(self, "zlib.h"):
|
if _find_include_file(self, "zlib.h"):
|
||||||
if _find_library_file(self, "z"):
|
if _find_library_file(self, "z"):
|
||||||
feature.zlib = "z"
|
feature.zlib = "z"
|
||||||
|
@ -398,6 +431,7 @@ class pil_build_ext(build_ext):
|
||||||
feature.zlib = "zlib" # alternative name
|
feature.zlib = "zlib" # alternative name
|
||||||
|
|
||||||
if feature.want('jpeg'):
|
if feature.want('jpeg'):
|
||||||
|
_dbg('Looking for jpeg')
|
||||||
if _find_include_file(self, "jpeglib.h"):
|
if _find_include_file(self, "jpeglib.h"):
|
||||||
if _find_library_file(self, "jpeg"):
|
if _find_library_file(self, "jpeg"):
|
||||||
feature.jpeg = "jpeg"
|
feature.jpeg = "jpeg"
|
||||||
|
@ -407,11 +441,13 @@ class pil_build_ext(build_ext):
|
||||||
|
|
||||||
feature.openjpeg_version = None
|
feature.openjpeg_version = None
|
||||||
if feature.want('jpeg2000'):
|
if feature.want('jpeg2000'):
|
||||||
|
_dbg('Looking for jpeg2000')
|
||||||
best_version = None
|
best_version = None
|
||||||
best_path = None
|
best_path = None
|
||||||
|
|
||||||
# Find the best version
|
# Find the best version
|
||||||
for directory in self.compiler.include_dirs:
|
for directory in self.compiler.include_dirs:
|
||||||
|
_dbg('Checking for openjpeg-#.# in %s', directory)
|
||||||
try:
|
try:
|
||||||
listdir = os.listdir(directory)
|
listdir = os.listdir(directory)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -421,10 +457,13 @@ class pil_build_ext(build_ext):
|
||||||
if name.startswith('openjpeg-') and \
|
if name.startswith('openjpeg-') and \
|
||||||
os.path.isfile(os.path.join(directory, name,
|
os.path.isfile(os.path.join(directory, name,
|
||||||
'openjpeg.h')):
|
'openjpeg.h')):
|
||||||
|
_dbg('Found openjpeg.h in %s/%s', (directory, name))
|
||||||
version = tuple([int(x) for x in name[9:].split('.')])
|
version = tuple([int(x) for x in name[9:].split('.')])
|
||||||
if best_version is None or version > best_version:
|
if best_version is None or version > best_version:
|
||||||
best_version = version
|
best_version = version
|
||||||
best_path = os.path.join(directory, name)
|
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'):
|
if best_version and _find_library_file(self, 'openjp2'):
|
||||||
# Add the directory to the include path so we can include
|
# Add the directory to the include path so we can include
|
||||||
|
@ -436,6 +475,7 @@ class pil_build_ext(build_ext):
|
||||||
best_version])
|
best_version])
|
||||||
|
|
||||||
if feature.want('tiff'):
|
if feature.want('tiff'):
|
||||||
|
_dbg('Looking for tiff')
|
||||||
if _find_library_file(self, "tiff"):
|
if _find_library_file(self, "tiff"):
|
||||||
feature.tiff = "tiff"
|
feature.tiff = "tiff"
|
||||||
if sys.platform == "win32" and _find_library_file(self, "libtiff"):
|
if sys.platform == "win32" and _find_library_file(self, "libtiff"):
|
||||||
|
@ -445,25 +485,27 @@ class pil_build_ext(build_ext):
|
||||||
feature.tiff = "libtiff"
|
feature.tiff = "libtiff"
|
||||||
|
|
||||||
if feature.want('freetype'):
|
if feature.want('freetype'):
|
||||||
|
_dbg('Looking for freetype')
|
||||||
if _find_library_file(self, "freetype"):
|
if _find_library_file(self, "freetype"):
|
||||||
# look for freetype2 include files
|
# look for freetype2 include files
|
||||||
freetype_version = 0
|
freetype_version = 0
|
||||||
for dir in self.compiler.include_dirs:
|
for subdir in self.compiler.include_dirs:
|
||||||
if os.path.isfile(os.path.join(dir, "ft2build.h")):
|
if os.path.isfile(os.path.join(subdir, "ft2build.h")):
|
||||||
freetype_version = 21
|
freetype_version = 21
|
||||||
dir = os.path.join(dir, "freetype2")
|
subdir = os.path.join(subdir, "freetype2")
|
||||||
break
|
break
|
||||||
dir = os.path.join(dir, "freetype2")
|
subdir = os.path.join(subdir, "freetype2")
|
||||||
if os.path.isfile(os.path.join(dir, "ft2build.h")):
|
if os.path.isfile(os.path.join(subdir, "ft2build.h")):
|
||||||
freetype_version = 21
|
freetype_version = 21
|
||||||
break
|
break
|
||||||
if freetype_version:
|
if freetype_version:
|
||||||
feature.freetype = "freetype"
|
feature.freetype = "freetype"
|
||||||
feature.freetype_version = freetype_version
|
feature.freetype_version = freetype_version
|
||||||
if dir:
|
if subdir:
|
||||||
_add_directory(self.compiler.include_dirs, dir, 0)
|
_add_directory(self.compiler.include_dirs, subdir, 0)
|
||||||
|
|
||||||
if feature.want('lcms'):
|
if feature.want('lcms'):
|
||||||
|
_dbg('Looking for lcms')
|
||||||
if _find_include_file(self, "lcms2.h"):
|
if _find_include_file(self, "lcms2.h"):
|
||||||
if _find_library_file(self, "lcms2"):
|
if _find_library_file(self, "lcms2"):
|
||||||
feature.lcms = "lcms2"
|
feature.lcms = "lcms2"
|
||||||
|
@ -486,6 +528,7 @@ class pil_build_ext(build_ext):
|
||||||
feature.tk = "tk" + TCL_VERSION
|
feature.tk = "tk" + TCL_VERSION
|
||||||
|
|
||||||
if feature.want('webp'):
|
if feature.want('webp'):
|
||||||
|
_dbg('Looking for webp')
|
||||||
if (_find_include_file(self, "webp/encode.h") and
|
if (_find_include_file(self, "webp/encode.h") and
|
||||||
_find_include_file(self, "webp/decode.h")):
|
_find_include_file(self, "webp/decode.h")):
|
||||||
# In Google's precompiled zip it is call "libwebp":
|
# In Google's precompiled zip it is call "libwebp":
|
||||||
|
@ -495,6 +538,7 @@ class pil_build_ext(build_ext):
|
||||||
feature.webp = "libwebp"
|
feature.webp = "libwebp"
|
||||||
|
|
||||||
if feature.want('webpmux'):
|
if feature.want('webpmux'):
|
||||||
|
_dbg('Looking for webpmux')
|
||||||
if (_find_include_file(self, "webp/mux.h") and
|
if (_find_include_file(self, "webp/mux.h") and
|
||||||
_find_include_file(self, "webp/demux.h")):
|
_find_include_file(self, "webp/demux.h")):
|
||||||
if (_find_library_file(self, "webpmux") and
|
if (_find_library_file(self, "webpmux") and
|
||||||
|
@ -518,10 +562,10 @@ class pil_build_ext(build_ext):
|
||||||
# core library
|
# core library
|
||||||
|
|
||||||
files = ["_imaging.c"]
|
files = ["_imaging.c"]
|
||||||
for file in _IMAGING:
|
for src_file in _IMAGING:
|
||||||
files.append(file + ".c")
|
files.append(src_file + ".c")
|
||||||
for file in _LIB_IMAGING:
|
for src_file in _LIB_IMAGING:
|
||||||
files.append(os.path.join("libImaging", file + ".c"))
|
files.append(os.path.join("libImaging", src_file + ".c"))
|
||||||
|
|
||||||
libs = []
|
libs = []
|
||||||
defs = []
|
defs = []
|
||||||
|
@ -592,10 +636,10 @@ class pil_build_ext(build_ext):
|
||||||
if (os.path.exists(root_tcl) and os.path.exists(root_tk)):
|
if (os.path.exists(root_tcl) and os.path.exists(root_tk)):
|
||||||
print("--- using frameworks at %s" % root)
|
print("--- using frameworks at %s" % root)
|
||||||
frameworks = ["-framework", "Tcl", "-framework", "Tk"]
|
frameworks = ["-framework", "Tcl", "-framework", "Tk"]
|
||||||
dir = os.path.join(root_tcl, "Headers")
|
subdir = os.path.join(root_tcl, "Headers")
|
||||||
_add_directory(self.compiler.include_dirs, dir, 0)
|
_add_directory(self.compiler.include_dirs, subdir, 0)
|
||||||
dir = os.path.join(root_tk, "Headers")
|
subdir = os.path.join(root_tk, "Headers")
|
||||||
_add_directory(self.compiler.include_dirs, dir, 1)
|
_add_directory(self.compiler.include_dirs, subdir, 1)
|
||||||
break
|
break
|
||||||
if frameworks:
|
if frameworks:
|
||||||
exts.append(Extension("PIL._imagingtk",
|
exts.append(Extension("PIL._imagingtk",
|
||||||
|
@ -689,8 +733,8 @@ class pil_build_ext(build_ext):
|
||||||
|
|
||||||
def check_zlib_version(self, include_dirs):
|
def check_zlib_version(self, include_dirs):
|
||||||
# look for unsafe versions of zlib
|
# look for unsafe versions of zlib
|
||||||
for dir in include_dirs:
|
for subdir in include_dirs:
|
||||||
zlibfile = os.path.join(dir, "zlib.h")
|
zlibfile = os.path.join(subdir, "zlib.h")
|
||||||
if os.path.isfile(zlibfile):
|
if os.path.isfile(zlibfile):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user