Use setuptools_scm for dynamic versioning

This commit is contained in:
Hugo van Kemenade 2023-12-17 13:04:20 +02:00
parent e1a2ad14df
commit 8754a16b61
5 changed files with 17 additions and 7 deletions

3
.gitignore vendored
View File

@ -92,3 +92,6 @@ Tests/images/sunraster
# pyinstaller
*.spec
# Generated by setuptools_scm
src/PIL/_version.py

View File

@ -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

View File

@ -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:]:

View File

@ -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"

View File

@ -1,2 +0,0 @@
# Master version for Pillow
__version__ = "10.2.0.dev0"