From 4b8a3cbb06362672cbced8ba136b0b31f9100b92 Mon Sep 17 00:00:00 2001 From: "M. Eric Irrgang" Date: Fri, 8 Aug 2025 14:51:49 -0700 Subject: [PATCH] Support Python wheel packaging. - Update CMake infrastructure. - Update Python source layout. - Add pyproject.toml. - Add additional instructions. Deferred: - Editable installs are not yet supported because of the way the Python code calls `ctypes`. --- CMakeLists.txt | 4 +- README.md | 20 +++++++++- pyproject.toml | 40 +++++++++++++++++++ src/CMakeLists.txt | 13 ++---- .../__init__.py} | 2 +- 5 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 pyproject.toml rename src/{xrayphysics.py => xrayphysics/__init__.py} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e922031..397630a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ -cmake_minimum_required(VERSION 3.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.20 FATAL_ERROR) -project(xrayphysics) +project(xrayphysics CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/README.md b/README.md index f61d407..eb32266 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,25 @@ The x-ray source models are at least as accurate as TASMICS and much more flexib ## Installation and Usage +A python *wheel* package can be built and installed as follows. + +```commandline +python -m pip install --upgrade pip build +python -m build . +pip install dist/xrayphysics*whl +``` + +The wildcard `*` is used in the above example because the exact package file name may vary. + +If the build system cannot find all dependencies, they can be provided with CMake variables. +For example, + +```commandline +python -m build . \ + -Ccmake.define.CMAKE_PREFIX_PATH=/opt/homebrew \ + -Ccmake.define.OpenMP_ROOT=/opt/homebrew/opt/libomp +``` + Documentation is available [here](https://xrayphysics.readthedocs.io/) Installation and usage information is posted on the [wiki page](https://github.com/kylechampley/XrayPhysics/wiki) @@ -40,4 +59,3 @@ Champley, Kyle M., Stephen G. Azevedo, Isaac M. Seetho, Steven M. Glenn, Larry D Kyle Champley and Timo Bremer. ”Efficient and Accurate Correction of Beam Hardening Artifacts.”, 3rd International Congress on Image Formation in X-ray CT, 2014. - diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4cffa3d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,40 @@ +[build-system] +requires = ["scikit-build-core"] +build-backend = "scikit_build_core.build" + +[project] +name = "xrayphysics" +authors = [ + { name = "Kyle Champley", email = "champley@gmail.com" }, +] +description = "x-ray cross section tables, x-ray tube source simulation, beam hardening correction, and dual energy decompositon" +readme = "README.md" +requires-python = ">=3.6" +#license = { text = "internal use only" } +dependencies = [ + "numpy", +] +version = "1.2" + +[project.optional-dependencies] + +[tool.scikit-build] + +# Extra args to pass directly to the builder in the build step. +build.tool-args = [] + +# The build targets to use when building the project. Empty builds the default +# target. +build.targets = [] + +# The components to install. If empty, all default components are installed. +install.components = [] + +sdist.cmake = true +sdist.include = [ + "LICENSE", +] + +wheel.packages = ["src/xrayphysics"] +wheel.license-files = ["LICENSE.txt"] +wheel.py-api = "py3" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed9df05..163df9b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,3 @@ -cmake_minimum_required(VERSION 3.0 FATAL_ERROR) - -project(xrayphysics CXX) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - find_package(OpenMP REQUIRED) if (WIN32) @@ -62,7 +55,7 @@ target_link_libraries(${PROJECT_NAME} install(TARGETS ${PROJECT_NAME} PUBLIC_HEADER DESTINATION include - RUNTIME DESTINATION bin - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib + RUNTIME DESTINATION xrayphysics + ARCHIVE DESTINATION xrayphysics + LIBRARY DESTINATION xrayphysics ) diff --git a/src/xrayphysics.py b/src/xrayphysics/__init__.py similarity index 99% rename from src/xrayphysics.py rename to src/xrayphysics/__init__.py index 3cc4143..6dc60d6 100644 --- a/src/xrayphysics.py +++ b/src/xrayphysics/__init__.py @@ -160,7 +160,7 @@ def resample(self, gammas, s, gammas_out): Args: gammas (numpy array): the energy samples (keV) of the given spectra s (numpy array): the given spectra to resample - gammmas_out (numpy array): the energy samples (keV) to rebin to + gammas_out (numpy array): the energy samples (keV) to rebin to Returns: resampled spectra