mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
pass build config before setuptools command; add build_editable to custom build backend
This commit is contained in:
parent
ded2c8b1d1
commit
8070fe10f1
2
.github/workflows/wheels.yml
vendored
2
.github/workflows/wheels.yml
vendored
|
@ -5,6 +5,7 @@ on:
|
|||
paths:
|
||||
- ".ci/requirements-cibw.txt"
|
||||
- ".github/workflows/wheel*"
|
||||
- "setup.py"
|
||||
- "wheels/*"
|
||||
- "winbuild/build_prepare.py"
|
||||
- "winbuild/fribidi.cmake"
|
||||
|
@ -14,6 +15,7 @@ on:
|
|||
paths:
|
||||
- ".ci/requirements-cibw.txt"
|
||||
- ".github/workflows/wheel*"
|
||||
- "setup.py"
|
||||
- "wheels/*"
|
||||
- "winbuild/build_prepare.py"
|
||||
- "winbuild/fribidi.cmake"
|
||||
|
|
|
@ -11,41 +11,16 @@ backend_class = build_wheel.__self__.__class__
|
|||
class _CustomBuildMetaBackend(backend_class):
|
||||
def run_setup(self, setup_script="setup.py"):
|
||||
if self.config_settings:
|
||||
params = []
|
||||
for k, v in self.config_settings.items():
|
||||
if isinstance(v, list):
|
||||
msg = "Conflicting options: " + ", ".join(
|
||||
f"'--config-setting {k}={v_}'" for v_ in v
|
||||
)
|
||||
raise ValueError(msg)
|
||||
params.append(f"--pillow-configuration={k}={v}")
|
||||
|
||||
def config_has(key, value):
|
||||
settings = self.config_settings.get(key)
|
||||
if settings:
|
||||
if not isinstance(settings, list):
|
||||
settings = [settings]
|
||||
return value in settings
|
||||
|
||||
flags = []
|
||||
for dependency in (
|
||||
"zlib",
|
||||
"jpeg",
|
||||
"tiff",
|
||||
"freetype",
|
||||
"raqm",
|
||||
"lcms",
|
||||
"webp",
|
||||
"webpmux",
|
||||
"jpeg2000",
|
||||
"imagequant",
|
||||
"xcb",
|
||||
):
|
||||
if config_has(dependency, "enable"):
|
||||
flags.append("--enable-" + dependency)
|
||||
elif config_has(dependency, "disable"):
|
||||
flags.append("--disable-" + dependency)
|
||||
for dependency in ("raqm", "fribidi"):
|
||||
if config_has(dependency, "vendor"):
|
||||
flags.append("--vendor-" + dependency)
|
||||
if self.config_settings.get("platform-guessing") == "disable":
|
||||
flags.append("--disable-platform-guessing")
|
||||
if self.config_settings.get("debug") == "true":
|
||||
flags.append("--debug")
|
||||
if flags:
|
||||
sys.argv = sys.argv[:1] + ["build_ext"] + flags + sys.argv[1:]
|
||||
sys.argv = sys.argv[:1] + params + sys.argv[1:]
|
||||
return super().run_setup(setup_script)
|
||||
|
||||
def build_wheel(
|
||||
|
@ -54,5 +29,15 @@ class _CustomBuildMetaBackend(backend_class):
|
|||
self.config_settings = config_settings
|
||||
return super().build_wheel(wheel_directory, config_settings, metadata_directory)
|
||||
|
||||
def build_editable(
|
||||
self, wheel_directory, config_settings=None, metadata_directory=None
|
||||
):
|
||||
self.config_settings = config_settings
|
||||
return super().build_editable(
|
||||
wheel_directory, config_settings, metadata_directory
|
||||
)
|
||||
|
||||
build_wheel = _CustomBuildMetaBackend().build_wheel
|
||||
|
||||
_backend = _CustomBuildMetaBackend()
|
||||
build_wheel = _backend.build_wheel
|
||||
build_editable = _backend.build_editable
|
||||
|
|
|
@ -92,7 +92,7 @@ version = {attr = "PIL.__version__"}
|
|||
[tool.cibuildwheel]
|
||||
before-all = ".github/workflows/wheels-dependencies.sh"
|
||||
build-verbosity = 1
|
||||
config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable"
|
||||
config-settings = "raqm=vendor fribidi=vendor imagequant=disable"
|
||||
test-command = "cd {project} && .github/workflows/wheels-test.sh"
|
||||
test-extras = "tests"
|
||||
|
||||
|
|
34
setup.py
34
setup.py
|
@ -28,6 +28,9 @@ def get_version():
|
|||
return locals()["__version__"]
|
||||
|
||||
|
||||
configuration = {}
|
||||
|
||||
|
||||
PILLOW_VERSION = get_version()
|
||||
FREETYPE_ROOT = None
|
||||
HARFBUZZ_ROOT = None
|
||||
|
@ -334,15 +337,24 @@ class pil_build_ext(build_ext):
|
|||
+ [("add-imaging-libs=", None, "Add libs to _imaging build")]
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def check_configuration(option, value):
|
||||
return True if configuration.get(option) == value else None
|
||||
|
||||
def initialize_options(self):
|
||||
self.disable_platform_guessing = None
|
||||
self.disable_platform_guessing = self.check_configuration(
|
||||
"platform-guessing", "disable"
|
||||
)
|
||||
self.add_imaging_libs = ""
|
||||
build_ext.initialize_options(self)
|
||||
for x in self.feature:
|
||||
setattr(self, f"disable_{x}", None)
|
||||
setattr(self, f"enable_{x}", None)
|
||||
setattr(self, f"disable_{x}", self.check_configuration(x, "disable"))
|
||||
setattr(self, f"enable_{x}", self.check_configuration(x, "enable"))
|
||||
for x in ("raqm", "fribidi"):
|
||||
setattr(self, f"vendor_{x}", None)
|
||||
setattr(self, f"vendor_{x}", self.check_configuration(x, "vendor"))
|
||||
if self.check_configuration("debug", "true"):
|
||||
self.debug = True
|
||||
self.parallel = configuration.get("parallel")
|
||||
|
||||
def finalize_options(self):
|
||||
build_ext.finalize_options(self)
|
||||
|
@ -390,6 +402,9 @@ class pil_build_ext(build_ext):
|
|||
raise ValueError(msg)
|
||||
_dbg("Using vendored version of %s", x)
|
||||
self.feature.vendor.add(x)
|
||||
if x == "raqm":
|
||||
_dbg("--vendor-raqm implies --enable-raqm")
|
||||
self.feature.required.add(x)
|
||||
|
||||
def _update_extension(self, name, libraries, define_macros=None, sources=None):
|
||||
for extension in self.extensions:
|
||||
|
@ -985,6 +1000,17 @@ ext_modules = [
|
|||
Extension("PIL._imagingmorph", ["src/_imagingmorph.c"]),
|
||||
]
|
||||
|
||||
|
||||
# parse configuration from _custom_build/backend.py
|
||||
while len(sys.argv[1]) >= 2 and sys.argv[1].startswith("--pillow-configuration="):
|
||||
_, key, value = sys.argv[1].split("=", 2)
|
||||
old = configuration.get(key)
|
||||
if old is not None:
|
||||
msg = f"Conflicting options: '-C {key}={old}' and '-C {key}={value}'"
|
||||
raise ValueError(msg)
|
||||
configuration[key] = value
|
||||
del sys.argv[1]
|
||||
|
||||
try:
|
||||
setup(
|
||||
cmdclass={"build_ext": pil_build_ext},
|
||||
|
|
Loading…
Reference in New Issue
Block a user