Skip to content

Commit b139b6a

Browse files
committed
cleanup build
1 parent 71bb907 commit b139b6a

File tree

8 files changed

+132
-71
lines changed

8 files changed

+132
-71
lines changed

CMakeLists.txt

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
cmake_minimum_required(VERSION 3.12.0)
1+
cmake_minimum_required(VERSION 3.15...3.26)
22

33
cmake_policy(SET CMP0054 NEW)
4+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
45
set(SKBUILD_LINK_LIBRARIES_KEYWORD PRIVATE)
6+
set(Python_FIND_IMPLEMENTATIONS CPython PyPy)
57

68
set(THREADS_PREFER_PTHREAD_FLAG ON)
79
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -18,8 +20,36 @@ else()
1820
add_compile_options(-Wall -Wextra -pedantic)
1921
endif()
2022

21-
find_package(PythonExtensions REQUIRED)
22-
find_package(Python COMPONENTS Interpreter Development)
23-
find_package(Cython REQUIRED)
23+
if(CMAKE_VERSION VERSION_LESS 3.18)
24+
find_package(
25+
Python
26+
COMPONENTS Interpreter Development
27+
REQUIRED)
28+
else()
29+
set(Python_ARTIFACTS_INTERACTIVE TRUE)
30+
find_package(
31+
Python
32+
COMPONENTS Interpreter Development.Module
33+
REQUIRED)
34+
endif()
35+
36+
if(CMAKE_VERSION VERSION_LESS 3.17)
37+
execute_process(
38+
COMMAND
39+
"${Python_EXECUTABLE}" -c
40+
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX').split('.')[1])"
41+
OUTPUT_VARIABLE Python_SOABI
42+
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
43+
message(STATUS "Corrected SOABI: ${Python_SOABI}")
44+
elseif("${Python_INTERPRETER_ID}" STREQUAL "PyPy")
45+
message(STATUS "PyPy SOABI: ${Python_SOABI}")
46+
execute_process(
47+
COMMAND
48+
"${Python_EXECUTABLE}" -c
49+
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX').split('.')[1])"
50+
OUTPUT_VARIABLE Python_SOABI
51+
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT)
52+
message(STATUS "Corrected SOABI: ${Python_SOABI}")
53+
endif()
2454

25-
add_subdirectory(src/cython)
55+
add_subdirectory(src/cydifflib)

pyproject.toml

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,57 @@
11
[build-system]
22
requires = [
3-
"setuptools>=42",
4-
"scikit-build~=0.17.0",
5-
"cmake",
6-
"ninja; platform_system!='Windows'",
7-
"Cython >=3.0.7, <3.1.0"
3+
"scikit-build-core>=0.11",
4+
"Cython>=3.0.12,<3.1.0"
85
]
9-
build-backend = "setuptools.build_meta"
6+
build-backend = "scikit_build_core.build"
7+
8+
[project]
9+
name = "cydifflib"
10+
dynamic = ["version"]
11+
requires-python = ">= 3.9"
12+
authors = [
13+
{name = "Max Bachmann", email = "[email protected]"},
14+
]
15+
maintainers = [
16+
{name = "Max Bachmann", email = "[email protected]"},
17+
]
18+
description = "Fast implementation of difflib's algorithms"
19+
readme = "README.md"
20+
license = "MIT"
21+
classifiers=[
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
26+
"Programming Language :: Python :: 3.12",
27+
"Programming Language :: Python :: 3.13",
28+
]
29+
30+
[project.urls]
31+
Homepage = "https://github.com/rapidfuzz/CyDifflib"
32+
Repository = "https://github.com/rapidfuzz/CyDifflib.git"
33+
Issues = "https://github.com/rapidfuzz/CyDifflib/issues"
34+
Changelog = "https://github.com/rapidfuzz/CyDifflib/blob/main/CHANGELOG.md"
35+
36+
[tool.scikit-build]
37+
sdist.include = [
38+
"src/cydifflib/*.cxx",
39+
]
40+
sdist.exclude = [
41+
".github"
42+
]
43+
wheel.exclude = [
44+
"**.pyx",
45+
"**.cxx",
46+
"**.cpp",
47+
"**.hpp",
48+
"CMakeLists.txt",
49+
"generate.sh"
50+
]
51+
52+
[tool.scikit-build.metadata.version]
53+
provider = "scikit_build_core.metadata.regex"
54+
input = "src/cydifflib/__init__.py"
1055

1156
[tool.black]
1257
line-length = 120

setup.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/cydifflib/CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function(create_cython_target _name)
2+
if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx)
3+
set(${_name}
4+
${CMAKE_CURRENT_LIST_DIR}/${_name}.cxx
5+
PARENT_SCOPE)
6+
else()
7+
add_custom_command(
8+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_name}.cxx"
9+
MAIN_DEPENDENCY "${CMAKE_CURRENT_LIST_DIR}/${_name}.pyx"
10+
VERBATIM
11+
COMMAND
12+
Python::Interpreter -m cython "${CMAKE_CURRENT_LIST_DIR}/${_name}.pyx"
13+
--cplus --output-file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.cxx")
14+
15+
set(${_name}
16+
${CMAKE_CURRENT_BINARY_DIR}/${_name}.cxx
17+
PARENT_SCOPE)
18+
endif()
19+
endfunction(create_cython_target)
20+
21+
22+
function(rf_add_library name)
23+
if(CMAKE_VERSION VERSION_LESS 3.17)
24+
python_add_library(${name} MODULE ${ARGV})
25+
get_property(
26+
suffix
27+
TARGET ${name}
28+
PROPERTY SUFFIX)
29+
if(NOT suffix)
30+
set(suffix "${CMAKE_SHARED_MODULE_SUFFIX}")
31+
endif()
32+
set_property(TARGET ${name} PROPERTY SUFFIX ".${Python_SOABI}${suffix}")
33+
else()
34+
python_add_library(${name} MODULE WITH_SOABI ${ARGV})
35+
endif()
36+
endfunction(rf_add_library)
37+
38+
39+
create_cython_target(_initialize)
40+
rf_add_library(_initialize ${_initialize})
41+
target_compile_features(_initialize PUBLIC cxx_std_17)
42+
install(TARGETS _initialize DESTINATION cydifflib/)

src/cydifflib/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,8 @@
2626
For producing HTML side by side comparison with change highlights.
2727
"""
2828

29-
from __future__ import annotations
30-
3129
__author__ = "Max Bachmann"
3230
__license__ = "MIT"
33-
34-
import importlib.metadata
35-
36-
try:
37-
__version__: str = importlib.metadata.version(__package__ or __name__)
38-
except importlib.metadata.PackageNotFoundError:
39-
__version__: str = "0.0.0"
31+
__version__: str = "1.2.0"
4032

4133
from ._initialize import *
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# distutils: language=c++
2+
# cython: language_level=3, binding=True, linetrace=True
3+
14
__all__ = ['get_close_matches', 'ndiff', 'restore', 'SequenceMatcher',
25
'Differ','IS_CHARACTER_JUNK', 'IS_LINE_JUNK', 'context_diff',
36
'unified_diff', 'diff_bytes', 'HtmlDiff', 'Match']

src/cython/CMakeLists.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)