Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Switch Python bindings to pybind11. #57

Merged
merged 6 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.eggs
.pytest_cache
*.egg-info
__pycache__
tags
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "python/pybind11"]
path = python/pybind11
url = https://github.com/pybind/pybind11.git
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ services:

before_install:
- docker pull bluebrain/spack
- docker run -v $PWD:/source -w /source bluebrain/spack spack diy --test=root mvdtool@develop
- docker run -v $PWD:/source -w /source bluebrain/spack:latest spack diy --test=root mvdtool@develop

script: "ruby -ne 'puts $_ if /^==>.*make.*test/../.*phase.*install/ and not /^==>|make: \\*\\*\\*/' spack-build.out"
45 changes: 32 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
project(MVDTool)
cmake_minimum_required(VERSION 3.0)

include(CTest)

set(MVDTOOL_VERSION_MAJOR 1)
set(MVDTOOL_VERSION_MINOR 5)
set(MVDTOOL_VERSION_PATCH 2)
# get version from Python package
find_package(PythonInterp REQUIRED)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but isn't that for module dependencies? We're trying to get just the version out of setup.py, without requiring any python modules to be installed, really.

execute_process(COMMAND ${PYTHON_EXECUTABLE} setup.py --version
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE PY_VERSION_FAILED
OUTPUT_VARIABLE PY_PKG_VERSION_FULL
ERROR_VARIABLE PY_VERSION_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(PY_VERSION_FAILED)
message(
FATAL_ERROR
"Could not retrieve version from command '${PYTHON_EXECUTABLE} setup.py --version'\n"
${PY_VERSION_ERROR})
endif()
# keep last line of command output
string(REPLACE "\n"
";"
PY_PKG_VERSION_FULL
"${PY_PKG_VERSION_FULL}")
list(GET PY_PKG_VERSION_FULL -1 PY_PKG_VERSION_FULL)
# keep MAJOR.MINOR.PATCH
string(REGEX
REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+).*"
"\\1"
PY_PKG_VERSION
"${PY_PKG_VERSION_FULL}")

project(MVDTool VERSION ${PY_PKG_VERSION})

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake
${PROJECT_SOURCE_DIR}/CMake/portability
${PROJECT_SOURCE_DIR}/CMake/packages
${PROJECT_SOURCE_DIR}/CMake/config)

include(CTest)
include(GNUInstallDirs)
include(PackageConfig)
include(ReleaseDebugAutoFlags)


option(MVDTOOL_INSTALL_HIGHFIVE "Install header of dependency HighFive (needed for subprojects)" ON)
option(MVDTOOL_UNIT_TESTS "Enable or disable unit tests" ON)
option(BUILD_UNIT_TESTS "Enable or disable unit tests" ON)
option(BUILD_PYTHON_BINDINGS "Build python bindings?" OFF)
set(Boost_NO_BOOST_CMAKE TRUE)

Expand All @@ -26,16 +48,13 @@ find_package(Boost 1.41 QUIET REQUIRED COMPONENTS system)
find_package(HDF5 QUIET REQUIRED)
find_package(HighFive QUIET REQUIRED)

include(PackageConfig)

FILE(GLOB MVDTOOL_HEADERS "include/mvd/*.hpp")
FILE(GLOB MVDTOOLE_BITS_HEADERS "include/mvd/*/*.hpp")
set(MVDTOOL_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")

add_subdirectory(src)

if(BUILD_PYTHON_BINDINGS)
add_subdirectory(python)
endif()

add_subdirectory(src)
add_subdirectory(tests/unit)
93 changes: 4 additions & 89 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,90 +1,5 @@
##############################################
# Requirements
find_package(PythonComplete QUIET)
find_package(Cython REQUIRED)





##############################################
# Definitions
set(cymod_src "${CMAKE_CURRENT_SOURCE_DIR}/mvdtool.pyx")
set(default_cybindings_cpp "${CMAKE_CURRENT_SOURCE_DIR}/mvdtool.cpp")
set(cybindings_cpp "${CMAKE_CURRENT_BINARY_DIR}/mvdtool.cpp")
set(local_include_dir "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(cy_sources
mvdtool.pyx
include/boost.pxd
include/MVD2.pxd
include/MVD3.pxd
include/MVD_MVDType.pxd
include/MVD.pxd
include/std.pxd)

##############################################
# Rules

# .pyx -> .cpp
add_custom_command(
OUTPUT ${cybindings_cpp}
COMMAND ${CYTHON_EXECUTABLE} ${CYTHON_FLAGS} --fast-fail --cplus -I${local_include_dir} --output-file ${cybindings_cpp} ${cymod_src}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# No dependencies, except own sources
DEPENDS ${cy_sources}
COMMENT "Cythonizing ${cymod_src}"
)

# .cpp -> shared_lib
add_definitions("-std=c++11" "-Wfatal-errors" "-Wno-strict-aliasing")
python_add_module(mvdtool ${cybindings_cpp})
target_include_directories(mvdtool PRIVATE ${PYTHON_INCLUDE_DIRS} ${local_include_dir})
target_link_libraries(mvdtool MVDTool)


##############################################
# Python packaging

get_target_property(_include_dirs mvd-tool INCLUDE_DIRECTORIES)
set(_inc_str ${local_include_dir})
foreach(dir ${_include_dirs})
set(_inc_str "${_inc_str}:${dir}")
endforeach()

# Wheel
add_custom_target(pydist
COMMAND python setup.py build --build-base=${CMAKE_CURRENT_BINARY_DIR} build_ext "-I${_inc_str}" bdist_wheel --dist-dir ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${cybindings_cpp}
COMMENT "Building distributable Python wheel in ${CMAKE_BINARY_DIR}"
)

# Source dist - still requires include dirs
add_custom_target(pysrcdist
COMMAND python setup.py build --build-base=${CMAKE_CURRENT_BINARY_DIR} sdist --dist-dir ${CMAKE_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${cybindings_cpp}
COMMENT "Building distributable Python wheel in ${CMAKE_BINARY_DIR}"
)


##############################################
# Install
#
install(TARGETS mvdtool
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_PYTHON_PACKAGES} )


##############################################
# TESTS
#
add_test(NAME python_read_mvd2
COMMAND bash -c "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR} python test/read_mvd2.py"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_test(NAME python_read_mvd3
COMMAND bash -c "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR} python test/read_mvd3.py"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_subdirectory(pybind11)

pybind11_add_module(mvdtool mvdtool.cpp)
target_link_libraries(mvdtool PUBLIC MVDTool HighFive)
install(TARGETS mvdtool DESTINATION lib/python)
Empty file removed python/__init__.py
Empty file.
38 changes: 0 additions & 38 deletions python/include/MVD.pxd

This file was deleted.

40 changes: 0 additions & 40 deletions python/include/MVD2.pxd

This file was deleted.

49 changes: 0 additions & 49 deletions python/include/MVD3.pxd

This file was deleted.

19 changes: 0 additions & 19 deletions python/include/MVD_MVDType.pxd

This file was deleted.

8 changes: 0 additions & 8 deletions python/include/__init__.py

This file was deleted.

14 changes: 0 additions & 14 deletions python/include/boost.pxd

This file was deleted.

14 changes: 0 additions & 14 deletions python/include/std.pxd

This file was deleted.

Loading