From 37c9232c623f9f126335962ac00bb2a93c3d0212 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 19 Jul 2022 07:43:47 +0200 Subject: [PATCH] make cmake and ninja more optional --- .github/workflows/releasebuild.yml | 16 ++++-- CHANGELOG.md | 5 ++ MANIFEST.in | 1 + _custom_build/backend.py | 89 ++++++++++++++++++++++++++++++ pyproject.toml | 5 +- setup.py | 2 +- src/jarowinkler/__init__.py | 2 +- tools/sdist.patch | 10 ++-- 8 files changed, 116 insertions(+), 14 deletions(-) create mode 100644 _custom_build/backend.py diff --git a/.github/workflows/releasebuild.yml b/.github/workflows/releasebuild.yml index 5347420..b622d68 100644 --- a/.github/workflows/releasebuild.yml +++ b/.github/workflows/releasebuild.yml @@ -15,15 +15,23 @@ jobs: strategy: fail-fast: false matrix: - arch: [all] + arch: [auto32, auto64] python_tag: ["cp36-*", "cp37-*", "cp38-*", "cp39-*", "cp310-*", "pp37-*", "pp38-*", "pp39-*"] exclude: + # PyPy only supports x86_64 on Windows + - arch: auto32 + python_tag: "pp37-*" + - arch: auto32 + python_tag: "pp38-*" + - arch: auto32 + python_tag: "pp39-*" + # PyPy Windows is currently broken in scikit-build - - arch: all + - arch: auto64 python_tag: "pp37-*" - - arch: all + - arch: auto64 python_tag: "pp38-*" - - arch: all + - arch: auto64 python_tag: "pp39-*" env: CIBW_BUILD: ${{matrix.python_tag}} diff --git a/CHANGELOG.md b/CHANGELOG.md index 26099b0..38c4824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +### [1.2.0] - 2022-07- +#### Changed +- added in-tree build backend to install cmake and ninja only when it is not installed yet + and only when wheels are available + ### [1.1.2] - 2022-07-11 #### Fixed - remove incorrect module import diff --git a/MANIFEST.in b/MANIFEST.in index f36be8a..10c95b2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,6 +4,7 @@ include CMakeLists.txt include README.md include LICENSE include pyproject.toml +include _custom_build/backend.py include src/jarowinkler/py.typed recursive-include src/jarowinkler CMakeLists.txt diff --git a/_custom_build/backend.py b/_custom_build/backend.py new file mode 100644 index 0000000..a225029 --- /dev/null +++ b/_custom_build/backend.py @@ -0,0 +1,89 @@ +from setuptools import build_meta as _orig +from packaging import version as _version +from packaging.tags import sys_tags as _sys_tags +from skbuild.exceptions import SKBuildError as _SKBuildError +from skbuild.cmaker import get_cmake_version as _get_cmake_version +import subprocess as _subprocess +import platform as _platform + +prepare_metadata_for_build_wheel = _orig.prepare_metadata_for_build_wheel +build_wheel = _orig.build_wheel +build_sdist = _orig.build_sdist +get_requires_for_build_sdist = _orig.get_requires_for_build_sdist + +cmake_wheels = { + "win_amd64", + "win32", + "musllinux_1_1_x86_64", + "musllinux_1_1_s390x", + "musllinux_1_1_ppc64le", + "musllinux_1_1_i686", + "musllinux_1_1_aarch64", + "manylinux_2_17_s390x", + "manylinux_2_17_ppc64le", + "manylinux_2_17_aarch64", + "manylinux_2_17_x86_64", + "manylinux_2_17_i686", + "manylinux_2_5_x86_64", + "manylinux_2_5_i686", + "macosx_10_10_universal2", +} + +ninja_wheels = { + "win_amd64", + "win32.whl", + "musllinux_1_1_x86_64", + "musllinux_1_1_s390x", + "musllinux_1_1_ppc64le", + "musllinux_1_1_i686", + "musllinux_1_1_aarch64", + "manylinux_2_17_s390x", + "manylinux_2_17_ppc64le", + "manylinux_2_17_aarch64", + "manylinux_2_5_x86_64", + "manylinux_2_5_i686", + "macosx_10_9_universal2", +} + +def _cmake_required(): + try: + if _version.parse(_get_cmake_version()) >= _version.parse("3.12"): + print("Using System version of cmake") + return False + except _SKBuildError: + pass + + for tag in _sys_tags(): + if tag.platform in cmake_wheels: + return True + + print("No Cmake wheel available on platform") + return False + +def _ninja_required(): + if _platform.system() == "Windows": + print("Ninja is part of the MSVC installation on Windows") + return False + + try: + _subprocess.check_output(["ninja", '--version']) + print("Using System version of Ninja") + return False + except (OSError, _subprocess.CalledProcessError): + pass + + for tag in _sys_tags(): + if tag.platform in ninja_wheels: + return True + + print("No Ninja wheel available on platform") + return False + +def get_requires_for_build_wheel(self, config_settings=None): + packages = [] + if _cmake_required(): + packages.append('cmake') + if _ninja_required(): + packages.append('ninja') + + return _orig.get_requires_for_build_wheel(config_settings) + packages diff --git a/pyproject.toml b/pyproject.toml index 6efb23f..1f4d4d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,9 +2,8 @@ requires = [ "setuptools>=42", "scikit-build>=0.13.0", - "cmake; platform_machine not in 'armv7l|armv6l|arm64|aarch64'", - "ninja; platform_system!='Windows' and platform_machine not in 'armv7l|armv6l|arm64|aarch64'", "Cython==3.0.0a10", "rapidfuzz_capi==1.0.5" ] -build-backend = "setuptools.build_meta" +build-backend = "backend" +backend-path = ["_custom_build"] diff --git a/setup.py b/setup.py index 07bc401..45d2009 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def show_message(*lines): setup_args = { "name": "jarowinkler", - "version": "1.1.2", + "version": "1.2.0", "url": "https://github.com/maxbachmann/JaroWinkler", "author": "Max Bachmann", "author_email": "pypi@maxbachmann.de", diff --git a/src/jarowinkler/__init__.py b/src/jarowinkler/__init__.py index 459229f..de157f6 100644 --- a/src/jarowinkler/__init__.py +++ b/src/jarowinkler/__init__.py @@ -1,6 +1,6 @@ __author__: str = "Max Bachmann" __license__: str = "MIT" -__version__: str = "1.1.2" +__version__: str = "1.2.0" def _fallback_import(module: str, name: str): import importlib diff --git a/tools/sdist.patch b/tools/sdist.patch index e7522d4..9969b8f 100644 --- a/tools/sdist.patch +++ b/tools/sdist.patch @@ -1,12 +1,12 @@ diff --git a/pyproject.toml b/pyproject.toml -index 6efb23f..cd80bc3 100644 +index 1f4d4d6..1f94979 100644 --- a/pyproject.toml +++ b/pyproject.toml -@@ -4,7 +4,6 @@ requires = [ +@@ -2,7 +2,6 @@ + requires = [ + "setuptools>=42", "scikit-build>=0.13.0", - "cmake; platform_machine not in 'armv7l|armv6l|arm64|aarch64'", - "ninja; platform_system!='Windows' and platform_machine not in 'armv7l|armv6l|arm64|aarch64'", - "Cython==3.0.0a10", "rapidfuzz_capi==1.0.5" ] - build-backend = "setuptools.build_meta" + build-backend = "backend"