summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile79
-rw-r--r--debian/changelog7
-rw-r--r--debian/patches/Fix-palette-handling-for-Pillow-9.1.0.patch46
-rw-r--r--debian/patches/series1
-rw-r--r--docs/release_notes.rst11
-rw-r--r--pyproject.toml6
-rw-r--r--setup.py43
-rw-r--r--src/pikepdf/models/_transcoding.py9
-rw-r--r--tests/test_image_access.py3
10 files changed, 158 insertions, 48 deletions
diff --git a/.gitignore b/.gitignore
index 6394a3a..e68d749 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,7 @@ coverage/
pip-wheel-metadata/
src/vendor/qpdf/
wheelhouse/
+unpacked/
# Main directory testing
/*.pdf
diff --git a/Makefile b/Makefile
index 6251c17..846c06a 100644
--- a/Makefile
+++ b/Makefile
@@ -38,25 +38,48 @@ clean: clean-coverage
test: build
pytest -n auto
+# Reminder to not indent if clauses, because Makefile...
+ifdef SETUPTOOLS_SCM_PRETEND_VERSION
+$(info Using version from SETUPTOOLS_SCM_PRETEND_VERSION ${SETUPTOOLS_SCM_PRETEND_VERSION})
+version := ${SETUPTOOLS_SCM_PRETEND_VERSION}
+else
+$(info Using version from git describe)
version := $(subst v,,$(shell git describe --tags))
-macwheel39 := pikepdf-$(version)-cp39-cp39-macosx_11_0_arm64.whl
-macwheel310 := pikepdf-$(version)-cp310-cp310-macosx_11_0_arm64.whl
-#$(info $$version is [${version}])
-#$(info $$macwheel is [${macwheel}])
-
-wheelhouse/$(macwheel39): clean pip-install-e
+endif
+
+ifndef MACOSX_DEPLOYMENT_TARGET
+$(info Setting MACOSX_DEPLOYMENT_TARGET to default of 11.0)
+MACOSX_DEPLOYMENT_TARGET=11.0
+endif
+underscored_target := $(subst .,_,${MACOSX_DEPLOYMENT_TARGET})
+$(info $$underscored_target is ${underscored_target})
+
+$(info Version of wheels will be: ${version})
+macwheel39 := pikepdf-$(version)-cp39-cp39-macosx_${underscored_target}_arm64.whl
+macwheel310 := pikepdf-$(version)-cp310-cp310-macosx_${underscored_target}_arm64.whl
+$(info $$macwheel39 is ${macwheel39})
+$(info $$macwheel310 is ${macwheel310})
+
+wheelhouse/$(macwheel39): clean
rm -f wheelhouse/pikepdf*cp39*.whl
- python -m pip wheel -w wheelhouse .
+ rm -rf .venv39
+ /opt/homebrew/bin/python3.9 -m venv .venv39
+ ( \
+ source .venv39/bin/activate; \
+ python -m pip install --upgrade setuptools pip wheel; \
+ python -m pip install .; \
+ python -m pip wheel -w wheelhouse .; \
+ )
mv wheelhouse/pikepdf*cp39*.whl wheelhouse/$(macwheel39)
- rm -rf unpacked/
- python -m wheel unpack wheelhouse/$(macwheel39) --dest unpacked
- rm -f wheelhouse/$(macwheel39)
- install_name_tool -change /usr/local/lib/libqpdf.28.dylib \
- /Users/jb/src/qpdf/libqpdf/build/.libs/libqpdf.28.dylib \
- unpacked/pikepdf-*/pikepdf/_qpdf.cpython*.so
- python -m wheel pack unpacked/pikepdf-*/ --dest-dir wheelhouse
- rm -rf unpacked/
+ # rm -rf unpacked/
+ # python -m wheel unpack wheelhouse/$(macwheel39) --dest unpacked
+ # rm -f wheelhouse/$(macwheel39)
+ # install_name_tool -change /usr/local/lib/libqpdf.28.dylib \
+ # /Users/jb/src/qpdf/libqpdf/build/.libs/libqpdf.28.dylib \
+ # unpacked/pikepdf-*/pikepdf/_qpdf.cpython*.so
+ # python -m wheel pack unpacked/pikepdf-*/ --dest-dir wheelhouse
+ # rm -rf unpacked/
wheelhouse/$(macwheel310): clean
@@ -71,14 +94,14 @@ wheelhouse/$(macwheel310): clean
)
mv wheelhouse/pikepdf*cp310*.whl wheelhouse/$(macwheel310)
- rm -rf unpacked/
- python -m wheel unpack wheelhouse/$(macwheel310) --dest unpacked
- rm -f wheelhouse/$(macwheel310)
- install_name_tool -change /usr/local/lib/libqpdf.28.dylib \
- /Users/jb/src/qpdf/libqpdf/build/.libs/libqpdf.28.dylib \
- unpacked/pikepdf-*/pikepdf/_qpdf.cpython*.so
- python -m wheel pack unpacked/pikepdf-*/ --dest-dir wheelhouse
- rm -rf unpacked/
+ # rm -rf unpacked/
+ # python -m wheel unpack wheelhouse/$(macwheel310) --dest unpacked
+ # rm -f wheelhouse/$(macwheel310)
+ # install_name_tool -change /usr/local/lib/libqpdf.28.dylib \
+ # /Users/jb/src/qpdf/libqpdf/build/.libs/libqpdf.28.dylib \
+ # unpacked/pikepdf-*/pikepdf/_qpdf.cpython*.so
+ # python -m wheel pack unpacked/pikepdf-*/ --dest-dir wheelhouse
+ # rm -rf unpacked/
wheelhouse/delocated/$(macwheel39): wheelhouse/$(macwheel39)
delocate-wheel -w wheelhouse/delocated -v wheelhouse/$(macwheel39)
@@ -86,8 +109,16 @@ wheelhouse/delocated/$(macwheel39): wheelhouse/$(macwheel39)
wheelhouse/delocated/$(macwheel310): wheelhouse/$(macwheel310)
delocate-wheel -w wheelhouse/delocated -v wheelhouse/$(macwheel310)
+.PHONY: macwheel39
+macwheel39: wheelhouse/delocated/$(macwheel39)
+ -
+
+.PHONY: macwheel310
+macwheel310: wheelhouse/delocated/$(macwheel310)
+ -
+
.PHONY: apple-silicon-wheels
-apple-silicon-wheels: wheelhouse/delocated/$(macwheel310) wheelhouse/delocated/$(macwheel39)
+apple-silicon-wheels: wheelhouse/delocated/$(macwheel39) wheelhouse/delocated/$(macwheel310)
twine upload wheelhouse/delocated/$(macwheel39) wheelhouse/delocated/$(macwheel310)
.PHONY: pycov
diff --git a/debian/changelog b/debian/changelog
index 8031f76..53cbeef 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+pikepdf (5.1.1+dfsg-1) unstable; urgency=medium
+
+ * New upstream release.
+ * Cherry-pick upstream commit 4f6923f (Closes: #1009737).
+
+ -- Sean Whitton <spwhitton@spwhitton.name> Fri, 15 Apr 2022 14:49:08 -0700
+
pikepdf (5.0.1+dfsg-1) unstable; urgency=medium
* New upstream release.
diff --git a/debian/patches/Fix-palette-handling-for-Pillow-9.1.0.patch b/debian/patches/Fix-palette-handling-for-Pillow-9.1.0.patch
new file mode 100644
index 0000000..e74a180
--- /dev/null
+++ b/debian/patches/Fix-palette-handling-for-Pillow-9.1.0.patch
@@ -0,0 +1,46 @@
+From: "James R. Barlow" <james@purplerock.ca>
+Date: Fri, 15 Apr 2022 00:58:07 -0700
+Subject: Fix palette handling for Pillow 9.1.0
+
+(cherry picked from commit 4f6923fe33c2d7e78d1482a5eb2beb6e9155977b)
+---
+ src/pikepdf/models/_transcoding.py | 9 ++++-----
+ tests/test_image_access.py | 3 ++-
+ 2 files changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/src/pikepdf/models/_transcoding.py b/src/pikepdf/models/_transcoding.py
+index 7e26381..1bfc3d1 100644
+--- a/src/pikepdf/models/_transcoding.py
++++ b/src/pikepdf/models/_transcoding.py
+@@ -163,13 +163,12 @@ def fix_1bit_palette_image(
+ im: Image.Image, base_mode: str, palette: BytesLike
+ ) -> Image.Image:
+ """Apply palettes to 1-bit images."""
+- if base_mode == 'RGB' and palette != b'\x00\x00\x00\xff\xff\xff':
++ if base_mode == 'RGB':
+ im = im.convert('P')
++ if len(palette) == 6:
++ # rgbrgb -> rgb000000...rgb
++ palette = palette[0:3] + (b'\x00\x00\x00' * (256 - 2)) + palette[3:6]
+ im.putpalette(palette, rawmode=base_mode)
+- gp = im.getpalette()
+- if gp:
+- gp[765:768] = gp[3:6] # work around Pillow bug
+- im.putpalette(gp)
+ elif base_mode == 'L' and palette != b'\x00\xff':
+ im = im.convert('P')
+ try:
+diff --git a/tests/test_image_access.py b/tests/test_image_access.py
+index 512c2ca..11a3b97 100644
+--- a/tests/test_image_access.py
++++ b/tests/test_image_access.py
+@@ -516,7 +516,8 @@ def test_image_palette(resources, filename, bpc, rgb):
+ outstream = BytesIO()
+ pim.extract_to(stream=outstream)
+
+- im = pim.as_pil_image().convert('RGB')
++ im_pal = pim.as_pil_image()
++ im = im_pal.convert('RGB')
+ assert im.getpixel((1, 1)) == rgb
+
+
diff --git a/debian/patches/series b/debian/patches/series
index 887982c..93e1509 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,4 @@
docs-build-use-DEB_VERSION_UPSTREAM.patch
drop-installation-from-docs-contents.patch
drop-save-pike.patch
+Fix-palette-handling-for-Pillow-9.1.0.patch
diff --git a/docs/release_notes.rst b/docs/release_notes.rst
index e0d7bd6..ebdaa6f 100644
--- a/docs/release_notes.rst
+++ b/docs/release_notes.rst
@@ -18,6 +18,17 @@ is in production use. Note that the C++ extension module
``pikepdf._qpdf`` is a private interface within pikepdf that applications
should not access directly, along with any modules with a prefixed underscore.
+v5.1.1
+======
+
+- Fixes to pyproject.toml to support PEP-621 changes.
+
+v5.1.0
+======
+
+- Rebuild against QPDF 10.6.3.
+- Improvements to Makefile for Apple Silicon wheels.
+
v5.0.1
======
diff --git a/pyproject.toml b/pyproject.toml
index 9ca8d07..385f2f7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,5 +1,7 @@
[project]
-requires-python = ">=3.7"
+name = "pikepdf"
+requires-python = "~=3.7"
+dynamic = ['version']
[build-system]
requires = [
@@ -42,7 +44,7 @@ test-skip = "*_arm64 *_universal2:arm64"
[tool.cibuildwheel.environment]
QPDF_MIN_VERSION = "10.6.2"
-QPDF_VERSION = "10.6.2"
+QPDF_VERSION = "10.6.3"
QPDF_PATTERN = "https://github.com/qpdf/qpdf/releases/download/release-qpdf-VERSION/qpdf-VERSION.tar.gz"
JPEG_RELEASE = "https://www.ijg.org/files/jpegsrc.v9d.tar.gz"
ZLIB_RELEASE = "https://www.zlib.net/zlib-1.2.11.tar.gz"
diff --git a/setup.py b/setup.py
index e0072c2..f7ae786 100644
--- a/setup.py
+++ b/setup.py
@@ -3,6 +3,7 @@ from glob import glob
from itertools import chain
from os import environ
from os.path import exists, join
+from platform import machine
from typing import cast
from pybind11.setup_helpers import ParallelCompile, Pybind11Extension, build_ext
@@ -11,12 +12,22 @@ from setuptools import Extension, setup
extra_includes = []
extra_library_dirs = []
qpdf_source_tree = environ.get('QPDF_SOURCE_TREE', '')
-if qpdf_source_tree:
- # Point this to qpdf source tree built with shared libaries
- extra_includes.append(join(qpdf_source_tree, 'include'))
- extra_library_dirs.append(join(qpdf_source_tree, 'libqpdf/build/.libs'))
-if 'bsd' in sys.platform:
- extra_includes.append('/usr/local/include')
+
+# If CFLAGS is defined, disable any efforts to shim the build, because
+# the caller is probably a maintainer and knows what they are doing.
+cflags_defined = bool(environ.get('CFLAGS', ''))
+
+if not cflags_defined:
+ if qpdf_source_tree:
+ # Point this to qpdf source tree built with shared libaries
+ extra_includes.append(join(qpdf_source_tree, 'include'))
+ extra_library_dirs.append(join(qpdf_source_tree, 'libqpdf/build/.libs'))
+
+ if 'bsd' in sys.platform:
+ extra_includes.append('/usr/local/include')
+ elif 'darwin' in sys.platform and machine() == 'arm64':
+ extra_includes.append('/opt/homebrew/include')
+ extra_library_dirs.append('/opt/homebrew/lib')
try:
from setuptools_scm import get_version
@@ -48,18 +59,18 @@ extmodule: Extension = cast(
),
)
-if sys.platform == 'cygwin':
- # On cygwin, use gnu++17 instead of c++17
- eca = extmodule.extra_compile_args
- eca[eca.index('-std=c++17')] = '-std=gnu++17'
-
-# Debug build
-# module[0].extra_compile_args.append('-g3')
+if not cflags_defined:
+ if sys.platform == 'cygwin':
+ # On cygwin, use gnu++17 instead of c++17
+ eca = extmodule.extra_compile_args
+ eca[eca.index('-std=c++17')] = '-std=gnu++17'
-if qpdf_source_tree:
- for lib in extra_library_dirs:
- extmodule.extra_link_args.append(f'-Wl,-rpath,{lib}') # type: ignore
+ # Debug build
+ # module[0].extra_compile_args.append('-g3')
+ if qpdf_source_tree:
+ for lib in extra_library_dirs:
+ extmodule.extra_link_args.append(f'-Wl,-rpath,{lib}') # type: ignore
if __name__ == '__main__':
with ParallelCompile("PIKEPDF_NUM_BUILD_JOBS"): # optional envvar
diff --git a/src/pikepdf/models/_transcoding.py b/src/pikepdf/models/_transcoding.py
index 7e26381..1bfc3d1 100644
--- a/src/pikepdf/models/_transcoding.py
+++ b/src/pikepdf/models/_transcoding.py
@@ -163,13 +163,12 @@ def fix_1bit_palette_image(
im: Image.Image, base_mode: str, palette: BytesLike
) -> Image.Image:
"""Apply palettes to 1-bit images."""
- if base_mode == 'RGB' and palette != b'\x00\x00\x00\xff\xff\xff':
+ if base_mode == 'RGB':
im = im.convert('P')
+ if len(palette) == 6:
+ # rgbrgb -> rgb000000...rgb
+ palette = palette[0:3] + (b'\x00\x00\x00' * (256 - 2)) + palette[3:6]
im.putpalette(palette, rawmode=base_mode)
- gp = im.getpalette()
- if gp:
- gp[765:768] = gp[3:6] # work around Pillow bug
- im.putpalette(gp)
elif base_mode == 'L' and palette != b'\x00\xff':
im = im.convert('P')
try:
diff --git a/tests/test_image_access.py b/tests/test_image_access.py
index 512c2ca..11a3b97 100644
--- a/tests/test_image_access.py
+++ b/tests/test_image_access.py
@@ -516,7 +516,8 @@ def test_image_palette(resources, filename, bpc, rgb):
outstream = BytesIO()
pim.extract_to(stream=outstream)
- im = pim.as_pil_image().convert('RGB')
+ im_pal = pim.as_pil_image()
+ im = im_pal.convert('RGB')
assert im.getpixel((1, 1)) == rgb