Skip to content

Commit e0460b5

Browse files
authored
Migrate from setuptools to scikit-build-core (#121)
- Replace setuptools build backend with scikit-build-core in pyproject.toml - Add CMakeLists.txt for building Cython extension with platform-specific RPATH
1 parent a02a516 commit e0460b5

File tree

5 files changed

+278
-149
lines changed

5 files changed

+278
-149
lines changed

CMakeLists.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
cmake_minimum_required(VERSION 3.15...3.27)
2+
project(${SKBUILD_PROJECT_NAME} LANGUAGES C)
3+
4+
# Find Python
5+
find_package(
6+
Python
7+
COMPONENTS Interpreter Development.Module NumPy
8+
REQUIRED)
9+
10+
# Get NumPy include directory
11+
message(STATUS "NumPy include directory: ${Python_NumPy_INCLUDE_DIRS}")
12+
13+
# Cythonize the .pyx file to .c
14+
add_custom_command(
15+
OUTPUT cutil.c
16+
COMMENT "Cythonizing ${CMAKE_CURRENT_SOURCE_DIR}/src/simplification/cutil.pyx"
17+
COMMAND Python::Interpreter -m cython
18+
"${CMAKE_CURRENT_SOURCE_DIR}/src/simplification/cutil.pyx"
19+
--output-file cutil.c
20+
-I "${CMAKE_CURRENT_SOURCE_DIR}/src/simplification"
21+
DEPENDS src/simplification/cutil.pyx src/simplification/rdp_p.pxd
22+
VERBATIM)
23+
24+
# Create the extension module
25+
python_add_library(cutil MODULE cutil.c WITH_SOABI)
26+
27+
# Set include directories
28+
target_include_directories(cutil PRIVATE
29+
${CMAKE_CURRENT_SOURCE_DIR}/src/simplification
30+
${Python_NumPy_INCLUDE_DIRS}
31+
)
32+
33+
# Link against the rdp library
34+
# The library is pre-built and located in src/simplification/
35+
find_library(RDP_LIBRARY
36+
NAMES rdp librdp
37+
PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/simplification
38+
NO_DEFAULT_PATH
39+
REQUIRED
40+
)
41+
message(STATUS "Found RDP library: ${RDP_LIBRARY}")
42+
43+
target_link_libraries(cutil PRIVATE ${RDP_LIBRARY})
44+
45+
# Set RPATH for different platforms
46+
if(APPLE)
47+
set_target_properties(cutil PROPERTIES
48+
INSTALL_RPATH "@loader_path"
49+
BUILD_WITH_INSTALL_RPATH TRUE
50+
)
51+
elseif(UNIX)
52+
set_target_properties(cutil PROPERTIES
53+
INSTALL_RPATH "$ORIGIN"
54+
BUILD_WITH_INSTALL_RPATH TRUE
55+
)
56+
endif()
57+
58+
# Install the extension module
59+
install(TARGETS cutil DESTINATION simplification)
60+
61+
# Install the shared library
62+
if(APPLE)
63+
set(RDP_LIB_NAME "librdp.dylib")
64+
elseif(UNIX)
65+
set(RDP_LIB_NAME "librdp.so")
66+
elseif(WIN32)
67+
set(RDP_LIB_NAME "rdp.dll")
68+
endif()
69+
70+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/simplification/${RDP_LIB_NAME}
71+
DESTINATION simplification)
72+
73+
# Install header file
74+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/simplification/header.h
75+
DESTINATION simplification)

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ Simplify a LineString using the [Ramer–Douglas–Peucker](https://en.wikipedia
1111
`conda install conda-forge::simplification`
1212

1313
### Installing for local development
14-
1. Ensure you have a copy of `librdp` from https://github.com/urschrei/rdp/releases, and it's in the `src/simplification` subdir
15-
2. run `pip install -e .[test] --use-pep517`
14+
1. Ensure you have a copy of `librdp` and `header.h` from https://github.com/urschrei/rdp/releases, and it's in the `src/simplification` subdir
15+
2. run `uv sync --dev`
1616
3. run `pytest .`
17+
4. If you make changes, you must rebuild the extension: `uv sync --reinstall`
18+
19+
## Building SDist and Wheels
20+
1. Ensure that `librdp` and header are present, as above
21+
2. Run `uv build --sdist --wheel`
1722

1823
### Supported Python Versions
1924
Simplification supports all [_currently_ supported Python versions](https://devguide.python.org/versions/).

pyproject.toml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[project]
22
name = "simplification"
3-
dynamic = ["version", "readme"]
3+
version = "0.7.15"
44
description = "Fast linestring simplification using RDP or Visvalingam-Whyatt and a Rust binary"
5+
readme = "README.md"
56
requires-python = ">=3.10"
67
dependencies = [
78
"numpy >= 2.0.0",
@@ -29,37 +30,28 @@ classifiers = [
2930
Repository = "https://github.com/urschrei/simplification"
3031
Tracker = "https://github.com/urschrei/simplification/issues"
3132

32-
[project.optional-dependencies]
33-
test = ["pytest >= 7.4.2"]
34-
35-
[tool.setuptools.packages.find]
36-
where = ["src"]
37-
38-
[tool.setuptools.package-data]
39-
simplification = ["*.dylib", "*.dll", "*.so", "*.h"]
33+
[dependency-groups]
34+
dev = [
35+
"pytest>=8.4.1",
36+
]
4037

41-
[tool.setuptools.dynamic]
42-
readme = {file = ["README.md", "LICENSE.md"], content-type = "text/markdown"}
38+
[tool.scikit-build]
39+
minimum-version = "build-system.requires"
40+
wheel.packages = ["src/simplification"]
4341

4442
[build-system]
45-
build-backend = "setuptools.build_meta"
4643
requires = [
47-
"setuptools >= 45",
48-
"setuptools-scm[toml] >= 6.2",
44+
"scikit-build-core>=0.10",
4945
"numpy >= 2.0.0",
50-
"cython >= 3.0.0",
51-
"wheel >= 0.29.0"
46+
"cython >= 3.1.0",
5247
]
48+
build-backend = "scikit_build_core.build"
5349

5450
[tool.pytest.ini_options]
55-
minversion = "6.2.2"
51+
minversion = "8.4.1"
5652
addopts = [
5753
"--import-mode=importlib",
5854
]
5955
testpaths = [
6056
"tests",
6157
]
62-
63-
[tool.setuptools_scm]
64-
write_to = "src/_version.py"
65-

setup.py

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

0 commit comments

Comments
 (0)