Skip to content

Commit 5d6b29e

Browse files
authored
Use pyproject.toml instead of setup.py (#1168)
* Make some imports lazy * Switch from setup.py to pure pyproject.toml. Many thanks to @barrettMCW for showing how this could be done with Cython. * Find python headers
1 parent 3bd7370 commit 5d6b29e

File tree

10 files changed

+127
-129
lines changed

10 files changed

+127
-129
lines changed

.circleci/config.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
py39:
6868
working_directory: ~/project
6969
machine:
70-
image: ubuntu-2204:current
70+
image: ubuntu-2404:current
7171
steps:
7272
- checkout
7373
- upgradepython:
@@ -93,7 +93,7 @@ jobs:
9393
py310:
9494
working_directory: ~/project
9595
machine:
96-
image: ubuntu-2204:current
96+
image: ubuntu-2404:current
9797
steps:
9898
- checkout
9999
- upgradepython:
@@ -119,7 +119,7 @@ jobs:
119119
py311:
120120
working_directory: ~/project
121121
machine:
122-
image: ubuntu-2204:current
122+
image: ubuntu-2404:current
123123
steps:
124124
- checkout
125125
- upgradepython:
@@ -145,7 +145,7 @@ jobs:
145145
py312:
146146
working_directory: ~/project
147147
machine:
148-
image: ubuntu-2204:current
148+
image: ubuntu-2404:current
149149
steps:
150150
- checkout
151151
- upgradepython:
@@ -171,7 +171,7 @@ jobs:
171171
py313:
172172
working_directory: ~/project
173173
machine:
174-
image: ubuntu-2204:current
174+
image: ubuntu-2404:current
175175
steps:
176176
- checkout
177177
- upgradepython:
@@ -213,7 +213,7 @@ jobs:
213213
docker:
214214
working_directory: ~/project
215215
machine:
216-
image: ubuntu-2204:current
216+
image: ubuntu-2404:current
217217
steps:
218218
- checkout
219219
- run:
@@ -245,7 +245,7 @@ jobs:
245245
publish_docker:
246246
working_directory: ~/project
247247
machine:
248-
image: ubuntu-2204:current
248+
image: ubuntu-2404:current
249249
steps:
250250
- checkout
251251
- attach_workspace:
@@ -266,7 +266,7 @@ jobs:
266266
wheels:
267267
working_directory: ~/project
268268
machine:
269-
image: ubuntu-2204:current
269+
image: ubuntu-2404:current
270270
steps:
271271
- checkout
272272
# - setup_remote_docker

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
cmake_minimum_required(VERSION 3.6.2)
1+
cmake_minimum_required(VERSION 3.15...3.26)
22

3-
project(histomicstk)
3+
project(histomicstk LANGUAGES CXX)
44

5-
find_package(PythonInterp REQUIRED)
6-
find_package(PythonExtensions REQUIRED)
5+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module NumPy)
76

87
add_subdirectory(histomicstk/features)
98
add_subdirectory(histomicstk/segmentation/label)

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Ready to contribute? Here's how to set up ``HistomicsTK`` for local development.
6969
$ mkvirtualenv HistomicsTK
7070
$ cd HistomicsTK/
7171
$ python -m pip install setuptools-scm Cython>=0.25.2 scikit-build>=0.8.1 cmake>=0.6.0 numpy>=1.12.1
72-
$ python setup.py develop
72+
$ python -m pip install .
7373

7474
Of course, any type of virtual python environment will do. These instructions are equally applicable inside ``conda`` environments.
7575

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ include LICENSE
44
include NOTICE
55
include *.rst
66
global-include CMakeLists.txt
7-
include setup.py
87
include pyproject.toml
98
include requirements-dev.txt
109
graft histomicstk

build_wheels.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ docker create --name wheels dsarchive/histomicstk_wheels
1010
docker cp wheels:/io/wheels .
1111
docker rm wheels
1212

13-
python -m pip install scikit-build
14-
python setup.py sdist
13+
python -m pip install scikit-build build
14+
python -m build
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
find_package(Cython REQUIRED)
2-
find_package(NumPy REQUIRED)
1+
find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED)
32

4-
add_cython_target(_compute_marginal_glcm_probs_cython CXX)
5-
add_library(_compute_marginal_glcm_probs_cython MODULE ${_compute_marginal_glcm_probs_cython})
6-
python_extension_module(_compute_marginal_glcm_probs_cython)
7-
target_include_directories(_compute_marginal_glcm_probs_cython PRIVATE ${NumPy_INCLUDE_DIR})
3+
add_custom_command(
4+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_compute_marginal_glcm_probs_cython.cpp
5+
COMMENT
6+
"Making ${CMAKE_CURRENT_BINARY_DIR}/_compute_marginal_glcm_probs_cython.cpp from ${CMAKE_CURRENT_SOURCE_DIR}/_compute_marginal_glcm_probs_cython.pyx"
7+
COMMAND Python::Interpreter -m cython --cplus -o "${CMAKE_CURRENT_BINARY_DIR}/_compute_marginal_glcm_probs_cython.cpp"
8+
"${CMAKE_CURRENT_SOURCE_DIR}/_compute_marginal_glcm_probs_cython.pyx"
9+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/_compute_marginal_glcm_probs_cython.pyx"
10+
VERBATIM)
811

9-
install(TARGETS _compute_marginal_glcm_probs_cython LIBRARY DESTINATION histomicstk/features)
12+
python_add_library(_compute_marginal_glcm_probs_cython MODULE
13+
"${CMAKE_CURRENT_BINARY_DIR}/_compute_marginal_glcm_probs_cython.cpp"
14+
WITH_SOABI)
15+
16+
target_link_libraries(_compute_marginal_glcm_probs_cython PRIVATE Python::Module Python::NumPy)
17+
18+
install(TARGETS _compute_marginal_glcm_probs_cython DESTINATION histomicstk/features)
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
find_package(Cython REQUIRED)
2-
find_package(NumPy REQUIRED)
1+
find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED)
32

4-
add_cython_target(_trace_object_boundaries_cython CXX)
5-
add_library(_trace_object_boundaries_cython MODULE ${_trace_object_boundaries_cython})
6-
python_extension_module(_trace_object_boundaries_cython)
7-
message("NUMPY_INCLUDE_DIRS:${NumPy_INCLUDE_DIR}")
8-
target_include_directories(_trace_object_boundaries_cython PRIVATE ${NumPy_INCLUDE_DIR})
3+
add_custom_command(
4+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_trace_object_boundaries_cython.cpp
5+
COMMENT
6+
"Making ${CMAKE_CURRENT_BINARY_DIR}/_trace_object_boundaries_cython.cpp from ${CMAKE_CURRENT_SOURCE_DIR}/_trace_object_boundaries_cython.pyx"
7+
COMMAND Python::Interpreter -m cython --cplus -o "${CMAKE_CURRENT_BINARY_DIR}/_trace_object_boundaries_cython.cpp"
8+
"${CMAKE_CURRENT_SOURCE_DIR}/_trace_object_boundaries_cython.pyx"
9+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/_trace_object_boundaries_cython.pyx"
10+
VERBATIM)
911

10-
install(TARGETS _trace_object_boundaries_cython LIBRARY DESTINATION histomicstk/segmentation/label)
12+
python_add_library(_trace_object_boundaries_cython MODULE
13+
"${CMAKE_CURRENT_BINARY_DIR}/_trace_object_boundaries_cython.cpp"
14+
WITH_SOABI)
15+
16+
target_link_libraries(_trace_object_boundaries_cython PRIVATE Python::Module Python::NumPy)
17+
18+
install(TARGETS _trace_object_boundaries_cython DESTINATION histomicstk/segmentation/label)
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
find_package(Cython REQUIRED)
2-
find_package(NumPy REQUIRED)
1+
find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED)
32

4-
add_cython_target(_max_clustering_cython CXX)
5-
add_library(_max_clustering_cython MODULE ${_max_clustering_cython})
6-
python_extension_module(_max_clustering_cython)
7-
target_include_directories(_max_clustering_cython PRIVATE ${NumPy_INCLUDE_DIR})
3+
add_custom_command(
4+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/_max_clustering_cython.cpp
5+
COMMENT
6+
"Making ${CMAKE_CURRENT_BINARY_DIR}/_max_clustering_cython.cpp from ${CMAKE_CURRENT_SOURCE_DIR}/_max_clustering_cython.pyx"
7+
COMMAND Python::Interpreter -m cython --cplus -o "${CMAKE_CURRENT_BINARY_DIR}/_max_clustering_cython.cpp"
8+
"${CMAKE_CURRENT_SOURCE_DIR}/_max_clustering_cython.pyx"
9+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/_max_clustering_cython.pyx"
10+
VERBATIM)
811

9-
install(TARGETS _max_clustering_cython LIBRARY DESTINATION histomicstk/segmentation/nuclear)
12+
python_add_library(_max_clustering_cython MODULE
13+
"${CMAKE_CURRENT_BINARY_DIR}/_max_clustering_cython.cpp"
14+
WITH_SOABI)
15+
16+
target_link_libraries(_max_clustering_cython PRIVATE Python::Module Python::NumPy)
17+
18+
install(TARGETS _max_clustering_cython DESTINATION histomicstk/segmentation/nuclear)

pyproject.toml

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,71 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja", "numpy", "cython", "setuptools-scm"]
2+
requires = ["scikit-build-core>=0.7", "setuptools-scm", "cython>=0.29", "numpy"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "histomicstk"
7+
description = "A Python toolkit for Histopathology Image Analysis"
8+
readme = "README.rst"
9+
authors = [
10+
{name = "Kitware, Inc.", email = "developers@digitalslidearchive.net"}
11+
]
12+
urls = {Homepage = "https://github.com/DigitalSlideArchive/HistomicsTK"}
13+
license = {text = "Apache Software License 2.0"}
14+
classifiers = [
15+
"Development Status :: 5 - Production/Stable",
16+
"License :: OSI Approved :: Apache Software License",
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 3.9",
19+
"Programming Language :: Python :: 3.10",
20+
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
23+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
24+
"Topic :: Software Development :: Libraries :: Python Modules",
25+
]
26+
keywords = ["histomicstk"]
27+
requires-python = ">=3.9"
28+
dependencies = [
29+
"girder-client",
30+
"nimfa",
31+
"numpy",
32+
"scipy",
33+
"Pillow",
34+
"pandas",
35+
"scikit-image",
36+
"scikit-learn",
37+
"imageio",
38+
"shapely",
39+
"sqlalchemy",
40+
"matplotlib",
41+
"pyvips",
42+
"dask[dataframe]<2024.11.0",
43+
"distributed",
44+
"large-image[sources];sys.platform=='linux'",
45+
"large-image[common];sys.platform!='linux'",
46+
"large-image-converter;sys.platform=='linux'",
47+
"girder-slicer-cli-web",
48+
"ctk-cli",
49+
"opencv-python-headless",
50+
]
51+
dynamic = ["version"]
52+
53+
[project.scripts]
54+
histomicstk = "histomicstk.cli.__main__:main"
55+
56+
[tool.scikit-build]
57+
wheel.packages = ["histomicstk"]
58+
sdist.exclude = ["*.git*"]
59+
cmake.build-type = "Release"
60+
61+
[tool.setuptools_scm]
62+
local_scheme = "no-local-version"
63+
fallback_version = "0.0.0"
64+
65+
[tool.setuptools.package-data]
66+
"*" = ["*.pyx", "*.pxd"]
367

468
[tool.codespell]
5-
# Ref: https://github.com/codespell-project/codespell#using-a-config-file
669
skip = '.git*,*.pdf,*.svg,.pre-commit-config.yaml'
770
check-hidden = true
871
ignore-regex = '(^\s*"image/\S+": ".*)'

setup.py

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

0 commit comments

Comments
 (0)