From 8754a16b61092b084a9ab088476991c7ba7171ac Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 17 Dec 2023 13:04:20 +0200 Subject: [PATCH] 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 1dd6c9175..2bf4d3389 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 f9cea0612..f0865fa98 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 2a364ba97..2705136e3 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 @@ if sys.platform == "win32" and sys.version_info >= (3, 13): 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 @@ class pil_build_ext(build_ext): 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 @@ class pil_build_ext(build_ext): 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 ad9df0244..67eff10e9 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 @@ try: # 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 279b6e228..000000000 --- a/src/PIL/_version.py +++ /dev/null @@ -1,2 +0,0 @@ -# Master version for Pillow -__version__ = "10.2.0.dev0"