Skip to content

Commit

Permalink
migrate to pyproject.toml
Browse files Browse the repository at this point in the history
- fixes #1873
- add setuptools_scm
- drop setup.py
  + part of #1875
- drop Wrappers/Python/CMake
  • Loading branch information
casperdcl committed Jul 26, 2024
1 parent a9ce83a commit 3073029
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 208 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/build/
__pycache__/
/Wrappers/Python/build/
/Wrappers/Python/*.egg*/
/Wrappers/Python/cil/version.py
/Wrappers/Python/setup.py
__pycache__/
*.egg*
31 changes: 1 addition & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ else()
cmake_minimum_required(VERSION 3.4)
endif()

project (cil LANGUAGES CXX)
project(cil LANGUAGES CXX)

if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
cmake_policy(SET CMP0148 OLD)
Expand All @@ -44,37 +44,8 @@ if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()


# CIL version TAG is determined by git describe as for the conda package
# variable GIT_DESCRIBE_TAG
# https://docs.conda.io/projects/conda-build/en/stable/resources/define-metadata.html#templating-with-jinja
# https://stackoverflow.com/questions/38919840/get-package-version-for-conda-meta-yaml-from-source-file

find_package(Git REQUIRED)

find_package(Python COMPONENTS Interpreter REQUIRED)

if (Python_FOUND)
execute_process(COMMAND "${Python_EXECUTABLE}" ${CMAKE_CURRENT_SOURCE_DIR}/Wrappers/Python/CMake/parse_git_describe.py "${GIT_EXECUTABLE}"
RESULT_VARIABLE worked
OUTPUT_VARIABLE CIL_VERSION
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT worked EQUAL 0)
message(FATAL_ERROR "git describe returned ${worked}")
else()
string(REPLACE " " ";" CIL_VERSION ${CIL_VERSION})
list(LENGTH CIL_VERSION CIL_version_len)

list(GET CIL_VERSION 0 CIL_VERSION_MAJOR)
list(GET CIL_VERSION 1 CIL_VERSION_MINOR)
list(GET CIL_VERSION 2 CIL_VERSION_PATCH)
list(GET CIL_VERSION 3 CIL_NUM_COMMIT)
list(GET CIL_VERSION 4 CIL_COMMIT_HASH)

endif()
endif()


add_subdirectory(src/Core)
add_subdirectory(Wrappers/Python)
47 changes: 0 additions & 47 deletions Wrappers/Python/CMake/parse_git_describe.py

This file was deleted.

59 changes: 0 additions & 59 deletions Wrappers/Python/CMake/setup.py.in

This file was deleted.

20 changes: 0 additions & 20 deletions Wrappers/Python/CMake/sp_dir.py

This file was deleted.

25 changes: 0 additions & 25 deletions Wrappers/Python/CMake/version.py.in

This file was deleted.

30 changes: 6 additions & 24 deletions Wrappers/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ if (BUILD_PYTHON_WRAPPER)
if (PYTHON_DEST_DIR)
set(PYTHON_DEST "${PYTHON_DEST_DIR}")
else()
message(STATUS "python version ${PYTHON_DEST}")
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/CMake/sp_dir.py
OUTPUT_VARIABLE SP_DIR)
# remove trailing newline
string(REGEX REPLACE "\n$" "" PYTHON_DEST ${SP_DIR})
# append default site-packages
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import os; print(os.path.dirname(os.__file__))"
OUTPUT_VARIABLE PYTHON_DEST
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(PYTHON_DEST "${PYTHON_DEST}/site-packages")
endif()

Expand Down Expand Up @@ -58,30 +55,16 @@ if (BUILD_PYTHON_WRAPPER)

if (PYTHONINTERP_FOUND)
message("Python found " ${PYTHON_EXECUTABLE})
set(SETUP_PY "${CMAKE_CURRENT_SOURCE_DIR}/setup.py")
set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/timestamp")
file(GLOB_RECURSE DEPS ${CMAKE_CURRENT_SOURCE_DIR}/cil/*.py )
# TODO: add to add_custom_command DEPENDS the list of python files of the project.
# file(GLOB_RECURSE DEPS ${CMAKE_CURRENT_SOURCE_DIR}/cil/*.py )

# adds the CIL_VERSION to the setup.py
if (EXISTS ${SETUP_PY})
file(REMOVE ${SETUP_PY})
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/setup.py.in ${SETUP_PY})
# adds the version.py file to the source code with correct version string.
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/cil/version.py)
file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/cil/version.py)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMake/version.py.in ${CMAKE_CURRENT_SOURCE_DIR}/cil/version.py)



# add to add_custom_command DEPENDS the list of python files of the project.
# as a hack I remove ${OUTPUT}. This should trigger the new build.
file( REMOVE ${OUTPUT} )

add_custom_target(pythonsetup ALL
COMMAND ${CMAKE_COMMAND} -E env ${PYTHON_EXECUTABLE} -m pip install . -t ${PYTHON_DEST} --upgrade
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
DEPENDS cilacc)

Expand All @@ -90,7 +73,6 @@ if (BUILD_PYTHON_WRAPPER)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cil)
endif()


add_custom_target(PythonWrapper ALL DEPENDS pythonsetup)

endif()
Expand Down
39 changes: 39 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
version_file = "Wrappers/Python/cil/version.py"
version_file_template = """
version = '{version}'
major = {version_tuple[0]}
minor = {version_tuple[1]}
patch = {version_tuple[2]}
commit_hash = '{scm_version.node}'
num_commit = {scm_version.distance}
"""

[tool.setuptools]
package-dir = {"" = "Wrappers/Python"}

[tool.setuptools.packages.find]
where = ["Wrappers/Python"]
include = ["cil", "cil.*"]
exclude = ["data", "test"]

[project.urls]
#homepage = "https://ccpi.ac.uk/cil"
homepage = "https://tomographicimaging.github.io/CIL"
documentation = "https://tomographicimaging.github.io/CIL/nightly"
repository = "https://github.com/TomographicImaging/CIL"
changelog = "https://github.com/TomographicImaging/CIL/blob/master/CHANGELOG.md"

[project]
name = "cil"
dynamic = ["version"]
description = "Core Imaging Library"
license = {text = "Apache-2.0"}
maintainers = [{name="CIL developers", email="[email protected]"}]
requires-python = ">=3.10"
readme = "README.md"
keywords = ["tomography", "optimisation"]

0 comments on commit 3073029

Please sign in to comment.