Skip to content

Commit

Permalink
Use setuptools_scm for dynamic versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Dec 17, 2023
1 parent e1a2ad1 commit 8754a16
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ Tests/images/sunraster

# pyinstaller
*.spec

# Generated by setuptools_scm
src/PIL/_version.py
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
build-backend = "backend"
requires = [
"setuptools>=67.8",
"setuptools_scm>=8",
]
backend-path = [
"_custom_build",
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +28,6 @@ def get_version():
return locals()["__version__"]


PILLOW_VERSION = get_version()
FREETYPE_ROOT = None
HARFBUZZ_ROOT = None
FRIBIDI_ROOT = None
Expand All @@ -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.",
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:]:
Expand Down
6 changes: 5 additions & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#
# See the README file for information on usage and redistribution.
#
from __future__ import annotations

import atexit
import builtins
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions src/PIL/_version.py

This file was deleted.

0 comments on commit 8754a16

Please sign in to comment.