Skip to content

Commit

Permalink
Merge pull request #3022 from T-Dynamos/pillow-update
Browse files Browse the repository at this point in the history
pillow: update to `10.3.0`
  • Loading branch information
AndreMiras authored May 25, 2024
2 parents 9e467a5 + 3d69b69 commit 5dc17e1
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 234 deletions.
51 changes: 13 additions & 38 deletions pythonforandroid/recipes/Pillow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from os.path import join

from pythonforandroid.recipe import CompiledComponentsPythonRecipe
from pythonforandroid.recipe import PyProjectRecipe


class PillowRecipe(CompiledComponentsPythonRecipe):
class PillowRecipe(PyProjectRecipe):
"""
A recipe for Pillow (previously known as Pil).
Expand All @@ -23,67 +23,42 @@ class PillowRecipe(CompiledComponentsPythonRecipe):
- libwebp: library to encode and decode images in WebP format.
"""

version = '8.4.0'
version = '10.3.0'
url = 'https://github.com/python-pillow/Pillow/archive/{version}.tar.gz'
site_packages_name = 'PIL'
patches = ["setup.py.patch"]
depends = ['png', 'jpeg', 'freetype', 'setuptools']
opt_depends = ['libwebp']
patches = [join('patches', 'fix-setup.patch')]

call_hostpython_via_targetpython = False

def get_recipe_env(self, arch=None, with_flags_in_cc=True):
env = super().get_recipe_env(arch, with_flags_in_cc)

png = self.get_recipe('png', self.ctx)
png_lib_dir = join(png.get_build_dir(arch.arch), '.libs')
png_inc_dir = png.get_build_dir(arch)
def get_recipe_env(self, arch, **kwargs):
env = super().get_recipe_env(arch, **kwargs)

jpeg = self.get_recipe('jpeg', self.ctx)
jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch)
env["JPEG_ROOT"] = "{}:{}".format(jpeg_lib_dir, jpeg_inc_dir)

freetype = self.get_recipe('freetype', self.ctx)
free_lib_dir = join(freetype.get_build_dir(arch.arch), 'objs', '.libs')
free_inc_dir = join(freetype.get_build_dir(arch.arch), 'include')
env["FREETYPE_ROOT"] = "{}:{}".format(free_lib_dir, free_inc_dir)

# harfbuzz is a direct dependency of freetype and we need the proper
# flags to successfully build the Pillow recipe, so we add them here.
harfbuzz = self.get_recipe('harfbuzz', self.ctx)
harf_lib_dir = join(harfbuzz.get_build_dir(arch.arch), 'src', '.libs')
harf_inc_dir = harfbuzz.get_build_dir(arch.arch)
env["HARFBUZZ_ROOT"] = "{}:{}".format(harf_lib_dir, harf_inc_dir)

env["ZLIB_ROOT"] = f"{arch.ndk_lib_dir_versioned}:{self.ctx.ndk.sysroot_include_dir}"

# libwebp is an optional dependency, so we add the
# flags if we have it in our `ctx.recipe_build_order`
build_with_webp_support = 'libwebp' in self.ctx.recipe_build_order
if build_with_webp_support:
if 'libwebp' in self.ctx.recipe_build_order:
webp = self.get_recipe('libwebp', self.ctx)
webp_install = join(
webp.get_build_dir(arch.arch), 'installation'
)

# Add libraries includes to CFLAGS
cflags = f' -I{png_inc_dir}'
cflags += f' -I{harf_inc_dir} -I{join(harf_inc_dir, "src")}'
cflags += f' -I{free_inc_dir}'
cflags += f' -I{jpeg_inc_dir}'
if build_with_webp_support:
cflags += f' -I{join(webp_install, "include")}'
cflags += f' -I{self.ctx.ndk.sysroot_include_dir}'

# Link the basic Pillow libraries...no need to add webp's libraries
# since it seems that the linkage is properly made without it :)
env['LIBS'] = ' -lpng -lfreetype -lharfbuzz -ljpeg -lturbojpeg -lm'

# Add libraries locations to LDFLAGS
env['LDFLAGS'] += f' -L{png_lib_dir}'
env['LDFLAGS'] += f' -L{free_lib_dir}'
env['LDFLAGS'] += f' -L{harf_lib_dir}'
env['LDFLAGS'] += f' -L{jpeg_lib_dir}'
if build_with_webp_support:
env['LDFLAGS'] += f' -L{join(webp_install, "lib")}'
env['LDFLAGS'] += f' -L{arch.ndk_lib_dir_versioned}'
if cflags not in env['CFLAGS']:
env['CFLAGS'] += cflags + " -lm"
env["WEBP_ROOT"] = f"{join(webp_install, 'lib')}:{join(webp_install, 'include')}"
return env


Expand Down
196 changes: 0 additions & 196 deletions pythonforandroid/recipes/Pillow/patches/fix-setup.patch

This file was deleted.

76 changes: 76 additions & 0 deletions pythonforandroid/recipes/Pillow/setup.py.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
--- Pillow/setup.py 2024-05-24 19:35:08.270160608 +0530
+++ Pillow.mod/setup.py 2024-05-24 22:07:52.741495666 +0530
@@ -39,6 +39,7 @@
LCMS_ROOT = None
TIFF_ROOT = None
ZLIB_ROOT = None
+WEBP_ROOT = None
FUZZING_BUILD = "LIB_FUZZING_ENGINE" in os.environ

if sys.platform == "win32" and sys.version_info >= (3, 13):
@@ -150,6 +151,7 @@


def _find_library_dirs_ldconfig():
+ return []
# Based on ctypes.util from Python 2

ldconfig = "ldconfig" if shutil.which("ldconfig") else "/sbin/ldconfig"
@@ -460,15 +462,16 @@
"HARFBUZZ_ROOT": "harfbuzz",
"FRIBIDI_ROOT": "fribidi",
"LCMS_ROOT": "lcms2",
+ "WEBP_ROOT": "libwebp",
"IMAGEQUANT_ROOT": "libimagequant",
}.items():
root = globals()[root_name]

if root is None and root_name in os.environ:
- prefix = os.environ[root_name]
- root = (os.path.join(prefix, "lib"), os.path.join(prefix, "include"))
+ root = tuple(os.environ[root_name].split(":"))

if root is None and pkg_config:
+ continue
if isinstance(lib_name, tuple):
for lib_name2 in lib_name:
_dbg(f"Looking for `{lib_name2}` using pkg-config.")
@@ -495,14 +498,6 @@
for include_dir in include_root:
_add_directory(include_dirs, include_dir)

- # respect CFLAGS/CPPFLAGS/LDFLAGS
- for k in ("CFLAGS", "CPPFLAGS", "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:
@@ -514,13 +509,10 @@
for d in os.environ[k].split(os.path.pathsep):
_add_directory(library_dirs, d)

- _add_directory(library_dirs, os.path.join(sys.prefix, "lib"))
- _add_directory(include_dirs, os.path.join(sys.prefix, "include"))
-
#
# add platform directories

- if self.disable_platform_guessing:
+ if True:
pass

elif sys.platform == "cygwin":
@@ -614,7 +606,7 @@
# FIXME: check /opt/stuff directories here?

# standard locations
- if not self.disable_platform_guessing:
+ if False: #not self.disable_platform_guessing:
_add_directory(library_dirs, "/usr/local/lib")
_add_directory(include_dirs, "/usr/local/include")

0 comments on commit 5dc17e1

Please sign in to comment.