Skip to content

Commit

Permalink
Merge branch 'main' into psd
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 31, 2024
2 parents c2907dc + 4a4b90c commit 2888f76
Show file tree
Hide file tree
Showing 226 changed files with 2,969 additions and 2,352 deletions.
2 changes: 1 addition & 1 deletion .ci/requirements-cibw.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cibuildwheel==2.16.2
cibuildwheel==2.16.5
12 changes: 11 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,26 @@ jobs:
with:
python-version: "3.x"
cache: pip
cache-dependency-path: ".ci/*.sh"
cache-dependency-path: |
".ci/*.sh"
"pyproject.toml"
- name: Build system information
run: python3 .github/workflows/system-info.py

- name: Cache libimagequant
uses: actions/cache@v4
id: cache-libimagequant
with:
path: ~/cache-libimagequant
key: ${{ runner.os }}-libimagequant-${{ hashFiles('depends/install_imagequant.sh') }}

- name: Install Linux dependencies
run: |
.ci/install.sh
env:
GHA_PYTHON_VERSION: "3.x"
GHA_LIBIMAGEQUANT_CACHE_HIT: ${{ steps.cache-libimagequant.outputs.cache-hit }}

- name: Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v4

- name: pre-commit cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: lint-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/macos-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

set -e

brew install libtiff libjpeg openjpeg libimagequant webp little-cms2 freetype libraqm
brew install \
freetype \
ghostscript \
libimagequant \
libjpeg \
libraqm \
libtiff \
little-cms2 \
openjpeg \
webp
export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"

# TODO Update condition when cffi supports 3.13
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test-cygwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: actions/checkout@v4

- name: Install Cygwin
uses: cygwin/cygwin-install-action@v4
uses: egor-tensin/setup-cygwin@v4
with:
platform: x86_64
packages: >
Expand All @@ -69,6 +69,7 @@ jobs:
make
netpbm
perl
python39=3.9.16-1
python3${{ matrix.python-minor-version }}-cffi
python3${{ matrix.python-minor-version }}-cython
python3${{ matrix.python-minor-version }}-devel
Expand All @@ -86,7 +87,7 @@ jobs:

- name: Select Python version
run: |
ln -sf c:/cygwin/bin/python3.${{ matrix.python-minor-version }} c:/cygwin/bin/python3
ln -sf c:/tools/cygwin/bin/python3.${{ matrix.python-minor-version }} c:/tools/cygwin/bin/python3
- name: Get latest NumPy version
id: latest-numpy
Expand All @@ -95,7 +96,7 @@ jobs:
python3 -m pip list --outdated | grep numpy | sed -r 's/ +/ /g' | cut -d ' ' -f 3 | sed 's/^/version=/' >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: 'C:\cygwin\home\runneradmin\.cache\pip'
key: ${{ runner.os }}-cygwin-pip3.${{ matrix.python-minor-version }}-numpy${{ steps.latest-numpy.outputs.version }}-${{ hashFiles('.ci/install.sh') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:

- name: Cache build
id: build-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: winbuild\build
key:
Expand Down
34 changes: 29 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
FORCE_COLOR: 1

jobs:
build:

strategy:
fail-fast: false
matrix:
os: [
"macos-latest",
"macos-14",
"ubuntu-latest",
]
python-version: [
Expand All @@ -47,11 +50,21 @@ jobs:
"3.8",
]
include:
- python-version: "3.9"
- python-version: "3.11"
PYTHONOPTIMIZE: 1
REVERSE: "--reverse"
- python-version: "3.8"
- python-version: "3.10"
PYTHONOPTIMIZE: 2
# M1 only available for 3.10+
- os: "macos-latest"
python-version: "3.9"
- os: "macos-latest"
python-version: "3.8"
exclude:
- os: "macos-14"
python-version: "3.9"
- os: "macos-14"
python-version: "3.8"

runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
Expand All @@ -65,17 +78,28 @@ jobs:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: pip
cache-dependency-path: ".ci/*.sh"
cache-dependency-path: |
".ci/*.sh"
"pyproject.toml"
- name: Build system information
run: python3 .github/workflows/system-info.py

- name: Cache libimagequant
if: startsWith(matrix.os, 'ubuntu')
uses: actions/cache@v4
id: cache-libimagequant
with:
path: ~/cache-libimagequant
key: ${{ runner.os }}-libimagequant-${{ hashFiles('depends/install_imagequant.sh') }}

- name: Install Linux dependencies
if: startsWith(matrix.os, 'ubuntu')
run: |
.ci/install.sh
env:
GHA_PYTHON_VERSION: ${{ matrix.python-version }}
GHA_LIBIMAGEQUANT_CACHE_HIT: ${{ steps.cache-libimagequant.outputs.cache-hit }}

- name: Install macOS dependencies
if: startsWith(matrix.os, 'macOS')
Expand Down Expand Up @@ -127,7 +151,7 @@ jobs:
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
flags: ${{ matrix.os == 'macos-latest' && 'GHA_macOS' || 'GHA_Ubuntu' }}
flags: ${{ matrix.os == 'ubuntu-latest' && 'GHA_Ubuntu' || 'GHA_macOS' }}
name: ${{ matrix.os }} Python ${{ matrix.python-version }}
gcov: true

Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ repos:
rev: v4.5.0
hooks:
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-json
- id: check-toml
Expand Down
12 changes: 12 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ Changelog (Pillow)
10.3.0 (unreleased)
-------------------

- Do not support using test-image-results to upload images after test failures #7739
[radarhere]

- Changed ImageMath.ops to be static #7721
[radarhere]

- Fix APNG info after seeking backwards more than twice #7701
[esoma, radarhere]

- Deprecate ImageCms constants and versions() function #7702
[nulano, radarhere]

- Added PerspectiveTransform #7699
[radarhere]

Expand Down
9 changes: 5 additions & 4 deletions Tests/bench_cffi_access.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

import time

from PIL import PyAccess
Expand All @@ -8,21 +9,21 @@
# Not running this test by default. No DOS against CI.


def iterate_get(size, access):
def iterate_get(size, access) -> None:
(w, h) = size
for x in range(w):
for y in range(h):
access[(x, y)]


def iterate_set(size, access):
def iterate_set(size, access) -> None:
(w, h) = size
for x in range(w):
for y in range(h):
access[(x, y)] = (x % 256, y % 256, 0)


def timer(func, label, *args):
def timer(func, label, *args) -> None:
iterations = 5000
starttime = time.time()
for x in range(iterations):
Expand All @@ -37,7 +38,7 @@ def timer(func, label, *args):
)


def test_direct():
def test_direct() -> None:
im = hopper()
im.load()
# im = Image.new("RGB", (2000, 2000), (1, 3, 2))
Expand Down
1 change: 0 additions & 1 deletion Tests/check_fli_oob.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from __future__ import annotations

from PIL import Image
Expand Down
3 changes: 2 additions & 1 deletion Tests/check_fli_overflow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from PIL import Image

TEST_FILE = "Tests/images/fli_overflow.fli"


def test_fli_overflow():
def test_fli_overflow() -> None:
# this should not crash with a malloc error or access violation
with Image.open(TEST_FILE) as im:
im.load()
16 changes: 11 additions & 5 deletions Tests/check_imaging_leaks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env python3
from __future__ import annotations

from typing import Any, Callable

import pytest

from PIL import Image
Expand All @@ -12,31 +15,34 @@
pytestmark = pytest.mark.skipif(is_win32(), reason="requires Unix or macOS")


def _get_mem_usage():
def _get_mem_usage() -> float:
from resource import RUSAGE_SELF, getpagesize, getrusage

mem = getrusage(RUSAGE_SELF).ru_maxrss
return mem * getpagesize() / 1024 / 1024


def _test_leak(min_iterations, max_iterations, fn, *args, **kwargs):
def _test_leak(
min_iterations: int, max_iterations: int, fn: Callable[..., None], *args: Any
) -> None:
mem_limit = None
for i in range(max_iterations):
fn(*args, **kwargs)
fn(*args)
mem = _get_mem_usage()
if i < min_iterations:
mem_limit = mem + 1
continue
msg = f"memory usage limit exceeded after {i + 1} iterations"
assert mem_limit is not None
assert mem <= mem_limit, msg


def test_leak_putdata():
def test_leak_putdata() -> None:
im = Image.new("RGB", (25, 25))
_test_leak(min_iterations, max_iterations, im.putdata, im.getdata())


def test_leak_getlist():
def test_leak_getlist() -> None:
im = Image.new("P", (25, 25))
_test_leak(
min_iterations,
Expand Down
5 changes: 3 additions & 2 deletions Tests/check_j2k_leaks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

from io import BytesIO

import pytest
Expand All @@ -19,7 +20,7 @@
]


def test_leak_load():
def test_leak_load() -> None:
from resource import RLIMIT_AS, RLIMIT_STACK, setrlimit

setrlimit(RLIMIT_STACK, (stack_size, stack_size))
Expand All @@ -29,7 +30,7 @@ def test_leak_load():
im.load()


def test_leak_save():
def test_leak_save() -> None:
from resource import RLIMIT_AS, RLIMIT_STACK, setrlimit

setrlimit(RLIMIT_STACK, (stack_size, stack_size))
Expand Down
5 changes: 4 additions & 1 deletion Tests/check_j2k_overflow.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import annotations

from pathlib import Path

import pytest

from PIL import Image


def test_j2k_overflow(tmp_path):
def test_j2k_overflow(tmp_path: Path) -> None:
im = Image.new("RGBA", (1024, 131584))
target = str(tmp_path / "temp.jpc")
with pytest.raises(OSError):
Expand Down
3 changes: 0 additions & 3 deletions Tests/check_jp2_overflow.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

# Reproductions/tests for OOB read errors in FliDecode.c

# When run in python, all of these images should fail for
Expand All @@ -14,7 +12,6 @@
# version.
from __future__ import annotations


from PIL import Image

repro = ("00r0_gray_l.jp2", "00r1_graya_la.jp2")
Expand Down

0 comments on commit 2888f76

Please sign in to comment.