|
1 | | -from os.path import join, exists |
2 | | -from pythonforandroid.recipe import CompiledComponentsPythonRecipe |
3 | | -from pythonforandroid.toolchain import shprint |
4 | | -import sh |
| 1 | +from pythonforandroid.recipes.Pillow import PillowRecipe |
| 2 | +from pythonforandroid.logger import warning |
5 | 3 |
|
6 | 4 |
|
7 | | -class PILRecipe(CompiledComponentsPythonRecipe): |
8 | | - name = 'pil' |
9 | | - version = '1.1.7' |
10 | | - url = 'http://effbot.org/downloads/Imaging-{version}.tar.gz' |
11 | | - depends = ['png', 'jpeg', 'setuptools'] |
12 | | - opt_depends = ['freetype'] |
13 | | - site_packages_name = 'PIL' |
| 5 | +class PilRecipe(PillowRecipe): |
| 6 | + """A transparent wrapper around the Pillow recipe, it should build |
| 7 | + Pillow automatically as if "pillow" were specified in the |
| 8 | + requirements. |
| 9 | + """ |
14 | 10 |
|
15 | | - patches = ['disable-tk.patch', |
16 | | - 'fix-directories.patch'] |
| 11 | + name = 'Pillow' # ensures the Pillow recipe directory is used where necessary |
17 | 12 |
|
18 | | - def get_recipe_env(self, arch=None, with_flags_in_cc=True): |
19 | | - env = super(PILRecipe, self).get_recipe_env(arch, with_flags_in_cc) |
| 13 | + conflicts = ['pillow'] |
20 | 14 |
|
21 | | - env['PYTHON_INCLUDE_ROOT'] = self.ctx.python_recipe.include_root(arch.arch) |
22 | | - env['PYTHON_LINK_ROOT'] = self.ctx.python_recipe.link_root(arch.arch) |
| 15 | + def build_arch(self, arch): |
| 16 | + warning('PIL is no longer supported, building Pillow instead. ' |
| 17 | + 'This should be a drop-in replacement.') |
| 18 | + warning('It is recommended to change "pil" to "pillow" in your requirements, ' |
| 19 | + 'to ensure future compatibility') |
| 20 | + super(PilRecipe, self).build_arch(arch) |
23 | 21 |
|
24 | | - ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib') |
25 | | - ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include') |
26 | 22 |
|
27 | | - png = self.get_recipe('png', self.ctx) |
28 | | - png_lib_dir = png.get_lib_dir(arch) |
29 | | - png_jni_dir = png.get_jni_dir(arch) |
30 | | - |
31 | | - jpeg = self.get_recipe('jpeg', self.ctx) |
32 | | - jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch) |
33 | | - |
34 | | - if 'freetype' in self.ctx.recipe_build_order: |
35 | | - freetype = self.get_recipe('freetype', self.ctx) |
36 | | - free_lib_dir = join(freetype.get_build_dir(arch.arch), 'objs', '.libs') |
37 | | - free_inc_dir = join(freetype.get_build_dir(arch.arch), 'include') |
38 | | - # hack freetype to be found by pil |
39 | | - freetype_link = join(free_inc_dir, 'freetype') |
40 | | - if not exists(freetype_link): |
41 | | - shprint(sh.ln, '-s', join(free_inc_dir), freetype_link) |
42 | | - |
43 | | - harfbuzz = self.get_recipe('harfbuzz', self.ctx) |
44 | | - harf_lib_dir = join(harfbuzz.get_build_dir(arch.arch), 'src', '.libs') |
45 | | - harf_inc_dir = harfbuzz.get_build_dir(arch.arch) |
46 | | - |
47 | | - env['FREETYPE_ROOT'] = '{}|{}'.format(free_lib_dir, free_inc_dir) |
48 | | - |
49 | | - env['JPEG_ROOT'] = '{}|{}'.format(jpeg_lib_dir, jpeg_inc_dir) |
50 | | - env['ZLIB_ROOT'] = '{}|{}'.format(ndk_lib_dir, ndk_include_dir) |
51 | | - |
52 | | - cflags = ' -std=c99' |
53 | | - cflags += ' -I{}'.format(png_jni_dir) |
54 | | - if 'freetype' in self.ctx.recipe_build_order: |
55 | | - cflags += ' -I{} -I{}'.format(harf_inc_dir, join(harf_inc_dir, 'src')) |
56 | | - cflags += ' -I{}'.format(free_inc_dir) |
57 | | - cflags += ' -I{}'.format(jpeg_inc_dir) |
58 | | - cflags += ' -I{}'.format(ndk_include_dir) |
59 | | - |
60 | | - py_v = self.ctx.python_recipe.major_minor_version_string |
61 | | - if py_v[0] == '3': |
62 | | - py_v += 'm' |
63 | | - |
64 | | - env['LIBS'] = ' -lpython{version} -lpng'.format(version=py_v) |
65 | | - if 'freetype' in self.ctx.recipe_build_order: |
66 | | - env['LIBS'] += ' -lfreetype -lharfbuzz' |
67 | | - env['LIBS'] += ' -ljpeg -lturbojpeg' |
68 | | - |
69 | | - env['LDFLAGS'] += ' -L{} -L{}'.format(env['PYTHON_LINK_ROOT'], png_lib_dir) |
70 | | - if 'freetype' in self.ctx.recipe_build_order: |
71 | | - env['LDFLAGS'] += ' -L{} -L{}'.format(harf_lib_dir, free_lib_dir) |
72 | | - env['LDFLAGS'] += ' -L{} -L{}'.format(jpeg_lib_dir, ndk_lib_dir) |
73 | | - |
74 | | - if cflags not in env['CFLAGS']: |
75 | | - env['CFLAGS'] += cflags |
76 | | - return env |
77 | | - |
78 | | - |
79 | | -recipe = PILRecipe() |
| 23 | +recipe = PilRecipe() |
0 commit comments