Files

115 lines
3.7 KiB
Ruby

class Pillow < Formula
bottle do
root_url "https://homebrew.mirror.ygg/bottles"
sha256 cellar: :any, arm64_sequoia: "3b3e8bfaa5ca2d7fc699923c86610e18c240bd8bab70e5f54bebfbdc0f7e5de1"
sha256 cellar: :any, arm64_tahoe: "368dd59ca13924d5bb3389dbc251dddc0fa4bc931f8a723cfa132ce1d31055dc"
sha256 cellar: "/home/linuxbrew/.linuxbrew/Cellar", x86_64_linux: "d7968166b5d2d7dba702ad5672f23100b47c876cfd0ef337863742894d649474"
end
desc "Friendly PIL fork (Python Imaging Library)"
homepage "https://python-pillow.github.io/"
url "https://files.pythonhosted.org/packages/1c/3d/bb7fca845737cf9d7dbde16ed1843984665ff2e0a518f5db43e77ec540b9/pillow-12.3.0.tar.gz"
sha256 "3b8182a766685eaa002637e28b4ec8d6b18819a0c71f579bf0dbaa5830297cce"
license "HPND"
compatibility_version 1
head "https://github.com/python-pillow/Pillow.git", branch: "main"
depends_on "cmake" => :build
depends_on "ninja" => :build
depends_on "pkgconf" => :build
depends_on "pybind11" => :build
depends_on "python@3.13" => [:build, :test]
depends_on "python@3.14" => [:build, :test]
depends_on "freetype"
depends_on "jpeg-turbo"
depends_on "libavif"
depends_on "libimagequant"
depends_on "libraqm"
depends_on "libtiff"
depends_on "libxcb"
depends_on "little-cms2"
depends_on "openjpeg"
depends_on "webp"
on_linux do
depends_on "zlib-ng-compat"
end
def pythons
deps.map(&:to_formula)
.select { |f| f.name.match?(/^python@\d\.\d+$/) }
.map { |f| f.opt_libexec/"bin/python" }
end
def install
ENV["MAX_CONCURRENCY"] = ENV.make_jobs.to_s
deps.each do |dep|
next if dep.build? || dep.test?
ENV.prepend "CPPFLAGS", "-I#{dep.to_formula.opt_include}"
ENV.prepend "LDFLAGS", "-L#{dep.to_formula.opt_lib}"
end
pythons.each do |python|
system python, "-m", "pip", "install", *std_pip_args(build_isolation: true),
"-C", "debug=true", # Useful in case of build failures.
"-C", "tiff=enable",
"-C", "freetype=enable",
"-C", "lcms=enable",
"-C", "webp=enable",
"-C", "xcb=enable",
"-C", "avif=enable",
"."
end
end
test do
(testpath/"test.py").write <<~PYTHON
from PIL import Image
im = Image.open("#{test_fixtures("test.jpg")}")
print(im.format, im.size, im.mode)
PYTHON
pythons.each do |python|
assert_equal "JPEG (1, 1) RGB", shell_output("#{python} test.py").chomp
end
# Test webp support
resource "test-webp" do
url "https://raw.githubusercontent.com/python-pillow/Pillow/refs/heads/main/Tests/images/flower.webp"
sha256 "af5bf1a0e420467c09d221fbfbb739646956c17f2b67f8280eacfacf87059a37"
end
testpath.install resource("test-webp")
test_webp = testpath/"flower.webp"
(testpath/"test_webp.py").write <<~PYTHON
from PIL import Image
im = Image.open("#{test_webp}")
print(im.format, im.size, im.mode)
PYTHON
pythons.each do |python|
assert_equal "WEBP (480, 360) RGB", shell_output("#{python} test_webp.py").chomp
end
# Test avif support
resource "test-avif" do
url "https://raw.githubusercontent.com/python-pillow/Pillow/refs/heads/main/Tests/images/avif/exif.avif"
sha256 "438dc63eb5aa722f4b23a93ac48cd0c19b7a575865c89e666c86b7ac363cff04"
end
testpath.install resource("test-avif")
test_avif = testpath/"exif.avif"
(testpath/"test_avif.py").write <<~PYTHON
from PIL import Image
im = Image.open("#{test_avif}")
print(im.format, im.size, im.mode)
PYTHON
pythons.each do |python|
assert_equal "AVIF (512, 512) RGB", shell_output("#{python} test_avif.py").chomp
end
end
end