From 2e3444d7f15260dde99e723c861b93c4f01b3c8b Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sat, 13 Jul 2024 18:14:18 +0200 Subject: [PATCH] use scikit-build-core --- .gitignore | 3 ++ CMakeLists.txt | 2 +- MANIFEST.in | 16 -------- _custom_build/backend.py | 51 ------------------------- pyproject.toml | 69 ++++++++++++++++++++++++++++++++-- setup.py | 33 ---------------- src/Levenshtein/CMakeLists.txt | 15 ++++++-- 7 files changed, 80 insertions(+), 109 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 _custom_build/backend.py delete mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 16f0fdc..8b708d6 100644 --- a/.gitignore +++ b/.gitignore @@ -140,3 +140,6 @@ cython_debug/ # vscode .vscode/ _skbuild/ + +# Cython generated files +*.cxx \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 665f92d..24d2ede 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12...3.24) +cmake_minimum_required(VERSION 3.15...3.26) cmake_policy(SET CMP0054 NEW) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 4bf6c43..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,16 +0,0 @@ -include setup.py -include CMakeLists.txt -include README.md -include COPYING -include HISTORY.md -include pyproject.toml -include _custom_build/backend.py -include src/Levenshtein/py.typed - -recursive-include src/Levenshtein CMakeLists.txt -recursive-include src/Levenshtein *.hpp *.h *.cpp *.pyx *.pxd *.cxx *.pyi -recursive-include tests * - -include extern/rapidfuzz-cpp/LICENSE -include extern/rapidfuzz-cpp/CMakeLists.txt -recursive-include extern/rapidfuzz-cpp/rapidfuzz *.hpp *.impl diff --git a/_custom_build/backend.py b/_custom_build/backend.py deleted file mode 100644 index 125845a..0000000 --- a/_custom_build/backend.py +++ /dev/null @@ -1,51 +0,0 @@ -from __future__ import annotations - -import platform as _platform -import subprocess as _subprocess - -from packaging import version as _version -from setuptools import build_meta as _orig -from skbuild.cmaker import get_cmake_version as _get_cmake_version -from skbuild.exceptions import SKBuildError as _SKBuildError - -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 - - -def _cmake_required(): - try: - if _version.parse(_get_cmake_version().split("-")[0]) >= _version.parse("3.12"): - print("Using System version of cmake") - return False - except _SKBuildError: - pass - - return True - - -def _ninja_required(): - if _platform.system() == "Windows": - print("Ninja is part of the MSVC installation on Windows") - return False - - for generator in ("ninja", "make"): - try: - _subprocess.check_output([generator, "--version"]) - print(f"Using System version of {generator}") - return False - except (OSError, _subprocess.CalledProcessError): - pass - - return True - - -def get_requires_for_build_wheel(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 bb711c4..0a8c033 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,57 @@ [build-system] requires = [ - "setuptools", - "scikit-build>=0.13.0", + "scikit-build-core>=0.9.8", "Cython>=3.0.2,<3.1.0" ] -build-backend = "backend" -backend-path = ["_custom_build"] +build-backend = "scikit_build_core.build" +[project] +name = "Levenshtein" +dynamic = ["version"] +dependencies = [ + "rapidfuzz >= 3.8.0, < 4.0.0" +] +requires-python = ">= 3.8" +authors = [ + {name = "Max Bachmann", email = "pypi@maxbachmann.de"}, +] +description = "Python extension for computing string edit distances and similarities." +readme = "README.md" +classifiers=[ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", +] +Homepage = "https://github.com/rapidfuzz/Levenshtein" +Documentation = "https://rapidfuzz.github.io/Levenshtein/" +Repository = "https://github.com/rapidfuzz/Levenshtein.git" +Issues = "https://github.com/rapidfuzz/Levenshtein/issues" +Changelog = "https://github.com/rapidfuzz/Levenshtein/blob/main/HISTORY.md" + +[tool.scikit-build] +sdist.include = [ + "src/Levenshtein/*.cxx", + "src/Levenshtein/_version.py" +] +sdist.exclude = [ + ".github" +] +wheel.exclude = [ + "**.pyx", + "**.cxx", + "**.cpp", + "**.hpp", + "CMakeLists.txt", + "generate.sh" +] + +[tool.scikit-build.metadata.version] +provider = "scikit_build_core.metadata.regex" +input = "src/Levenshtein/__init__.py" [tool.black] line-length = 120 @@ -95,3 +140,19 @@ isort.required-imports = ["from __future__ import annotations"] "bench/**" = ["T20"] "_custom_build/backend.py" = ["T20"] "setup.py" = ["T20"] + + + + +#[tool.scikit-build] + + + +#setup( +# url="https://github.com/rapidfuzz/Levenshtein", +# license="GPL", +# license_file="COPYING", +# packages=["Levenshtein"], +# package_dir={"": "src"}, +# package_data={"Levenshtein": ["*.pyi", "py.typed"]}, +#) \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 3d8c93b..0000000 --- a/setup.py +++ /dev/null @@ -1,33 +0,0 @@ -from __future__ import annotations - -from skbuild import setup - -with open("README.md", encoding="utf8") as f: - readme = f.read() - -setup( - name="Levenshtein", - version="0.25.1", - url="https://github.com/rapidfuzz/Levenshtein", - author="Max Bachmann", - install_requires=["rapidfuzz >= 3.8.0, < 4.0.0"], - author_email="pypi@maxbachmann.de", - description="Python extension for computing string edit distances and similarities.", - long_description=readme, - long_description_content_type="text/markdown", - license="GPL", - license_file="COPYING", - classifiers=[ - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)", - ], - packages=["Levenshtein"], - package_dir={"": "src"}, - package_data={"Levenshtein": ["*.pyi", "py.typed"]}, - python_requires=">=3.8", -) diff --git a/src/Levenshtein/CMakeLists.txt b/src/Levenshtein/CMakeLists.txt index 5bd14ca..a15f8a4 100644 --- a/src/Levenshtein/CMakeLists.txt +++ b/src/Levenshtein/CMakeLists.txt @@ -4,10 +4,17 @@ function(create_cython_target _name) ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx PARENT_SCOPE) else() - find_package(Cython REQUIRED) - add_cython_target(${_name} CXX) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_name}.cxx" + MAIN_DEPENDENCY "${CMAKE_CURRENT_LIST_DIR}/${_name}.pyx" + VERBATIM + COMMAND + Python::Interpreter -m cython + "${CMAKE_CURRENT_LIST_DIR}/${_name}.pyx" --output-file + "${CMAKE_CURRENT_BINARY_DIR}/${_name}.cxx") + set(${_name} - ${_name} + ${CMAKE_CURRENT_BINARY_DIR}/${_name}.cxx PARENT_SCOPE) endif() endfunction(create_cython_target) @@ -35,4 +42,4 @@ target_compile_features(levenshtein_cpp PUBLIC cxx_std_17) target_include_directories(levenshtein_cpp PRIVATE ${LEV_BASE_DIR}/Levenshtein-c) target_link_libraries(levenshtein_cpp PRIVATE rapidfuzz::rapidfuzz) -install(TARGETS levenshtein_cpp LIBRARY DESTINATION src/Levenshtein) +install(TARGETS levenshtein_cpp DESTINATION Levenshtein/)