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 17, 2022
1 parent 881419a commit 42c51de
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/releasebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
env:
CIBW_ARCHS_LINUX: ${{matrix.arch}}
CIBW_BUILD: ${{matrix.python_tag}}
CIBW_TEST_SKIP: "*_{aarch64,ppc64le,s390x}"
CIBW_TEST_SKIP: "{*_{aarch64,ppc64le,s390x},*musllinux_*}"
CIBW_TEST_REQUIRES: pytest hypothesis pandas
CIBW_TEST_COMMAND: pytest {package}/tests
CIBW_TEST_COMMAND_LINUX: "{package}/tools/seg_wrapper.sh pytest {package}/tests"
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

### [2.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

### [2.1.4] - 2022-07-17
#### Changed
- changed internal implementation of cdist to remove build dependency to numpy
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/rapidfuzz/py.typed
recursive-include src/rapidfuzz *.pyi

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
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Max Bachmann'

# The full version, including alpha/beta/rc tags
release = '2.1.4'
release = '2.2.0'


# -- General configuration ---------------------------------------------------
Expand Down
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +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",
"typing_extensions"
"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": "rapidfuzz",
"version": "2.1.4",
"version": "2.2.0",
"install_requires": ["jarowinkler >= 1.1.0, < 2.0.0"],
"extras_require": {'full': ['numpy']},
"url": "https://github.com/maxbachmann/RapidFuzz",
Expand Down
2 changes: 1 addition & 1 deletion src/rapidfuzz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"""
__author__: str = "Max Bachmann"
__license__: str = "MIT"
__version__: str = "2.1.4"
__version__: str = "2.2.0"

from rapidfuzz import process, distance, fuzz, string_metric, utils
12 changes: 6 additions & 6 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 66fef0a..a4b9f84 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",
"typing_extensions"
"rapidfuzz_capi==1.0.5"
]
build-backend = "backend"

0 comments on commit 42c51de

Please sign in to comment.