From 8754a16b61092b084a9ab088476991c7ba7171ac Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 17 Dec 2023 13:04:20 +0200 Subject: [PATCH 1/5] Use setuptools_scm for dynamic versioning --- .gitignore | 3 +++ pyproject.toml | 5 +++++ setup.py | 8 ++++---- src/PIL/Image.py | 6 +++++- src/PIL/_version.py | 2 -- 5 files changed, 17 insertions(+), 7 deletions(-) delete mode 100644 src/PIL/_version.py diff --git a/.gitignore b/.gitignore index 1dd6c917524..2bf4d3389e5 100644 --- a/.gitignore +++ b/.gitignore @@ -92,3 +92,6 @@ Tests/images/sunraster # pyinstaller *.spec + +# Generated by setuptools_scm +src/PIL/_version.py diff --git a/pyproject.toml b/pyproject.toml index f9cea0612af..f0865fa986a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,7 @@ build-backend = "backend" requires = [ "setuptools>=67.8", + "setuptools_scm>=8", ] backend-path = [ "_custom_build", @@ -86,6 +87,10 @@ package-dir = {"" = "src"} [tool.setuptools.dynamic] version = {attr = "PIL.__version__"} +[tool.setuptools_scm] +local_scheme = "no-local-version" +version_file = "src/PIL/_version.py" + [tool.cibuildwheel] before-all = ".github/workflows/wheels-dependencies.sh" build-verbosity = 1 diff --git a/setup.py b/setup.py index 2a364ba97eb..2705136e305 100755 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Final rating: 10/10 # Your cheese is so fresh most people think it's a cream: Mascarpone # ------------------------------ +from __future__ import annotations import os import re @@ -27,7 +28,6 @@ def get_version(): return locals()["__version__"] -PILLOW_VERSION = get_version() FREETYPE_ROOT = None HARFBUZZ_ROOT = None FRIBIDI_ROOT = None @@ -44,7 +44,7 @@ def get_version(): atexit.register( lambda: warnings.warn( - f"Pillow {PILLOW_VERSION} does not support Python " + f"Pillow {get_version()} does not support Python " f"{sys.version_info.major}.{sys.version_info.minor} and does not provide " "prebuilt Windows binaries. We do not recommend building from source on " "Windows.", @@ -847,7 +847,7 @@ def build_extensions(self): if struct.unpack("h", b"\0\1")[0] == 1: defs.append(("WORDS_BIGENDIAN", None)) - defs.append(("PILLOW_VERSION", f'"{PILLOW_VERSION}"')) + defs.append(("PILLOW_VERSION", f'"{get_version()}"')) self._update_extension("PIL._imaging", libs, defs) @@ -912,7 +912,7 @@ def summary_report(self, feature): print("-" * 68) print("PIL SETUP SUMMARY") print("-" * 68) - print(f"version Pillow {PILLOW_VERSION}") + print(f"version Pillow {get_version()}") v = sys.version.split("[") print(f"platform {sys.platform} {v[0].strip()}") for v in v[1:]: diff --git a/src/PIL/Image.py b/src/PIL/Image.py index ad9df024453..67eff10e98f 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -23,6 +23,7 @@ # # See the README file for information on usage and redistribution. # +from __future__ import annotations import atexit import builtins @@ -81,7 +82,10 @@ class DecompressionBombError(Exception): # and should be considered private and subject to change. from . import _imaging as core - if __version__ != getattr(core, "PILLOW_VERSION", None): + # if __version__ != getattr(core, "PILLOW_VERSION", None): + if not hasattr(core, "PILLOW_VERSION") or re.sub( + "dev[0-9]+", "dev0", __version__ + ) != re.sub("dev[0-9]+", "dev0", core.PILLOW_VERSION): msg = ( "The _imaging extension was built for another version of Pillow or PIL:\n" f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n" diff --git a/src/PIL/_version.py b/src/PIL/_version.py deleted file mode 100644 index 279b6e2289a..00000000000 --- a/src/PIL/_version.py +++ /dev/null @@ -1,2 +0,0 @@ -# Master version for Pillow -__version__ = "10.2.0.dev0" From 14d6341b233fd1f17840840b25467f4ac2321e0d Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 17 Dec 2023 13:27:09 +0200 Subject: [PATCH 2/5] Fetch tags for setuptools_scm --- .github/workflows/test-cygwin.yml | 2 ++ .github/workflows/test-docker.yml | 2 ++ .github/workflows/test-mingw.yml | 2 ++ .github/workflows/test-valgrind.yml | 2 ++ .github/workflows/test-windows.yml | 2 ++ .github/workflows/test.yml | 2 ++ 6 files changed, 12 insertions(+) diff --git a/.github/workflows/test-cygwin.yml b/.github/workflows/test-cygwin.yml index 32ac6f65e76..52870150cd1 100644 --- a/.github/workflows/test-cygwin.yml +++ b/.github/workflows/test-cygwin.yml @@ -47,6 +47,8 @@ jobs: - name: Checkout Pillow uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Install Cygwin uses: cygwin/cygwin-install-action@v4 diff --git a/.github/workflows/test-docker.yml b/.github/workflows/test-docker.yml index eb27b4bf75b..ba8a0b4f7e7 100644 --- a/.github/workflows/test-docker.yml +++ b/.github/workflows/test-docker.yml @@ -70,6 +70,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build system information run: python3 .github/workflows/system-info.py diff --git a/.github/workflows/test-mingw.yml b/.github/workflows/test-mingw.yml index 115c2e9bebc..842236fc399 100644 --- a/.github/workflows/test-mingw.yml +++ b/.github/workflows/test-mingw.yml @@ -45,6 +45,8 @@ jobs: steps: - name: Checkout Pillow uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up shell run: echo "C:\msys64\usr\bin\" >> $env:GITHUB_PATH diff --git a/.github/workflows/test-valgrind.yml b/.github/workflows/test-valgrind.yml index 59bb958ec1c..29c14c02a30 100644 --- a/.github/workflows/test-valgrind.yml +++ b/.github/workflows/test-valgrind.yml @@ -40,6 +40,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Build system information run: python3 .github/workflows/system-info.py diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 86cd5b5fa1e..c01dc0af92a 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -41,6 +41,8 @@ jobs: steps: - name: Checkout Pillow uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Checkout cached dependencies uses: actions/checkout@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aa0e2513825..4e91dadd815 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,6 +60,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 From 53668d0572ef37726c17325cf5c3501e2e0b941d Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 17 Dec 2023 13:38:39 +0200 Subject: [PATCH 3/5] Add mingw-w64-x86_64-tools-git --- .github/workflows/test-mingw.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-mingw.yml b/.github/workflows/test-mingw.yml index 842236fc399..320ab30af67 100644 --- a/.github/workflows/test-mingw.yml +++ b/.github/workflows/test-mingw.yml @@ -65,12 +65,13 @@ jobs: mingw-w64-x86_64-libtiff \ mingw-w64-x86_64-libwebp \ mingw-w64-x86_64-openjpeg2 \ + mingw-w64-x86_64-python-pyqt6 \ mingw-w64-x86_64-python3-cffi \ mingw-w64-x86_64-python3-numpy \ mingw-w64-x86_64-python3-olefile \ mingw-w64-x86_64-python3-pip \ mingw-w64-x86_64-python3-setuptools \ - mingw-w64-x86_64-python-pyqt6 + mingw-w64-x86_64-tools-git python3 -m pip install pyroma pytest pytest-cov pytest-timeout From be7e1a4a2a8118a25ecbe38e4eb5bbab4f8848ea Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 17 Dec 2023 13:52:26 +0200 Subject: [PATCH 4/5] Don't 'make clean' in CI, it's already clean --- .ci/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/build.sh b/.ci/build.sh index e678f68ec85..7309bf7d36e 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -6,5 +6,4 @@ python3 -m coverage erase if [ $(uname) == "Darwin" ]; then export CPPFLAGS="-I/usr/local/miniconda/include"; fi -make clean make install-coverage From 3f15c21648dd1f67f5e7c947a6f36fbf53464650 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 17 Dec 2023 14:13:07 +0200 Subject: [PATCH 5/5] Add git package for Cygwin --- .github/workflows/test-cygwin.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-cygwin.yml b/.github/workflows/test-cygwin.yml index 52870150cd1..a170bad50b8 100644 --- a/.github/workflows/test-cygwin.yml +++ b/.github/workflows/test-cygwin.yml @@ -57,6 +57,7 @@ jobs: packages: > gcc-g++ ghostscript + git ImageMagick jpeg libfreetype-devel