From fe6eb358fbdea7d1c94143a5107b3b23c4d66d2d Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Tue, 4 Jun 2024 16:40:57 +0200 Subject: [PATCH] ENH: Update to pyproject.toml --- .../build-test-package-python-cuda.yml | 12 +- .github/workflows/build-test-package.yml | 5 +- CMakeLists.txt | 10 -- .../rtkconjugategradient.py | 5 +- .../rtkelektasynergygeometry.py | 5 +- applications/rtkorageometry/rtkorageometry.py | 5 +- .../rtksimulatedgeometry.py | 5 +- .../rtkvarianobigeometry.py | 5 +- pyproject.toml | 127 ++++++++++++++++++ setup.py | 65 --------- wrapping/CMakeLists.txt | 8 +- 11 files changed, 165 insertions(+), 87 deletions(-) create mode 100644 pyproject.toml delete mode 100755 setup.py diff --git a/.github/workflows/build-test-package-python-cuda.yml b/.github/workflows/build-test-package-python-cuda.yml index ea42b1356..27e56f89f 100644 --- a/.github/workflows/build-test-package-python-cuda.yml +++ b/.github/workflows/build-test-package-python-cuda.yml @@ -4,8 +4,8 @@ on: [push,pull_request] env: itk-wheel-tag: 'v5.4.0' - itk-python-package-tag: 'v5.4.0' - itk-python-package-org: 'InsightSoftwareConsortium' + itk-python-package-tag: '26495c927f31ea20616efe2b2bad05e9275ea3a5' + itk-python-package-org: 'SimonRit' itk-module-deps: "RTKConsortium/ITKCudaCommon@v1.1.0" jobs: @@ -40,6 +40,7 @@ jobs: export CUDA_VERSION_MAJOR=`(echo ${CUDA_VERSION} | cut -b1-2)` export CUDA_VERSION_MINOR=`(echo ${CUDA_VERSION} | cut -b3-)` CMAKE_OPTIONS="-DRTK_CUDA_VERSION=${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" + CMAKE_OPTIONS="${CMAKE_OPTIONS} -DRTK_BUILD_APPLICATIONS:BOOL=OFF" CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCUDAToolkit_ROOT=/usr/lib64/cuda${CUDA_VERSION}" CMAKE_OPTIONS="${CMAKE_OPTIONS} -DCMAKE_CUDA_COMPILER=/usr/lib64/cuda${CUDA_VERSION}/bin/nvcc" @@ -68,6 +69,8 @@ jobs: LIBCUBLAS=`basename /home/srit/Downloads/cuda${CUDA_VERSION}/targets/x86_64-linux/lib/libcublas.so.${CUDA_VERSION_MAJOR}*` LIBCUBLASLT=`basename /home/srit/Downloads/cuda${CUDA_VERSION}/targets/x86_64-linux/lib/libcublasLt.so.${CUDA_VERSION_MAJOR}*` LIBCUFFT=`basename /home/srit/Downloads/cuda${CUDA_VERSION}/targets/x86_64-linux/lib/libcufft.so.$((${CUDA_VERSION_MAJOR}-1))*` + sed -i "s/dependencies = \[/dependencies = [ \"itk-cudacommon-cuda${CUDA_VERSION} == 1.1.*\",/g" pyproject.toml + sed -i "s/itk-rtk/itk-rtk-cuda${CUDA_VERSION}/g" pyproject.toml ./dockcross-manylinux-download-cache-and-build-module-wheels.sh "${CMAKE_OPTIONS[@]}" -x "libcuda.so.1;${LIBCUDART};${LIBCUBLAS};${LIBCUBLASLT};${LIBCUFFT}" cp3${{ matrix.python3-minor-version }} mv *zst ../.. @@ -147,12 +150,15 @@ jobs: $CUDA_VERSION_MAJOR=$CUDA_VERSION.substring(0,2) $CUDA_VERSION_MINOR=$CUDA_VERSION.substring(2,$CUDA_VERSION.Length-2) $env:CUDA_PATH = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" + $env:CUDACXX = "$env:CUDA_PATH\bin\nvcc.exe" $env:Path = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin;" + $env:Path $LIBCUDART= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cudart64*dll" ).Name $LIBCUBLAS= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cublas64*dll" ).Name $LIBCUBLASLT= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cublasLt64*dll" ).Name $LIBCUFFT= (Get-Item "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}\bin\cufft64*dll" ).Name - ./windows-download-cache-and-build-module-wheels.ps1 "${{ matrix.python3-minor-version }}" -setup_options "--lib-paths ""C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}/bin"" --exclude-libs ""nvcuda.dll;concrt140.dll;${LIBCUDART};${LIBCUBLAS};${LIBCUBLASLT};${LIBCUFFT}""" -cmake_options "-DRTK_CUDA_VERSION=${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" + ((Get-Content -Path pyproject.toml) -replace "itk-rtk","itk-rtk-cuda${CUDA_VERSION}") | Set-Content -Path pyproject.toml + ((Get-Content -Path pyproject.toml) -replace "dependencies = \[","dependencies = [""itk-cudacommon-cuda${CUDA_VERSION} == 1.1.*"",") | Set-Content -Path pyproject.toml + ./windows-download-cache-and-build-module-wheels.ps1 "${{ matrix.python3-minor-version }}" -setup_options "--lib-paths ""C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}/bin"" --exclude-libs ""nvcuda.dll;concrt140.dll;${LIBCUDART};${LIBCUBLAS};${LIBCUBLASLT};${LIBCUFFT}""" -cmake_options """-DRTK_CUDA_VERSION=${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}"" ""-DRTK_BUILD_APPLICATIONS:BOOL=OFF""" mkdir -p '${{ github.workspace }}\dist' cp 'dist\*.whl' '${{ github.workspace }}\dist' diff --git a/.github/workflows/build-test-package.yml b/.github/workflows/build-test-package.yml index d3143cea5..777d79b58 100644 --- a/.github/workflows/build-test-package.yml +++ b/.github/workflows/build-test-package.yml @@ -7,11 +7,10 @@ jobs: uses: InsightSoftwareConsortium/ITKRemoteModuleBuildTestPackageAction/.github/workflows/build-test-cxx.yml@main python-build-workflow: - uses: InsightSoftwareConsortium/ITKRemoteModuleBuildTestPackageAction/.github/workflows/build-test-package-python.yml@main + uses: InsightSoftwareConsortium/ITKRemoteModuleBuildTestPackageAction/.github/workflows/build-test-package-python.yml@1939208aff6d226e33eef13df09747e8ba77459e with: cmake-options: '-DRTK_BUILD_APPLICATIONS:BOOL=OFF' - itk-wheel-tag: 'v5.4.0' - itk-python-package-tag: 'v5.4.0' + itk-python-package-tag: 'f38e8b0f38580807809b0412235fb2ba0946deba' itk-module-deps: "RTKConsortium/ITKCudaCommon@v1.1.0" secrets: pypi_password: ${{ secrets.pypi_password }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 855649401..415c1e3fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -280,16 +280,6 @@ option(RTK_BUILD_APPLICATIONS "Build RTK applications" ON) if(RTK_BUILD_APPLICATIONS) add_subdirectory(applications) endif() -if(ITK_WRAP_PYTHON) - # Install Python application - install(FILES applications/rtkconjugategradient/rtkconjugategradient.py - applications/rtkelektasynergygeometry/rtkelektasynergygeometry.py - applications/rtkorageometry/rtkorageometry.py - applications/rtksimulatedgeometry/rtksimulatedgeometry.py - applications/rtkvarianobigeometry/rtkvarianobigeometry.py - DESTINATION ${RTK_INSTALL_LIB_DIR} - COMPONENT PythonWheelRuntimeLibraries) -endif() # -------------------------------------------------------- # Setup KWStyle from ITK diff --git a/applications/rtkconjugategradient/rtkconjugategradient.py b/applications/rtkconjugategradient/rtkconjugategradient.py index c9511edff..8d05eadfa 100755 --- a/applications/rtkconjugategradient/rtkconjugategradient.py +++ b/applications/rtkconjugategradient/rtkconjugategradient.py @@ -17,7 +17,7 @@ def GetCudaImageFromImage(img): else: return img -if __name__ == '__main__': +def main(): # argument parsing parser = argparse.ArgumentParser(description= 'Reconstructs a 3D volume from a sequence of projections with a conjugate gradient technique', @@ -131,3 +131,6 @@ def GetCudaImageFromImage(img): writer.SetFileName(args_info.output) writer.SetInput(conjugategradient.GetOutput()) writer.Update() + +if __name__ == '__main__': + main() diff --git a/applications/rtkelektasynergygeometry/rtkelektasynergygeometry.py b/applications/rtkelektasynergygeometry/rtkelektasynergygeometry.py index 607d91123..b9a919f79 100755 --- a/applications/rtkelektasynergygeometry/rtkelektasynergygeometry.py +++ b/applications/rtkelektasynergygeometry/rtkelektasynergygeometry.py @@ -4,7 +4,7 @@ import itk from itk import RTK as rtk -if __name__ == '__main__': +def main(): # Argument parsing parser = argparse.ArgumentParser(description= "Creates an RTK geometry file from an Elekta Synergy acquisition.") @@ -27,3 +27,6 @@ xmlWriter.SetFilename(args.output) xmlWriter.SetObject(reader.GetGeometry()) xmlWriter.WriteFile() + +if __name__ == '__main__': + main() diff --git a/applications/rtkorageometry/rtkorageometry.py b/applications/rtkorageometry/rtkorageometry.py index 914f8a7d3..f50618860 100644 --- a/applications/rtkorageometry/rtkorageometry.py +++ b/applications/rtkorageometry/rtkorageometry.py @@ -3,7 +3,7 @@ import itk from itk import RTK as rtk -if __name__ == '__main__': +def main(): # Argument parsing parser = argparse.ArgumentParser(description= "Creates an RTK geometry file from a Varian OBI acquisition.") @@ -37,3 +37,6 @@ xmlWriter.SetFilename(args.output) xmlWriter.SetObject(reader.GetGeometry()) xmlWriter.WriteFile() + +if __name__ == '__main__': + main() diff --git a/applications/rtksimulatedgeometry/rtksimulatedgeometry.py b/applications/rtksimulatedgeometry/rtksimulatedgeometry.py index 313723626..b3c3a249d 100644 --- a/applications/rtksimulatedgeometry/rtksimulatedgeometry.py +++ b/applications/rtksimulatedgeometry/rtksimulatedgeometry.py @@ -3,7 +3,7 @@ import sys from itk import RTK as rtk -if __name__ == '__main__': +def main(): # Argument parsing parser = argparse.ArgumentParser(description= "Creates an RTK geometry file from simulated/regular trajectory. See https://www.openrtk.org/Doxygen/DocGeo3D.html for more information.") @@ -51,3 +51,6 @@ writer.SetFilename(args.output) writer.SetObject(geometry) writer.WriteFile() + +if __name__ == '__main__': + main() diff --git a/applications/rtkvarianobigeometry/rtkvarianobigeometry.py b/applications/rtkvarianobigeometry/rtkvarianobigeometry.py index 02fd74882..fc34b5267 100644 --- a/applications/rtkvarianobigeometry/rtkvarianobigeometry.py +++ b/applications/rtkvarianobigeometry/rtkvarianobigeometry.py @@ -4,7 +4,7 @@ import itk from itk import RTK as rtk -if __name__ == '__main__': +def main(): # Argument parsing parser = argparse.ArgumentParser(description= "Creates an RTK geometry file from a Varian OBI acquisition.") @@ -34,3 +34,6 @@ xmlWriter.SetFilename(args.output) xmlWriter.SetObject(reader.GetGeometry()) xmlWriter.WriteFile() + +if __name__ == '__main__': + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..b288db74f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,127 @@ +[build-system] +requires = ["scikit-build-core"] +build-backend = "scikit_build_core.build" + +[project] +name = "itk-rtk" +version = "2.5.0" +description = "The Reconstruction Toolkit (RTK) for fast circular cone-beam CT reconstruction" +readme = "README.md" +license = {file = "LICENSE.TXT"} +authors = [ + { name = "RTK Consortium", email = "simon.rit@creatis.insa-lyon.fr" }, +] +keywords = [ + "itk", + "rtk", +] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: Healthcare Industry", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: Apache Software License", + "Operating System :: Android", + "Operating System :: MacOS", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX", + "Operating System :: Unix", + "Programming Language :: C++", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Topic :: Scientific/Engineering", + "Topic :: Scientific/Engineering :: Information Analysis", + "Topic :: Scientific/Engineering :: Medical Science Apps.", + "Topic :: Software Development :: Libraries", +] +requires-python = ">=3.8" +dependencies = [ + "itk == 5.4.*", +] + +[project.scripts] +rtkconjugategradient = "itk.rtkconjugategradient:main" +rtkelektasynergygeometry = "itk.rtkelektasynergygeometry:main" +rtkorageometry = "itk.rtkorageometry:main" +rtksimulatedgeometry = "itk.rtksimulatedgeometry:main" +rtkvarianobigeometry = "itk.rtkvarianobigeometry:main" + +[project.urls] +Download = "https://github.com/RTKConsortium/RTK" +Homepage = "https://www.openrtk.org" + +[tool.scikit-build] +# The versions of CMake to allow. If CMake is not present on the system or does +# not pass this specifier, it will be downloaded via PyPI if possible. An empty +# string will disable this check. +cmake.version = ">=3.16.3" + +# A list of args to pass to CMake when configuring the project. Setting this in +# config or envvar will override toml. See also ``cmake.define``. +cmake.args = [] + +# A table of defines to pass to CMake when configuring the project. Additive. +cmake.define = {} + +# Verbose printout when building. +cmake.verbose = true + +# The build type to use when building the project. Valid options are: "Debug", +# "Release", "RelWithDebInfo", "MinSizeRel", "", etc. +cmake.build-type = "Release" + +# The source directory to use when building the project. Currently only affects +# the native builder (not the setuptools plugin). +cmake.source-dir = "." + +# The versions of Ninja to allow. If Ninja is not present on the system or does +# not pass this specifier, it will be downloaded via PyPI if possible. An empty +# string will disable this check. +ninja.version = ">=1.11" + +# If CMake is not present on the system or is older required, it will be +# downloaded via PyPI if possible. An empty string will disable this check. +ninja.make-fallback = true + +# The logging level to display, "DEBUG", "INFO", "WARNING", and "ERROR" are +# possible options. +logging.level = "INFO" + +# Files to include in the SDist even if they are skipped by default. Supports +# gitignore syntax. +sdist.include = [] + +# Files to exclude from the SDist even if they are included by default. Supports +# gitignore syntax. +sdist.exclude = [] + +# A list of license files to include in the wheel. Supports glob patterns. +wheel.license-files = ["LICEN[CS]E*",] + +# Target the platlib or the purelib. If not set, the default is to target the +# platlib if wheel.cmake is true, and the purelib otherwise. +wheel.platlib = "false" + +# If CMake is less than this value, backport a copy of FindPython. Set to 0 +# disable this, or the empty string. +backport.find-python = "3.26.1" + +# Select the editable mode to use. Can be "redirect" (default) or "inplace". +editable.mode = "redirect" + +# Rebuild the project when the package is imported. The build-directory must be +# set. +editable.rebuild = false + +# The components to install. If empty, all default components are installed. +install.components = [] + +# Whether to strip the binaries. True for scikit-build-core 0.5+. +install.strip = true + +# If set, this will provide a method for backward compatibility. +minimum-version = "0.9.5" + +# The build directory. Defaults to a temporary directory, but can be set. +build-dir = "build/{wheel_tag}" diff --git a/setup.py b/setup.py deleted file mode 100755 index dbea42bf0..000000000 --- a/setup.py +++ /dev/null @@ -1,65 +0,0 @@ -# -*- coding: utf-8 -*- -from os import sys - -try: - from skbuild import setup -except ImportError: - print('scikit-build is required to build from source.', file=sys.stderr) - print('Please run:', file=sys.stderr) - print('', file=sys.stderr) - print(' python -m pip install scikit-build') - sys.exit(1) - -# Configure wheel name if CUDA is used -wheel_name='itk-rtk' -wheel_requirements=[r'itk==5.4.*'] - -# Extract cuda version from the RTK_CUDA_VERSION cmake option -for arg in sys.argv: - if "RTK_CUDA_VERSION" in str(arg): - cuda_version = arg.rsplit('RTK_CUDA_VERSION=', 1)[-1] - wheel_name += '-cuda' + cuda_version.replace('.', '') - cudacommon_wheel_name = wheel_name.replace('rtk', 'cudacommon') - wheel_requirements.append(fr'{cudacommon_wheel_name}') - -setup( - name=wheel_name, - version='2.5.0', - author='RTK Consortium', - author_email='rtk-users@openrtk.org', - packages=['itk'], - package_dir={'itk': 'itk'}, - download_url=r'https://github.com/RTKConsortium/RTK', - description=r'The Reconstruction Toolkit (RTK) for fast circular cone-beam CT reconstruction.', - long_description='Based on the Insight Toolkit ITK, RTK provides: basic operators for reconstruction (e.g. filtering, forward, projection and backprojection), multithreaded CPU and GPU versions, tools for respiratory motion correction, I/O for several scanners, preprocessing of raw data for scatter correction.', - classifiers=[ - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python", - "Programming Language :: C++", - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "Intended Audience :: Education", - "Intended Audience :: Healthcare Industry", - "Intended Audience :: Science/Research", - "Topic :: Scientific/Engineering", - "Topic :: Scientific/Engineering :: Medical Science Apps.", - "Topic :: Scientific/Engineering :: Information Analysis", - "Topic :: Software Development :: Libraries", - "Operating System :: Android", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX", - "Operating System :: Unix", - "Operating System :: MacOS" - ], - scripts=[ - "lib/rtkconjugategradient.py", - "lib/rtkelektasynergygeometry.py", - "lib/rtkorageometry.py", - "lib/rtksimulatedgeometry.py", - "lib/rtkvarianobigeometry.py" - ], - license='Apache', - keywords='RTK Reconstruction Toolkit', - url=r'https://www.openrtk.org/', - install_requires=wheel_requirements - ) diff --git a/wrapping/CMakeLists.txt b/wrapping/CMakeLists.txt index 44ad3bc7a..83afdc330 100644 --- a/wrapping/CMakeLists.txt +++ b/wrapping/CMakeLists.txt @@ -32,4 +32,10 @@ wrap_itk_python_bindings_install(/itk "RTK" ${RTK_SOURCE_DIR}/applications/rtk3Doutputimage_group.py ${RTK_SOURCE_DIR}/applications/rtkinputprojections_group.py ${RTK_SOURCE_DIR}/applications/rtkiterations_group.py - ${RTK_SOURCE_DIR}/applications/rtkprojectors_group.py) + ${RTK_SOURCE_DIR}/applications/rtkprojectors_group.py + ${RTK_SOURCE_DIR}/applications/rtkconjugategradient/rtkconjugategradient.py + ${RTK_SOURCE_DIR}/applications/rtkelektasynergygeometry/rtkelektasynergygeometry.py + ${RTK_SOURCE_DIR}/applications/rtkorageometry/rtkorageometry.py + ${RTK_SOURCE_DIR}/applications/rtksimulatedgeometry/rtksimulatedgeometry.py + ${RTK_SOURCE_DIR}/applications/rtkvarianobigeometry/rtkvarianobigeometry.py +)