Skip to content

Commit

Permalink
Merge pull request #25 from uploadcare/update-libs
Browse files Browse the repository at this point in the history
Update libs
  • Loading branch information
homm authored Aug 19, 2024
2 parents 3a16d3a + 15f7b28 commit 6b84085
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 37 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/Check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ on: [push]

jobs:
check:
name: py${{ matrix.python }} pillow-${{ matrix.pillow }} pyheif-${{ matrix.pyheif }}
name: py${{ matrix.python }} pillow-${{ matrix.pillow }} libheif-${{ matrix.libheif }} pyheif-${{ matrix.pyheif }}
runs-on: ubuntu-20.04
timeout-minutes: 3
strategy:
matrix:
python: ['3.8', '3.11']
pillow: [prod, latest]
pyheif: [prod, latest]
libheif: ['1.16.2-6ee6762-3f6b709', '1.18.2-bf35e9e-47f4fc0']
pyheif: ['', '0.7.1']
exclude:
- python: '3.11'
pyheif: '0.7.1'
- libheif: '1.18.2-bf35e9e-47f4fc0'
pyheif: '0.7.1'

steps:
- uses: actions/checkout@v2
Expand All @@ -20,17 +26,23 @@ jobs:
- name: Install system dependencies
run: |
BUCKET=https://uploadcare-packages.s3.amazonaws.com
curl -fLO $BUCKET/libheif/libheif-uc_1.16.2-6ee6762-3f6b709_$(dpkg --print-architecture).deb
curl -fLO $BUCKET/libheif/libheif-uc_${{ matrix.libheif }}_$(dpkg --print-architecture).deb
sudo dpkg -i *.deb && rm *.deb
sudo apt install --no-install-recommends -y libjpeg-dev
- name: Update pip
run: pip install pip==23.2.1
- name: Install dependencies
run: make install-pyheif-${{ matrix.pyheif }}-pillow-${{ matrix.pillow }}
run: make install-pillow-${{ matrix.pillow }}
- name: Install ovsolete pyheif
if: ${{ matrix.pyheif }}
run: |
pip uninstall -y pyheif
pip install pyheif==${{ matrix.pyheif }}
- name: Check
run: make check
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __pycache__
/coverage.xml
/.coverage
*.egg-info
/build
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked set -ex \
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked set -ex \
&& apt-get install --no-install-recommends -y \
python3-dev libpng-dev libjpeg-dev \
&& pip install --no-cache-dir -U pip
&& pip install --no-cache-dir -U pip setuptools

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked set -ex \
&& BUCKET=https://uploadcare-packages.s3.amazonaws.com \
&& curl -fLO $BUCKET/libheif/libheif-uc_1.16.2-6ee6762-3f6b709_$(dpkg --print-architecture).deb \
&& curl -fLO $BUCKET/libheif/libheif-uc_1.18.2-bf35e9e-47f4fc0_$(dpkg --print-architecture).deb \
&& dpkg -i *.deb \
&& rm *.deb
13 changes: 10 additions & 3 deletions HeifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ def check_heif_magic(data):
return pyheif.check(data) != pyheif.heif_filetype_no


is_buggy_la_mode = '1.17.0' <= pyheif.libheif_version() <= '1.18.2'


def _save(im, fp, filename):
# Save it before subsequent im.save() call
info = im.encoderinfo
Expand All @@ -174,10 +177,14 @@ def _save(im, fp, filename):
# disbled due to errors in libheif encoder
raise IOError("cannot write mode P as HEIF")

if im.mode == '1':
# to circumvent `heif-enc` bug
im = im.convert('L')

if im.mode == 'LA' and is_buggy_la_mode:
im = im.convert('RGBA')

with tempfile.NamedTemporaryFile(suffix='.png') as tmpfile:
if im.mode == '1':
# to circumvent `heif-enc` bug
im = im.convert('L')
im.save(
tmpfile, format='PNG', optimize=False, compress_level=0,
icc_profile=info.get('icc_profile', im.info.get('icc_profile')),
Expand Down
36 changes: 15 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean lint commit check
.PHONY: clean lint commit check docker_build docker_shell

xargs=$(if $(shell xargs -r </dev/null 2>/dev/null && echo 1), xargs -r, xargs)

Expand All @@ -8,36 +8,30 @@ clean:

lint: clean
isort --diff HeifImagePlugin.py ./tests
pycodestyle HeifImagePlugin.py ./tests
flake8 HeifImagePlugin.py ./tests

GIT_DIFF=git diff --name-only --cached --diff-filter=dt
commit:
${GIT_DIFF} -- '*.py' | $(xargs) isort --diff
${GIT_DIFF} -- '*.py' | $(xargs) pycodestyle
${GIT_DIFF} -- '*.py' | $(xargs) flake8

check: clean
pytest --cov=. --cov-report=xml tests

docker_build:
docker build --platform=linux/amd64 -t heif-image-plugin:latest .

.PHONY: install-pyheif-latest-pillow-latest
install-pyheif-latest-pillow-latest:
pip install --use-deprecated=legacy-resolver .[test]
docker_shell: docker_build
docker run --platform=linux/amd64 --rm -it -v .:/src heif-image-plugin:latest

.PHONY: install-pyheif-latest-pillow-prod
install-pyheif-latest-pillow-prod:
pip install --use-deprecated=legacy-resolver .[test] \
-e git+https://github.com/uploadcare/pillow-simd.git@simd/6.0-tiff-double-free#egg=pillow
.PHONY: install-pillow-latest
install-pillow-latest:
pip install .[test] \
git+https://github.com/uploadcare/pyheif.git@v0.8.0-transforms#egg=pyheif


.PHONY: install-pyheif-prod-pillow-latest
install-pyheif-prod-pillow-latest:
pip install --use-deprecated=legacy-resolver .[test] \
-e git+https://github.com/uploadcare/pyheif.git@read-transformations#egg=pyheif

.PHONY: install-pyheif-prod-pillow-prod
install-pyheif-prod-pillow-prod:
pip install --use-deprecated=legacy-resolver .[test] \
-e git+https://github.com/uploadcare/pillow-simd.git@simd/6.0-tiff-double-free#egg=pillow \
-e git+https://github.com/uploadcare/pyheif.git@read-transformations#egg=pyheif
.PHONY: install-pillow-prod
install-pillow-prod:
pip install .[test] \
./pip-stubs/pillow \
git+https://github.com/uploadcare/pillow-simd.git@simd/9.5-png-truncated#egg=pillow-simd \
git+https://github.com/uploadcare/[email protected]#egg=pyheif
9 changes: 9 additions & 0 deletions pip-stubs/pillow/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python
import setuptools


setuptools.setup(
name="pillow",
version="10.0.0",
packages=[],
)
5 changes: 2 additions & 3 deletions requirements-lint.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
isort>=5.0.0
pycodestyle>=2.5.0
flake8>=3.9.0
isort>=5.13.2
flake8>=5.0.4
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
],
extras_require={
'test': [
'pillow>=6.0.0',
'pytest>=4.6.5',
'pytest-cov>=2.8.1',
'pillow>=9.0.0',
'pytest>=8.3.2',
'pytest-cov>=5.0.0',
]
},
classifiers=[
Expand Down

0 comments on commit 6b84085

Please sign in to comment.