Pillow/setup.py

816 lines
31 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2013-09-28 17:28:16 +04:00
# > pyroma .
# ------------------------------
# Checking .
# Found Pillow
# ------------------------------
# Final rating: 10/10
# Your cheese is so fresh most people think it's a cream: Mascarpone
# ------------------------------
from __future__ import print_function
2010-11-28 23:15:53 +03:00
import os
2013-05-12 03:56:02 +04:00
import platform as plat
2010-11-28 23:15:53 +03:00
import re
import struct
import subprocess
import sys
import warnings
from distutils import ccompiler, sysconfig
2010-11-28 23:15:53 +03:00
from distutils.command.build_ext import build_ext
2017-12-28 01:23:17 +03:00
from setuptools import Extension, setup
2014-07-01 01:33:41 +04:00
# monkey patch import hook. Even though flake8 says it's not used, it is.
2014-08-28 15:44:19 +04:00
# comment this out to disable multi threaded builds.
2014-07-01 01:33:41 +04:00
import mp_compile
2010-11-28 23:15:53 +03:00
if sys.platform == "win32" and sys.version_info >= (3, 7):
warnings.warn(
"Pillow does not yet support Python {}.{} and does not yet provide "
"prebuilt Windows binaries. We do not recommend building from "
"source on Windows.".format(sys.version_info.major,
sys.version_info.minor),
RuntimeWarning)
_IMAGING = ("decode", "encode", "map", "display", "outline", "path")
2010-11-28 23:15:53 +03:00
_LIB_IMAGING = (
"Access", "AlphaComposite", "Resample", "Bands", "BcnDecode", "BitDecode",
2018-03-25 15:49:42 +03:00
"Blend", "Chops", "ColorLUT", "Convert", "ConvertYCbCr", "Copy", "Crop",
2017-12-04 15:35:05 +03:00
"Dib", "Draw", "Effects", "EpsEncode", "File", "Fill", "Filter",
"FliDecode", "Geometry", "GetBBox", "GifDecode", "GifEncode", "HexDecode",
2017-12-20 17:36:39 +03:00
"Histo", "JpegDecode", "JpegEncode", "Matrix", "ModeFilter",
2017-12-04 15:35:05 +03:00
"Negative", "Offset", "Pack", "PackDecode", "Palette", "Paste", "Quant",
"QuantOctree", "QuantHash", "QuantHeap", "PcdDecode", "PcxDecode",
"PcxEncode", "Point", "RankFilter", "RawDecode", "RawEncode", "Storage",
2017-07-22 10:34:06 +03:00
"SgiRleDecode", "SunRleDecode", "TgaRleDecode", "Unpack", "UnpackYCC",
2017-12-04 15:35:05 +03:00
"UnsharpMask", "XbmDecode", "XbmEncode", "ZipDecode", "ZipEncode",
"TiffDecode", "Jpeg2KDecode", "Jpeg2KEncode", "BoxBlur", "QuantPngQuant",
"codec_fd")
2010-11-28 23:15:53 +03:00
2016-03-30 19:16:10 +03:00
DEBUG = False
2010-11-28 23:15:53 +03:00
2017-12-04 15:35:05 +03:00
class DependencyException(Exception):
pass
class RequiredDependencyException(Exception):
pass
2017-09-19 15:44:56 +03:00
PLATFORM_MINGW = 'mingw' in ccompiler.get_default_compiler()
PLATFORM_PYPY = hasattr(sys, 'pypy_version_info')
2017-12-04 15:35:05 +03:00
2016-03-30 19:16:10 +03:00
def _dbg(s, tp=None):
if DEBUG:
if tp:
print(s % tp)
return
print(s)
2010-11-28 23:15:53 +03:00
2016-03-30 18:19:23 +03:00
def _add_directory(path, subdir, where=None):
if subdir is None:
2013-12-11 13:13:06 +04:00
return
2016-03-30 18:19:23 +03:00
subdir = os.path.realpath(subdir)
if os.path.isdir(subdir) and subdir not in path:
2010-11-28 23:15:53 +03:00
if where is None:
2016-03-30 19:16:10 +03:00
_dbg('Appending path %s', subdir)
2016-03-30 18:19:23 +03:00
path.append(subdir)
2010-11-28 23:15:53 +03:00
else:
2016-03-30 19:16:10 +03:00
_dbg('Inserting path %s', subdir)
2016-03-30 18:19:23 +03:00
path.insert(where, subdir)
elif subdir in path and where is not None:
path.remove(subdir)
path.insert(where, subdir)
2010-11-28 23:15:53 +03:00
def _find_include_file(self, include):
for directory in self.compiler.include_dirs:
2016-03-30 19:16:10 +03:00
_dbg('Checking for include file %s in %s', (include, directory))
2010-11-28 23:15:53 +03:00
if os.path.isfile(os.path.join(directory, include)):
2016-03-30 19:16:10 +03:00
_dbg('Found %s', include)
2010-11-28 23:15:53 +03:00
return 1
return 0
def _find_library_file(self, library):
2016-11-07 15:35:23 +03:00
ret = self.compiler.find_library_file(self.compiler.library_dirs, library)
2016-03-30 19:16:10 +03:00
if ret:
_dbg('Found library %s at %s', (library, ret))
else:
_dbg("Couldn't find library %s in %s",
(library, self.compiler.library_dirs))
2016-03-30 19:16:10 +03:00
return ret
2013-05-12 03:56:02 +04:00
2010-11-28 23:15:53 +03:00
def _cmd_exists(cmd):
return any(
os.access(os.path.join(path, cmd), os.X_OK)
for path in os.environ["PATH"].split(os.pathsep)
)
2010-11-28 23:20:53 +03:00
2017-12-04 15:35:05 +03:00
2010-11-28 23:15:53 +03:00
def _read(file):
with open(file, 'rb') as fp:
return fp.read()
2017-04-19 17:39:39 +03:00
def get_version():
2017-12-28 01:23:17 +03:00
version_file = 'src/PIL/version.py'
2017-05-10 14:59:37 +03:00
with open(version_file, 'r') as f:
2017-04-19 17:39:39 +03:00
exec(compile(f.read(), version_file, 'exec'))
return locals()['__version__']
2017-12-04 15:35:05 +03:00
2010-11-28 23:15:53 +03:00
try:
import _tkinter
2014-03-27 00:12:20 +04:00
except (ImportError, OSError):
# pypy emits an oserror
2010-11-28 23:15:53 +03:00
_tkinter = None
NAME = 'Pillow'
2017-04-19 17:39:39 +03:00
PILLOW_VERSION = get_version()
2010-11-28 23:15:53 +03:00
JPEG_ROOT = None
2014-03-14 18:35:09 +04:00
JPEG2K_ROOT = None
2010-11-28 23:15:53 +03:00
ZLIB_ROOT = None
IMAGEQUANT_ROOT = None
TIFF_ROOT = None
2010-11-28 23:15:53 +03:00
FREETYPE_ROOT = None
LCMS_ROOT = None
2017-12-04 15:35:05 +03:00
def _pkg_config(name):
try:
command = [
'pkg-config',
'--libs-only-L', name,
'--cflags-only-I', name,
]
if not DEBUG:
command.append('--silence-errors')
libs = subprocess.check_output(command).decode('utf8').split(' ')
return libs[1][2:].strip(), libs[0][2:].strip()
2017-12-04 15:35:05 +03:00
except Exception:
pass
2017-12-04 15:35:05 +03:00
2010-11-28 23:15:53 +03:00
class pil_build_ext(build_ext):
class feature:
features = ['zlib', 'jpeg', 'tiff', 'freetype', 'lcms', 'webp',
'webpmux', 'jpeg2000', 'imagequant']
required = {'jpeg', 'zlib'}
def __init__(self):
for f in self.features:
setattr(self, f, None)
def require(self, feat):
return feat in self.required
2014-06-24 10:34:05 +04:00
def want(self, feat):
return getattr(self, feat) is None
def __iter__(self):
for x in self.features:
yield x
feature = feature()
user_options = build_ext.user_options + [
('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
] + [
2017-12-04 15:35:05 +03:00
('disable-platform-guessing', None,
'Disable platform guessing on Linux'),
('debug', None, 'Debug logging')
]
def initialize_options(self):
self.disable_platform_guessing = None
build_ext.initialize_options(self)
for x in self.feature:
setattr(self, 'disable_%s' % x, None)
setattr(self, 'enable_%s' % x, None)
def finalize_options(self):
build_ext.finalize_options(self)
2016-03-30 19:16:10 +03:00
if self.debug:
global DEBUG
DEBUG = True
for x in self.feature:
if getattr(self, 'disable_%s' % x):
setattr(self.feature, x, False)
2015-09-22 23:07:31 +03:00
self.feature.required.discard(x)
2016-03-30 19:16:10 +03:00
_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):
2016-03-30 19:16:10 +03:00
_dbg('Requiring %s', x)
2015-09-22 23:07:31 +03:00
self.feature.required.add(x)
2010-11-28 23:15:53 +03:00
def build_extensions(self):
library_dirs = []
include_dirs = []
2017-12-28 01:23:17 +03:00
_add_directory(include_dirs, "src/libImaging")
2010-11-28 23:15:53 +03:00
pkg_config = None
if _cmd_exists('pkg-config'):
pkg_config = _pkg_config
#
# add configured kits
for root_name, lib_name in dict(JPEG_ROOT="libjpeg",
JPEG2K_ROOT="libopenjp2",
TIFF_ROOT=("libtiff-5", "libtiff-4"),
ZLIB_ROOT="zlib",
FREETYPE_ROOT="freetype2",
LCMS_ROOT="lcms2",
IMAGEQUANT_ROOT="libimagequant"
).items():
root = globals()[root_name]
if root is None and pkg_config:
if isinstance(lib_name, tuple):
for lib_name2 in lib_name:
_dbg('Looking for `%s` using pkg-config.' % lib_name2)
root = pkg_config(lib_name2)
if root:
break
else:
_dbg('Looking for `%s` using pkg-config.' % lib_name)
root = pkg_config(lib_name)
if isinstance(root, tuple):
lib_root, include_root = root
else:
lib_root = include_root = root
_add_directory(library_dirs, lib_root)
_add_directory(include_dirs, include_root)
# respect CFLAGS/LDFLAGS
for k in ('CFLAGS', 'LDFLAGS'):
if k in os.environ:
for match in re.finditer(r'-I([^\s]+)', os.environ[k]):
_add_directory(include_dirs, match.group(1))
for match in re.finditer(r'-L([^\s]+)', os.environ[k]):
_add_directory(library_dirs, match.group(1))
# include, rpath, if set as environment variables:
for k in ('C_INCLUDE_PATH', 'CPATH', 'INCLUDE'):
if k in os.environ:
for d in os.environ[k].split(os.path.pathsep):
_add_directory(include_dirs, d)
for k in ('LD_RUN_PATH', 'LIBRARY_PATH', 'LIB'):
if k in os.environ:
for d in os.environ[k].split(os.path.pathsep):
_add_directory(library_dirs, d)
prefix = sysconfig.get_config_var("prefix")
if prefix:
_add_directory(library_dirs, os.path.join(prefix, "lib"))
_add_directory(include_dirs, os.path.join(prefix, "include"))
2010-11-28 23:15:53 +03:00
#
# add platform directories
2016-05-01 12:57:50 +03:00
if self.disable_platform_guessing:
pass
2016-05-01 12:57:50 +03:00
elif sys.platform == "cygwin":
2010-11-28 23:15:53 +03:00
# pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory
_add_directory(library_dirs,
os.path.join("/usr/lib", "python%s" %
sys.version[:3], "config"))
2010-11-28 23:15:53 +03:00
elif sys.platform == "darwin":
# attempt to make sure we pick freetype2 over other versions
_add_directory(include_dirs, "/sw/include/freetype2")
_add_directory(include_dirs, "/sw/lib/freetype2/include")
# fink installation directories
_add_directory(library_dirs, "/sw/lib")
_add_directory(include_dirs, "/sw/include")
# darwin ports installation directories
_add_directory(library_dirs, "/opt/local/lib")
_add_directory(include_dirs, "/opt/local/include")
# if Homebrew is installed, use its lib and include directories
2013-10-02 19:36:47 +04:00
try:
prefix = subprocess.check_output(['brew', '--prefix']).strip(
).decode('latin1')
2017-12-04 15:35:05 +03:00
except Exception:
# Homebrew not installed
prefix = None
ft_prefix = None
if prefix:
# add Homebrew's include and lib directories
_add_directory(library_dirs, os.path.join(prefix, 'lib'))
_add_directory(include_dirs, os.path.join(prefix, 'include'))
ft_prefix = os.path.join(prefix, 'opt', 'freetype')
if ft_prefix and os.path.isdir(ft_prefix):
# freetype might not be linked into Homebrew's prefix
_add_directory(library_dirs, os.path.join(ft_prefix, 'lib'))
_add_directory(include_dirs,
os.path.join(ft_prefix, 'include'))
else:
2014-06-24 10:34:05 +04:00
# fall back to freetype from XQuartz if
# Homebrew's freetype is missing
_add_directory(library_dirs, "/usr/X11/lib")
_add_directory(include_dirs, "/usr/X11/include")
elif sys.platform.startswith("linux"):
arch_tp = (plat.processor(), plat.architecture()[0])
2017-11-13 13:57:49 +03:00
# This should be correct on debian derivatives.
if os.path.exists('/etc/debian_version'):
2017-11-13 13:57:49 +03:00
# If this doesn't work, don't just silently patch
# downstream because it's going to break when people
# try to build pillow from source instead of
# installing from the system packages.
self.add_multiarch_paths()
elif arch_tp == ("x86_64", "32bit"):
2017-11-13 14:35:15 +03:00
# Special Case: 32-bit build on 64-bit machine.
_add_directory(library_dirs, "/usr/lib/i386-linux-gnu")
2013-02-18 20:16:13 +04:00
else:
2017-11-13 14:35:15 +03:00
libdirs = {
2017-12-04 15:35:05 +03:00
'x86_64': ["/lib64", "/usr/lib64",
"/usr/lib/x86_64-linux-gnu"],
'64bit': ["/lib64", "/usr/lib64",
"/usr/lib/x86_64-linux-gnu"],
2017-11-13 14:35:15 +03:00
'i386': ["/usr/lib/i386-linux-gnu"],
'i686': ["/usr/lib/i386-linux-gnu"],
'32bit': ["/usr/lib/i386-linux-gnu"],
'aarch64': ["/usr/lib64", "/usr/lib/aarch64-linux-gnu"],
'arm': ["/usr/lib/arm-linux-gnueabi"],
'armv71': ["/usr/lib/arm-linux-gnueabi"],
'armv7l': ["/usr/lib"],
2017-11-13 14:35:15 +03:00
'ppc64': ["/usr/lib64", "/usr/lib/ppc64-linux-gnu",
"/usr/lib/powerpc64-linux-gnu"],
'ppc64le': ["/usr/lib64"],
2017-11-13 14:35:15 +03:00
'ppc': ["/usr/lib/ppc-linux-gnu",
"/usr/lib/powerpc-linux-gnu"],
's390x': ["/usr/lib64", "/usr/lib/s390x-linux-gnu"],
's390': ["/usr/lib/s390-linux-gnu"],
}
2017-11-29 12:23:46 +03:00
for platform_ in arch_tp:
2017-11-13 14:35:15 +03:00
dirs = libdirs.get(platform_, None)
if not dirs:
continue
2017-11-13 14:35:15 +03:00
for path in dirs:
_add_directory(library_dirs, path)
break
2017-11-29 12:23:46 +03:00
else:
raise ValueError(
"Unable to identify Linux platform: `%s`" % platform_)
2011-05-31 19:24:38 +04:00
# termux support for android.
# system libraries (zlib) are installed in /system/lib
# headers are at $PREFIX/include
# user libs are at $PREFIX/lib
if os.environ.get('ANDROID_ROOT', None):
_add_directory(library_dirs,
2017-12-04 15:35:05 +03:00
os.path.join(os.environ['ANDROID_ROOT'],
'lib'))
elif sys.platform.startswith("gnu"):
self.add_multiarch_paths()
elif sys.platform.startswith("freebsd"):
_add_directory(library_dirs, "/usr/local/lib")
_add_directory(include_dirs, "/usr/local/include")
2013-11-14 16:10:19 +04:00
elif sys.platform.startswith("netbsd"):
2015-07-28 12:59:52 +03:00
_add_directory(library_dirs, "/usr/pkg/lib")
_add_directory(include_dirs, "/usr/pkg/include")
2013-11-14 16:10:19 +04:00
2015-07-27 19:17:49 +03:00
elif sys.platform.startswith("sunos5"):
_add_directory(library_dirs, "/opt/local/lib")
_add_directory(include_dirs, "/opt/local/include")
2015-09-11 12:28:19 +03:00
2010-11-28 23:15:53 +03:00
# FIXME: check /opt/stuff directories here?
# standard locations
if not self.disable_platform_guessing:
_add_directory(library_dirs, "/usr/local/lib")
_add_directory(include_dirs, "/usr/local/include")
2010-11-28 23:15:53 +03:00
_add_directory(library_dirs, "/usr/lib")
_add_directory(include_dirs, "/usr/include")
2016-05-30 16:28:08 +03:00
# alpine, at least
_add_directory(library_dirs, "/lib")
2010-11-28 23:15:53 +03:00
2014-03-14 18:35:09 +04:00
# on Windows, look for the OpenJPEG libraries in the location that
2014-05-27 15:43:54 +04:00
# the official installer puts them
2014-03-14 18:35:09 +04:00
if sys.platform == "win32":
2014-05-27 15:43:54 +04:00
program_files = os.environ.get('ProgramFiles', '')
best_version = (0, 0)
best_path = None
for name in os.listdir(program_files):
if name.startswith('OpenJPEG '):
version = tuple(int(x) for x in name[9:].strip().split('.'))
2014-05-27 15:43:54 +04:00
if version > best_version:
best_version = version
best_path = os.path.join(program_files, name)
if best_path:
2016-03-30 19:16:10 +03:00
_dbg('Adding %s to search list', best_path)
_add_directory(library_dirs, os.path.join(best_path, 'lib'))
2014-05-27 15:43:54 +04:00
_add_directory(include_dirs,
os.path.join(best_path, 'include'))
2014-03-14 18:35:09 +04:00
2010-11-28 23:15:53 +03:00
#
# insert new dirs *before* default libs, to avoid conflicts
# between Python PYD stub libs and real libraries
self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
self.compiler.include_dirs = include_dirs + self.compiler.include_dirs
#
# look for available libraries
feature = self.feature
if feature.want('zlib'):
2016-03-30 19:16:10 +03:00
_dbg('Looking for zlib')
if _find_include_file(self, "zlib.h"):
if _find_library_file(self, "z"):
feature.zlib = "z"
2014-06-24 10:34:05 +04:00
elif (sys.platform == "win32" and
_find_library_file(self, "zlib")):
feature.zlib = "zlib" # alternative name
if feature.want('jpeg'):
2016-03-30 19:16:10 +03:00
_dbg('Looking for jpeg')
if _find_include_file(self, "jpeglib.h"):
if _find_library_file(self, "jpeg"):
feature.jpeg = "jpeg"
elif (sys.platform == "win32" and
_find_library_file(self, "libjpeg")):
feature.jpeg = "libjpeg" # alternative name
feature.openjpeg_version = None
if feature.want('jpeg2000'):
2016-03-30 19:16:10 +03:00
_dbg('Looking for jpeg2000')
2014-05-27 15:43:54 +04:00
best_version = None
best_path = None
2014-06-24 10:34:05 +04:00
2014-05-27 15:43:54 +04:00
# Find the best version
for directory in self.compiler.include_dirs:
2016-03-30 19:16:10 +03:00
_dbg('Checking for openjpeg-#.# in %s', directory)
try:
listdir = os.listdir(directory)
2014-08-28 15:44:19 +04:00
except Exception:
# WindowsError, FileNotFoundError
continue
for name in listdir:
2014-05-27 15:43:54 +04:00
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('.'))
2014-05-27 15:43:54 +04:00
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))
2014-05-27 15:43:54 +04:00
if best_version and _find_library_file(self, 'openjp2'):
# Add the directory to the include path so we can include
# <openjpeg.h> rather than having to cope with the versioned
# include path
2017-05-26 14:48:38 +03:00
# FIXME (melvyn-sopacua):
# At this point it's possible that best_path is already in
# self.compiler.include_dirs. Should investigate how that is
# possible.
2014-05-27 15:43:54 +04:00
_add_directory(self.compiler.include_dirs, best_path, 0)
feature.jpeg2000 = 'openjp2'
feature.openjpeg_version = '.'.join(str(x) for x in best_version)
2014-06-24 10:34:05 +04:00
if feature.want('imagequant'):
_dbg('Looking for imagequant')
if _find_include_file(self, 'libimagequant.h'):
if _find_library_file(self, "imagequant"):
feature.imagequant = "imagequant"
elif _find_library_file(self, "libimagequant"):
feature.imagequant = "libimagequant"
if feature.want('tiff'):
2016-03-30 19:16:10 +03:00
_dbg('Looking for tiff')
if _find_include_file(self, 'tiff.h'):
if _find_library_file(self, "tiff"):
feature.tiff = "tiff"
if sys.platform == "win32" and _find_library_file(self, "libtiff"):
feature.tiff = "libtiff"
if (sys.platform == "darwin" and
_find_library_file(self, "libtiff")):
feature.tiff = "libtiff"
if feature.want('freetype'):
2016-03-30 19:16:10 +03:00
_dbg('Looking for freetype')
if _find_library_file(self, "freetype"):
# look for freetype2 include files
freetype_version = 0
2016-03-30 18:19:23 +03:00
for subdir in self.compiler.include_dirs:
2016-03-30 19:16:10 +03:00
_dbg('Checking for include file %s in %s', ("ft2build.h", subdir))
2016-03-30 18:19:23 +03:00
if os.path.isfile(os.path.join(subdir, "ft2build.h")):
2016-03-30 19:16:10 +03:00
_dbg('Found %s in %s', ("ft2build.h", subdir))
freetype_version = 21
2016-03-30 18:19:23 +03:00
subdir = os.path.join(subdir, "freetype2")
break
2016-03-30 18:19:23 +03:00
subdir = os.path.join(subdir, "freetype2")
2016-03-30 19:16:10 +03:00
_dbg('Checking for include file %s in %s', ("ft2build.h", subdir))
2016-03-30 18:19:23 +03:00
if os.path.isfile(os.path.join(subdir, "ft2build.h")):
2016-03-30 19:16:10 +03:00
_dbg('Found %s in %s', ("ft2build.h", subdir))
freetype_version = 21
break
if freetype_version:
feature.freetype = "freetype"
feature.freetype_version = freetype_version
2016-03-30 18:19:23 +03:00
if subdir:
_add_directory(self.compiler.include_dirs, subdir, 0)
if feature.want('lcms'):
2016-03-30 19:16:10 +03:00
_dbg('Looking for lcms')
2013-10-02 10:05:56 +04:00
if _find_include_file(self, "lcms2.h"):
if _find_library_file(self, "lcms2"):
2014-08-23 03:14:19 +04:00
feature.lcms = "lcms2"
elif _find_library_file(self, "lcms2_static"):
2015-07-08 08:32:50 +03:00
# alternate Windows name.
2014-08-23 03:14:19 +04:00
feature.lcms = "lcms2_static"
2010-11-28 23:15:53 +03:00
if feature.want('webp'):
2016-03-30 19:16:10 +03:00
_dbg('Looking for webp')
if (_find_include_file(self, "webp/encode.h") and
_find_include_file(self, "webp/decode.h")):
2014-06-24 10:34:05 +04:00
# In Google's precompiled zip it is call "libwebp":
if _find_library_file(self, "webp"):
feature.webp = "webp"
2014-08-23 04:04:26 +04:00
elif _find_library_file(self, "libwebp"):
feature.webp = "libwebp"
2013-03-12 18:30:59 +04:00
if feature.want('webpmux'):
2016-03-30 19:16:10 +03:00
_dbg('Looking for webpmux')
if (_find_include_file(self, "webp/mux.h") and
_find_include_file(self, "webp/demux.h")):
2014-06-24 10:34:05 +04:00
if (_find_library_file(self, "webpmux") and
_find_library_file(self, "webpdemux")):
feature.webpmux = "webpmux"
2014-08-23 04:04:26 +04:00
if (_find_library_file(self, "libwebpmux") and
_find_library_file(self, "libwebpdemux")):
feature.webpmux = "libwebpmux"
for f in feature:
if not getattr(feature, f) and feature.require(f):
if f in ('jpeg', 'zlib'):
raise RequiredDependencyException(f)
raise DependencyException(f)
2010-11-28 23:15:53 +03:00
#
# core library
2017-12-28 01:23:17 +03:00
files = ["src/_imaging.c"]
2016-03-30 19:13:10 +03:00
for src_file in _IMAGING:
2017-12-28 01:23:17 +03:00
files.append("src/" + src_file + ".c")
2016-03-30 19:13:10 +03:00
for src_file in _LIB_IMAGING:
2017-12-28 01:23:17 +03:00
files.append(os.path.join("src/libImaging", src_file + ".c"))
2010-11-28 23:15:53 +03:00
libs = []
defs = []
if feature.jpeg:
libs.append(feature.jpeg)
defs.append(("HAVE_LIBJPEG", None))
if feature.jpeg2000:
libs.append(feature.jpeg2000)
defs.append(("HAVE_OPENJPEG", None))
2014-03-29 07:29:58 +04:00
if sys.platform == "win32":
defs.append(("OPJ_STATIC", None))
2010-11-28 23:15:53 +03:00
if feature.zlib:
libs.append(feature.zlib)
defs.append(("HAVE_LIBZ", None))
if feature.imagequant:
libs.append(feature.imagequant)
defs.append(("HAVE_LIBIMAGEQUANT", None))
if feature.tiff:
libs.append(feature.tiff)
defs.append(("HAVE_LIBTIFF", None))
2010-11-28 23:15:53 +03:00
if sys.platform == "win32":
libs.extend(["kernel32", "user32", "gdi32"])
if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
2010-11-28 23:15:53 +03:00
defs.append(("WORDS_BIGENDIAN", None))
2017-09-19 15:44:56 +03:00
if sys.platform == "win32" and not (PLATFORM_PYPY or PLATFORM_MINGW):
2017-12-04 15:35:05 +03:00
defs.append(("PILLOW_VERSION", '"\\"%s\\""' % PILLOW_VERSION))
else:
2017-12-04 15:35:05 +03:00
defs.append(("PILLOW_VERSION", '"%s"' % PILLOW_VERSION))
2017-04-19 17:39:39 +03:00
exts = [(Extension("PIL._imaging",
files,
libraries=libs,
define_macros=defs))]
2010-11-28 23:15:53 +03:00
#
# additional libraries
if feature.freetype:
2016-01-27 08:09:26 +03:00
libs = ["freetype"]
defs = []
exts.append(Extension(
2017-12-28 01:23:17 +03:00
"PIL._imagingft", ["src/_imagingft.c"], libraries=libs,
2016-01-27 08:09:26 +03:00
define_macros=defs))
2010-11-28 23:15:53 +03:00
2016-03-30 19:16:10 +03:00
if feature.lcms:
2010-11-28 23:15:53 +03:00
extra = []
if sys.platform == "win32":
extra.extend(["user32", "gdi32"])
exts.append(Extension("PIL._imagingcms",
2017-12-28 01:23:17 +03:00
["src/_imagingcms.c"],
libraries=[feature.lcms] + extra))
2010-11-28 23:15:53 +03:00
2016-03-30 19:16:10 +03:00
if feature.webp:
2014-08-23 04:04:26 +04:00
libs = [feature.webp]
defs = []
if feature.webpmux:
defs.append(("HAVE_WEBPMUX", None))
2014-08-23 04:04:26 +04:00
libs.append(feature.webpmux)
2015-04-24 03:15:14 +03:00
libs.append(feature.webpmux.replace('pmux', 'pdemux'))
exts.append(Extension("PIL._webp",
2017-12-28 01:23:17 +03:00
["src/_webp.c"],
libraries=libs,
define_macros=defs))
2013-03-12 18:30:59 +04:00
tk_libs = ['psapi'] if sys.platform == 'win32' else []
exts.append(Extension("PIL._imagingtk",
2018-01-04 10:33:10 +03:00
["src/_imagingtk.c", "src/Tk/tkImaging.c"],
include_dirs=['src/Tk'],
libraries=tk_libs))
2010-11-28 23:15:53 +03:00
2017-12-28 01:23:17 +03:00
exts.append(Extension("PIL._imagingmath", ["src/_imagingmath.c"]))
exts.append(Extension("PIL._imagingmorph", ["src/_imagingmorph.c"]))
2010-11-28 23:15:53 +03:00
self.extensions[:] = exts
build_ext.build_extensions(self)
#
# sanity checks
2010-11-28 23:15:53 +03:00
self.summary_report(feature)
2010-11-28 23:15:53 +03:00
def summary_report(self, feature):
2011-09-07 22:28:38 +04:00
print("-" * 68)
print("PIL SETUP SUMMARY")
print("-" * 68)
print("version Pillow %s" % PILLOW_VERSION)
v = sys.version.split("[")
2012-11-02 01:08:29 +04:00
print("platform %s %s" % (sys.platform, v[0].strip()))
2010-11-28 23:15:53 +03:00
for v in v[1:]:
2012-11-02 01:08:29 +04:00
print(" [%s" % v.strip())
print("-" * 68)
2010-11-28 23:15:53 +03:00
options = [
(feature.jpeg, "JPEG"),
2014-06-24 10:34:05 +04:00
(feature.jpeg2000, "OPENJPEG (JPEG2000)",
feature.openjpeg_version),
2010-11-28 23:15:53 +03:00
(feature.zlib, "ZLIB (PNG/ZIP)"),
(feature.imagequant, "LIBIMAGEQUANT"),
(feature.tiff, "LIBTIFF"),
2010-11-28 23:15:53 +03:00
(feature.freetype, "FREETYPE2"),
2013-10-02 10:05:56 +04:00
(feature.lcms, "LITTLECMS2"),
(feature.webp, "WEBP"),
(feature.webpmux, "WEBPMUX"),
]
2010-11-28 23:15:53 +03:00
all = 1
for option in options:
if option[0]:
2014-05-27 15:43:54 +04:00
version = ''
2014-05-31 02:08:21 +04:00
if len(option) >= 3 and option[2]:
2014-05-27 15:43:54 +04:00
version = ' (%s)' % option[2]
print("--- %s support available%s" % (option[1], version))
2010-11-28 23:15:53 +03:00
else:
2012-11-02 01:08:29 +04:00
print("*** %s support not available" % option[1])
2010-11-28 23:15:53 +03:00
all = 0
print("-" * 68)
2010-11-28 23:15:53 +03:00
if not all:
print("To add a missing option, make sure you have the required")
2016-03-30 19:16:10 +03:00
print("library and headers.")
2017-12-04 15:35:05 +03:00
print("See https://pillow.readthedocs.io/en/latest/installation."
"html#building-from-source")
2013-03-14 15:07:46 +04:00
print("")
2010-11-28 23:15:53 +03:00
print("To check the build, run the selftest.py script.")
2013-03-14 15:07:46 +04:00
print("")
2010-11-28 23:15:53 +03:00
2016-04-15 18:09:46 +03:00
# https://hg.python.org/users/barry/rev/7e8deab93d5a
2011-05-31 19:24:38 +04:00
def add_multiarch_paths(self):
# Debian/Ubuntu multiarch support.
# https://wiki.ubuntu.com/MultiarchSpec
2011-09-07 21:40:53 +04:00
# self.build_temp
2011-05-31 19:24:38 +04:00
tmpfile = os.path.join(self.build_temp, 'multiarch')
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
with open(tmpfile, 'wb') as fp:
2016-05-30 16:28:08 +03:00
try:
ret = subprocess.call(['dpkg-architecture',
'-qDEB_HOST_MULTIARCH'], stdout=fp)
2017-12-04 15:35:05 +03:00
except Exception:
2016-05-30 16:28:08 +03:00
return
2011-05-31 19:24:38 +04:00
try:
if ret >> 8 == 0:
2016-12-28 01:54:10 +03:00
with open(tmpfile, 'r') as fp:
multiarch_path_component = fp.readline().strip()
_add_directory(self.compiler.library_dirs,
'/usr/lib/' + multiarch_path_component)
_add_directory(self.compiler.include_dirs,
'/usr/include/' + multiarch_path_component)
2011-05-31 19:33:28 +04:00
finally:
os.unlink(tmpfile)
2011-05-31 19:24:38 +04:00
2014-06-27 19:57:49 +04:00
def debug_build():
return hasattr(sys, 'gettotalrefcount')
needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
pytest_runner = ['pytest-runner'] if needs_pytest else []
try:
setup(name=NAME,
version=PILLOW_VERSION,
description='Python Imaging Library (Fork)',
long_description=_read('README.rst').decode('utf-8'),
author='Alex Clark (Fork Author)',
author_email='aclark@aclark.net',
2018-04-04 23:29:14 +03:00
url='http://python-pillow.org',
classifiers=[
"Development Status :: 6 - Mature",
"Topic :: Multimedia :: Graphics",
"Topic :: Multimedia :: Graphics :: Capture :: Digital Camera",
"Topic :: Multimedia :: Graphics :: Capture :: Screen Capture",
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
"Topic :: Multimedia :: Graphics :: Viewers",
2017-11-29 12:23:46 +03:00
"License :: Other/Proprietary License",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
cmdclass={"build_ext": pil_build_ext},
ext_modules=[Extension("PIL._imaging", ["_imaging.c"])],
include_package_data=True,
setup_requires=pytest_runner,
tests_require=['pytest'],
2017-12-28 01:23:17 +03:00
packages=["PIL"],
2018-03-06 11:53:07 +03:00
package_dir={'': 'src'},
keywords=["Imaging", ],
license='Standard PIL License',
2017-09-19 15:44:56 +03:00
zip_safe=not (debug_build() or PLATFORM_MINGW), )
except RequiredDependencyException as err:
msg = """
The headers or library files could not be found for %s,
a required dependency when compiling Pillow from source.
Please see the install instructions at:
2017-02-14 12:27:02 +03:00
https://pillow.readthedocs.io/en/latest/installation.html
""" % (str(err))
sys.stderr.write(msg)
raise RequiredDependencyException(msg)
except DependencyException as err:
msg = """
The headers or library files could not be found for %s,
which was requested by the option flag --enable-%s
""" % (str(err), str(err))
sys.stderr.write(msg)
raise DependencyException(msg)