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 2 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
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ cmake_minimum_required(VERSION 3.0)

include(CTest)

set(MVDTOOL_VERSION_MAJOR 1)
set(MVDTOOL_VERSION_MINOR 5)
set(MVDTOOL_VERSION_PATCH 2)
set(MVDTOOL_VERSION_MAJOR 2)
set(MVDTOOL_VERSION_MINOR 0)
set(MVDTOOL_VERSION_PATCH 0)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake
${PROJECT_SOURCE_DIR}/CMake/portability
Expand All @@ -32,10 +32,9 @@ 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