Skip to content

Commit

Permalink
make cmake and ninja more optional
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Jul 19, 2022
1 parent a5060fe commit 37c9232
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 14 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/releasebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
89 changes: 89 additions & 0 deletions _custom_build/backend.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion src/jarowinkler/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions tools/sdist.patch
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 37c9232

Please sign in to comment.