Skip to content

Commit 0ac1013

Browse files
authored
Merge pull request #1339 from plapadoo/feature-pillow
Add Pillow Recipe
2 parents 5aec282 + 26d77c9 commit 0ac1013

File tree

4 files changed

+234
-1
lines changed

4 files changed

+234
-1
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
2+
from pythonforandroid.toolchain import shprint
3+
from os.path import join, dirname
4+
import sh
5+
6+
7+
class PillowRecipe(CompiledComponentsPythonRecipe):
8+
9+
version = '5.2.0'
10+
url = 'https://github.com/python-pillow/Pillow/archive/{version}.tar.gz'
11+
site_packages_name = 'Pillow'
12+
depends = [
13+
('python2', 'python3crystax'),
14+
'png',
15+
'jpeg',
16+
'freetype',
17+
'setuptools'
18+
]
19+
patches = [
20+
join('patches', 'fix-docstring.patch'),
21+
join('patches', 'fix-setup.patch')
22+
]
23+
24+
call_hostpython_via_targetpython = False
25+
26+
def get_recipe_env(self, arch=None):
27+
env = super(PillowRecipe, self).get_recipe_env(arch)
28+
py_ver = self.ctx.python_recipe.version[0:3]
29+
30+
ndk_dir = self.ctx.ndk_platform
31+
ndk_lib_dir = join(ndk_dir, 'usr', 'lib')
32+
ndk_include_dir = (join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include')
33+
if py_ver == '2.7' else join(ndk_dir, 'usr', 'include'))
34+
35+
png = self.get_recipe('png', self.ctx)
36+
png_lib_dir = png.get_lib_dir(arch)
37+
png_jni_dir = png.get_jni_dir(arch)
38+
39+
jpeg = self.get_recipe('jpeg', self.ctx)
40+
jpeg_lib_dir = jpeg.get_lib_dir(arch)
41+
jpeg_jni_dir = jpeg.get_jni_dir(arch)
42+
43+
env['JPEG_ROOT'] = '{}|{}'.format(jpeg_lib_dir, jpeg_jni_dir)
44+
env['ZLIB_ROOT'] = '{}|{}'.format(ndk_lib_dir, ndk_include_dir)
45+
46+
cflags = ' -nostdinc'
47+
cflags += ' -I{} -L{}'.format(png_jni_dir, png_lib_dir)
48+
cflags += ' -I{} -L{}'.format(jpeg_jni_dir, jpeg_lib_dir)
49+
cflags += ' -I{} -L{}'.format(ndk_include_dir, ndk_lib_dir)
50+
51+
gcc_lib = (shprint(sh.gcc, '-print-libgcc-file-name')
52+
.stdout.decode('utf-8').split('\n')[0])
53+
gcc_include = join(dirname(gcc_lib), 'include')
54+
cflags += ' -I{}'.format(gcc_include)
55+
56+
if self.ctx.ndk == 'crystax':
57+
py_inc_dir = join(self.ctx.ndk_dir, 'sources', 'python', py_ver,
58+
'include', 'python')
59+
py_lib_dir = join(self.ctx.ndk_dir, 'sources', 'python', py_ver,
60+
'libs', arch.arch)
61+
cflags += ' -I{}'.format(py_inc_dir)
62+
env['LDFLAGS'] += ' -L{} -lpython{}m'.format(py_lib_dir, py_ver)
63+
64+
env['LDFLAGS'] += ' {} -L{}'.format(env['CFLAGS'], self.ctx.libs_dir)
65+
if cflags not in env['CFLAGS']:
66+
env['CFLAGS'] += cflags
67+
env['LDSHARED'] = '{} {}'.format(env['CC'],
68+
'-pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions')
69+
return env
70+
71+
72+
recipe = PillowRecipe()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/src/PIL/__init__.py b/src/PIL/__init__.py
2+
index a07280e..6b9fe99 100644
3+
--- a/src/PIL/__init__.py
4+
+++ b/src/PIL/__init__.py
5+
@@ -24,7 +24,7 @@ PILLOW_VERSION = __version__ = _version.__version__
6+
7+
del _version
8+
9+
-__doc__ = __doc__.format(__version__) # include version in docstring
10+
+__doc__ = ''
11+
12+
13+
_plugins = ['BlpImagePlugin',
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
diff --git a/setup.py b/setup.py
2+
index 761d552..4ddc598 100755
3+
--- a/setup.py
4+
+++ b/setup.py
5+
@@ -136,12 +136,12 @@ except (ImportError, OSError):
6+
7+
NAME = 'Pillow'
8+
PILLOW_VERSION = get_version()
9+
-JPEG_ROOT = None
10+
+JPEG_ROOT = tuple(os.environ['JPEG_ROOT'].split('|')) if 'JPEG_ROOT' in os.environ else None
11+
JPEG2K_ROOT = None
12+
-ZLIB_ROOT = None
13+
+ZLIB_ROOT = tuple(os.environ['ZLIB_ROOT'].split('|')) if 'ZLIB_ROOT' in os.environ else None
14+
IMAGEQUANT_ROOT = None
15+
TIFF_ROOT = None
16+
-FREETYPE_ROOT = None
17+
+FREETYPE_ROOT = tuple(os.environ['FREETYPE_ROOT'].split('|')) if 'FREETYPE_ROOT' in os.environ else None
18+
LCMS_ROOT = None
19+
20+
21+
@@ -194,7 +194,7 @@ class pil_build_ext(build_ext):
22+
]
23+
24+
def initialize_options(self):
25+
- self.disable_platform_guessing = None
26+
+ self.disable_platform_guessing = True
27+
build_ext.initialize_options(self)
28+
for x in self.feature:
29+
setattr(self, 'disable_%s' % x, None)
30+
@@ -466,61 +466,6 @@ class pil_build_ext(build_ext):
31+
feature.jpeg = "libjpeg" # alternative name
32+
33+
feature.openjpeg_version = None
34+
- if feature.want('jpeg2000'):
35+
- _dbg('Looking for jpeg2000')
36+
- best_version = None
37+
- best_path = None
38+
-
39+
- # Find the best version
40+
- for directory in self.compiler.include_dirs:
41+
- _dbg('Checking for openjpeg-#.# in %s', directory)
42+
- try:
43+
- listdir = os.listdir(directory)
44+
- except Exception:
45+
- # WindowsError, FileNotFoundError
46+
- continue
47+
- for name in listdir:
48+
- if name.startswith('openjpeg-') and \
49+
- os.path.isfile(os.path.join(directory, name,
50+
- 'openjpeg.h')):
51+
- _dbg('Found openjpeg.h in %s/%s', (directory, name))
52+
- version = tuple(int(x) for x in name[9:].split('.'))
53+
- if best_version is None or version > best_version:
54+
- best_version = version
55+
- best_path = os.path.join(directory, name)
56+
- _dbg('Best openjpeg version %s so far in %s',
57+
- (best_version, best_path))
58+
-
59+
- if best_version and _find_library_file(self, 'openjp2'):
60+
- # Add the directory to the include path so we can include
61+
- # <openjpeg.h> rather than having to cope with the versioned
62+
- # include path
63+
- # FIXME (melvyn-sopacua):
64+
- # At this point it's possible that best_path is already in
65+
- # self.compiler.include_dirs. Should investigate how that is
66+
- # possible.
67+
- _add_directory(self.compiler.include_dirs, best_path, 0)
68+
- feature.jpeg2000 = 'openjp2'
69+
- feature.openjpeg_version = '.'.join(str(x) for x in best_version)
70+
-
71+
- if feature.want('imagequant'):
72+
- _dbg('Looking for imagequant')
73+
- if _find_include_file(self, 'libimagequant.h'):
74+
- if _find_library_file(self, "imagequant"):
75+
- feature.imagequant = "imagequant"
76+
- elif _find_library_file(self, "libimagequant"):
77+
- feature.imagequant = "libimagequant"
78+
-
79+
- if feature.want('tiff'):
80+
- _dbg('Looking for tiff')
81+
- if _find_include_file(self, 'tiff.h'):
82+
- if _find_library_file(self, "tiff"):
83+
- feature.tiff = "tiff"
84+
- if sys.platform == "win32" and _find_library_file(self, "libtiff"):
85+
- feature.tiff = "libtiff"
86+
- if (sys.platform == "darwin" and
87+
- _find_library_file(self, "libtiff")):
88+
- feature.tiff = "libtiff"
89+
90+
if feature.want('freetype'):
91+
_dbg('Looking for freetype')
92+
@@ -546,36 +491,6 @@ class pil_build_ext(build_ext):
93+
if subdir:
94+
_add_directory(self.compiler.include_dirs, subdir, 0)
95+
96+
- if feature.want('lcms'):
97+
- _dbg('Looking for lcms')
98+
- if _find_include_file(self, "lcms2.h"):
99+
- if _find_library_file(self, "lcms2"):
100+
- feature.lcms = "lcms2"
101+
- elif _find_library_file(self, "lcms2_static"):
102+
- # alternate Windows name.
103+
- feature.lcms = "lcms2_static"
104+
-
105+
- if feature.want('webp'):
106+
- _dbg('Looking for webp')
107+
- if (_find_include_file(self, "webp/encode.h") and
108+
- _find_include_file(self, "webp/decode.h")):
109+
- # In Google's precompiled zip it is call "libwebp":
110+
- if _find_library_file(self, "webp"):
111+
- feature.webp = "webp"
112+
- elif _find_library_file(self, "libwebp"):
113+
- feature.webp = "libwebp"
114+
-
115+
- if feature.want('webpmux'):
116+
- _dbg('Looking for webpmux')
117+
- if (_find_include_file(self, "webp/mux.h") and
118+
- _find_include_file(self, "webp/demux.h")):
119+
- if (_find_library_file(self, "webpmux") and
120+
- _find_library_file(self, "webpdemux")):
121+
- feature.webpmux = "webpmux"
122+
- if (_find_library_file(self, "libwebpmux") and
123+
- _find_library_file(self, "libwebpdemux")):
124+
- feature.webpmux = "libwebpmux"
125+
-
126+
for f in feature:
127+
if not getattr(feature, f) and feature.require(f):
128+
if f in ('jpeg', 'zlib'):
129+
@@ -612,8 +527,6 @@ class pil_build_ext(build_ext):
130+
defs.append(("HAVE_LIBTIFF", None))
131+
if sys.platform == "win32":
132+
libs.extend(["kernel32", "user32", "gdi32"])
133+
- if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1:
134+
- defs.append(("WORDS_BIGENDIAN", None))
135+
136+
if sys.platform == "win32" and not (PLATFORM_PYPY or PLATFORM_MINGW):
137+
defs.append(("PILLOW_VERSION", '"\\"%s\\""' % PILLOW_VERSION))
138+
@@ -658,10 +571,6 @@ class pil_build_ext(build_ext):
139+
define_macros=defs))
140+
141+
tk_libs = ['psapi'] if sys.platform == 'win32' else []
142+
- exts.append(Extension("PIL._imagingtk",
143+
- ["src/_imagingtk.c", "src/Tk/tkImaging.c"],
144+
- include_dirs=['src/Tk'],
145+
- libraries=tk_libs))
146+
147+
exts.append(Extension("PIL._imagingmath", ["src/_imagingmath.c"]))
148+
exts.append(Extension("PIL._imagingmorph", ["src/_imagingmorph.c"]))

pythonforandroid/recipes/setuptools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class SetuptoolsRecipe(PythonRecipe):
5-
version = '18.3.1'
5+
version = '40.0.0'
66
url = 'https://pypi.python.org/packages/source/s/setuptools/setuptools-{version}.zip'
77

88
depends = [('python2', 'python3crystax')]

0 commit comments

Comments
 (0)