Skip to content
Closed
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
26 changes: 20 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ cmake_policy(SET CMP0077 NEW) # ``option()`` honors normal variables.
cmake_policy(SET CMP0080 NEW) # ``BundleUtilities`` cannot be included at configure time.

# The ``FindPythonInterp`` and ``FindPythonLibs`` modules are removed.
# if(CMAKE_VERSION VERSION_GREATER "3.27.0")
# cmake_policy(SET CMP0148 NEW)
# endif()
if(CMAKE_VERSION VERSION_GREATER "3.27.0")
cmake_policy(SET CMP0148 NEW)
endif()

# resolves symlinks before collapsing ../ components.
if(CMAKE_VERSION VERSION_GREATER "3.28.0")
Expand All @@ -18,9 +18,9 @@ endif()
include(${CMAKE_CURRENT_LIST_DIR}/cmake/Utility.cmake)

# ------------------------------------------------------------------------------
# Is this a commercial or Free build
# Are we embedding Python
# ------------------------------------------------------------------------------
option(SIMPLNX_BUILD_PYTHON "Enable building Python building" OFF)
option(SIMPLNX_BUILD_PYTHON "Enable building Python bindings" OFF)
include(CMakeDependentOption)
cmake_dependent_option(SIMPLNX_EMBED_PYTHON "Embeds python interpreter in nxrunner" ON "SIMPLNX_BUILD_PYTHON" OFF)
enable_vcpkg_manifest_feature(TEST_VAR SIMPLNX_BUILD_PYTHON FEATURE "python")
Expand Down Expand Up @@ -178,6 +178,20 @@ else()
set(SIMPLNX_PIPELINE_INSTALL_DIR "pipelines")
endif()

# ------------------------------------------------------------------------------
# Find Python if needed
# ------------------------------------------------------------------------------
if(SIMPLNX_BUILD_PYTHON)
message(STATUS "/***************** Finding Python 3 Interpreter ${CMAKE_CURRENT_LIST_FILE}/")
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
message(STATUS "/**************************************************************/")

message(STATUS "/***************** Finding PyBind11 ${CMAKE_CURRENT_LIST_FILE}/")
find_package(pybind11 2.10.0 CONFIG REQUIRED)
message(STATUS "/**************************************************************/")
endif()


# -----------------------------------------------------------------------
# Find dependent libraries
# -----------------------------------------------------------------------
Expand Down Expand Up @@ -816,7 +830,7 @@ list(APPEND SIMPLNX_GENERATED_HEADERS
# Generate Python-Bindings Supporting Files
set(SIMPLNX_GENERATED_PYTHON_HEADER ${SIMPLNX_GENERATED_HEADER_DIR}/SimplnxPython.hpp)
set(SIMPLNX_PYTHON_MODULE "simplnx")
configure_file(${simplnx_SOURCE_DIR}/wrapping/python/CxPybind/SimplnxPython.hpp.in ${SIMPLNX_GENERATED_PYTHON_HEADER})
configure_file(${simplnx_SOURCE_DIR}/wrapping/python/NxPybind/SimplnxPython.hpp.in ${SIMPLNX_GENERATED_PYTHON_HEADER})

list(APPEND SIMPLNX_GENERATED_HEADERS
${SIMPLNX_GENERATED_PYTHON_HEADER}
Expand Down
2 changes: 1 addition & 1 deletion cmake/Summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ message(STATUS "* DREAM3D_DATA_DIR: ${DREAM3D_DATA_DIR}")
message(STATUS "* -------------- Simplnx Python Configuration Options -------------------------------------")
message(STATUS "* Pybind11 (${pybind11_VERSION}) ${pybind11_DIR}")
message(STATUS "* Python3_EXECUTABLE: ${Python3_EXECUTABLE}")
message(STATUS "* PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}")
# message(STATUS "* PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}")
message(STATUS "* SIMPLNX_BUILD_PYTHON: ${SIMPLNX_BUILD_PYTHON}")
message(STATUS "* SIMPLNX_BUILD_PYTHON_DOCS: ${SIMPLNX_BUILD_PYTHON_DOCS}")
message(STATUS "* SIMPLNX_BUILD_PYTHON_TESTS: ${SIMPLNX_BUILD_PYTHON_TESTS}")
Expand Down
3 changes: 2 additions & 1 deletion cmake/Utility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ function(AddPythonTest)
PROPERTY
ENVIRONMENT
"PYTHON_TEST_FILE=${ARGS_FILE}"
"PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
# "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}"
"Python3_EXECUTABLE=${Python3_EXECUTABLE}"
)
else()
add_test(NAME ${ARGS_NAME}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/ITKImageProcessing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if(NOT GENERATOR_IS_MULTI_CONFIG)
set_property(GLOBAL PROPERTY SIMPLNX_EXTRA_LIBRARY_DIRS ${SIMPLNX_EXTRA_LIBRARY_DIRS} ${ITK_LIB_DIR})
endif()

message(STATUS "* ITK (${ITK_VERSION}) ${ITK_DIR}")
message(STATUS "ITK (${ITK_VERSION}) ${ITK_DIR}")

include("${simplnx_SOURCE_DIR}/cmake/Plugin.cmake")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <CxPybind/CxPybind.hpp>
#include <NxPybind/NxPybind.hpp>

#include "ITKImageProcessing/ITKImageProcessingFilterBinding.hpp"
#include "ITKImageProcessing/ITKImageProcessingPlugin.hpp"

using namespace nx::core;
using namespace nx::core::CxPybind;
using namespace nx::core::NxPybind;
namespace py = pybind11;

PYBIND11_MODULE(itkimageprocessing, mod)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <CxPybind/CxPybind.hpp>
#include <NxPybind/NxPybind.hpp>

#include <OrientationAnalysis/OrientationAnalysisPlugin.hpp>

Expand All @@ -8,7 +8,7 @@
#include "OrientationAnalysis/OrientationAnalysisFilterBinding.hpp"

using namespace nx::core;
using namespace nx::core::CxPybind;
using namespace nx::core::NxPybind;
namespace py = pybind11;

using namespace pybind11::literals;
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <CxPybind/CxPybind.hpp>
#include <NxPybind/NxPybind.hpp>

#include <pybind11/pybind11.h>

Expand Down Expand Up @@ -92,7 +92,7 @@
#include <filesystem>

using namespace nx::core;
using namespace nx::core::CxPybind;
using namespace nx::core::NxPybind;

namespace py = pybind11;
namespace fs = std::filesystem;
Expand Down
2 changes: 0 additions & 2 deletions src/nxrunner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ target_link_libraries(nxrunner PRIVATE simplnx::simplnx)
source_group("nxrunner" FILES ${CLI_HDRS} ${CLI_SRCS})

if(SIMPLNX_EMBED_PYTHON)
find_package(pybind11 2.10.0 CONFIG REQUIRED)

target_link_libraries(nxrunner
PRIVATE
NxPythonEmbed
Expand Down
12 changes: 5 additions & 7 deletions wrapping/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
find_package(pybind11 2.10.0 CONFIG REQUIRED)
add_library(NxPybind INTERFACE)

add_library(CxPybind INTERFACE)
target_include_directories(NxPybind INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/NxPybind)

target_include_directories(CxPybind INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/CxPybind)

target_link_libraries(CxPybind
target_link_libraries(NxPybind
INTERFACE
simplnx
pybind11::headers
Expand Down Expand Up @@ -56,7 +54,7 @@ endif()
target_link_libraries(simplnxpy
PUBLIC
SimplnxCore
CxPybind
NxPybind
)

target_compile_options(simplnxpy
Expand Down Expand Up @@ -236,7 +234,7 @@ function(simplnx_add_python_plugin)
target_link_libraries(${PYTHON_MODULE_NAME}
PUBLIC
${ARGS_PLUGIN_NAME}
CxPybind
NxPybind
)

target_compile_definitions(${PYTHON_MODULE_NAME} PUBLIC PYBIND11_DETAILED_ERROR_MESSAGES)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
#pragma once

#include <pybind11/pybind11.h>
#include <simplnx/Common/ScopeGuard.hpp>
#include <simplnx/Core/Application.hpp>
#include <simplnx/Filter/Arguments.hpp>
#include <simplnx/Filter/FilterTraits.hpp>
#include <simplnx/Filter/IFilter.hpp>
#include <simplnx/Filter/IParameter.hpp>
#include <simplnx/Filter/ParameterTraits.hpp>
#include <simplnx/Filter/Parameters.hpp>
#include <simplnx/Plugin/AbstractPlugin.hpp>
#include <simplnx/Plugin/PluginLoader.hpp>

#include <pybind11/functional.h>
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/stl/filesystem.h>

#if PYBIND11_HAS_NATIVE_ENUM
#include <pybind11/native_enum.h>
#endif

#include <boost/mp11/algorithm.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/mp11/list.hpp>

#include <fmt/ranges.h>

#include <simplnx/Common/ScopeGuard.hpp>
#include <simplnx/Core/Application.hpp>
#include <simplnx/Filter/Arguments.hpp>
#include <simplnx/Filter/FilterTraits.hpp>
#include <simplnx/Filter/IFilter.hpp>
#include <simplnx/Filter/IParameter.hpp>
#include <simplnx/Filter/ParameterTraits.hpp>
#include <simplnx/Filter/Parameters.hpp>
#include <simplnx/Plugin/AbstractPlugin.hpp>
#include <simplnx/Plugin/PluginLoader.hpp>

#include <any>
#include <memory>
#include <type_traits>
Expand All @@ -34,7 +37,7 @@
#define SIMPLNX_PY_BIND_CLASS_VARIADIC(scope, className, ...) pybind11::class_<className, __VA_ARGS__>(scope, #className)
#define SIMPLNX_PY_BIND_PARAMETER(scope, className) SIMPLNX_PY_BIND_CLASS_VARIADIC(scope, className, nx::core::IParameter)

namespace nx::core::CxPybind
namespace nx::core::NxPybind
{
namespace py = pybind11;

Expand Down Expand Up @@ -111,11 +114,25 @@ std::string GetFixedPythonTypeCasterName()
template <class T>
std::string GetFullPythonName()
{
using CasterT = py::detail::make_caster<T>;
// Use py::type::of for registered C++ types otherwise use py::detail::type_caster::name
if constexpr(std::is_base_of_v<py::detail::type_caster_generic, py::detail::make_caster<T>>)
if constexpr(std::is_base_of_v<py::detail::type_caster_generic, CasterT>)
{
return GetRegisteredPythonTypeName<T>();
}
#if PYBIND11_HAS_NATIVE_ENUM
else if constexpr(std::is_base_of_v<py::detail::type_caster_enum_type<T>, CasterT>) // Is registered enum
{
const std::type_info& typeInfo = typeid(T);
py::handle nativeEnumHandle = py::detail::global_internals_native_enum_type_map_get_item(typeInfo);
if(nativeEnumHandle)
{
return GetFullPythonNameFromType(nativeEnumHandle);
}
py::handle handle = py::detail::get_type_handle(typeInfo, true);
return GetFullPythonNameFromType(handle);
}
#endif
else
{
return GetFixedPythonTypeCasterName<T>();
Expand Down Expand Up @@ -751,4 +768,4 @@ void BindParameterConstructor(py::class_<T, Options...>& object)

object.def(py::init<const std::string&, const std::string&, const std::string&, const typename T::ValueType&>(), "name"_a, "human_name"_a, "help_text"_a, "default_value"_a);
}
} // namespace nx::core::CxPybind
} // namespace nx::core::NxPybind
2 changes: 1 addition & 1 deletion wrapping/python/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ are developing new python bindings for `simplnx`.

- cmake
This directory holds various files used by CMake during the configuration of the python bindings
- CxPybind
- NxPybind
This directory holds C++ implementation details for the python bindings
- docs
This directory holds the entirety of the python binding documentation
Expand Down
4 changes: 2 additions & 2 deletions wrapping/python/cmake/FilterBinding.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace nx::core::@PLUGIN_NAME@
{
void BindFilters(pybind11::handle scope, const nx::core::CxPybind::Internals& internals)
void BindFilters(pybind11::handle scope, const nx::core::NxPybind::Internals& internals)
{
using namespace CxPybind;
using namespace NxPybind;
@FILTER_BINDING_CODE@
}
} // namespace nx::core
4 changes: 2 additions & 2 deletions wrapping/python/cmake/FilterBinding.hpp.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "CxPybind/CxPybind.hpp"
#include "NxPybind/NxPybind.hpp"

namespace nx::core::@PLUGIN_NAME@
{
void BindFilters(pybind11::handle scope, const nx::core::CxPybind::Internals& internals);
void BindFilters(pybind11::handle scope, const nx::core::NxPybind::Internals& internals);
} // namespace nx::core
7 changes: 4 additions & 3 deletions wrapping/python/testing/anaconda_test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
:: echo "complex_CONDA_ENV: %complex_CONDA_ENV%"
echo "PYTHON_TEST_FILE: %PYTHON_TEST_FILE%"
echo "PYTHONPATH: %PYTHONPATH%"
echo "PYTHON_EXECUTABLE: %PYTHON_EXECUTABLE%"
:: echo "PYTHON_EXECUTABLE: %PYTHON_EXECUTABLE%"
echo "Python3_EXECUTABLE: %Python3_EXECUTABLE%"

:: CALL "%complex_CONDA_EXECUTABLE%" activate "%complex_CONDA_ENV%"

echo "PATH: %PATH%"
:: echo "Where is Python: "
:: where python.exe
echo "Python Version: "
%PYTHON_EXECUTABLE% --version
%Python3_EXECUTABLE% --version
if %errorlevel% neq 0 exit 1

%PYTHON_EXECUTABLE% "%PYTHON_TEST_FILE%"
%Python3_EXECUTABLE% "%PYTHON_TEST_FILE%"
5 changes: 3 additions & 2 deletions wrapping/python/testing/anaconda_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# echo "complex_CONDA_ENV: $complex_CONDA_ENV"
echo "PYTHON_TEST_FILE: $PYTHON_TEST_FILE"
echo "PYTHONPATH: $PYTHONPATH"
echo "PYTHON_EXECUTABLE: $PYTHON_EXECUTABLE"
# echo "PYTHON_EXECUTABLE: $PYTHON_EXECUTABLE"
echo "Python3_EXECUTABLE: $Python3_EXECUTABLE"

# echo "Sourcing $complex_ANACONDA_DIR/etc/profile.d/conda.sh"
# source "$complex_ANACONDA_DIR"/etc/profile.d/conda.sh
Expand All @@ -19,4 +20,4 @@ echo "PATH: $PATH"
#PYTHONEXE=`which python`
#echo "Python Version: " `${PYTHONEXE} --version`

${PYTHON_EXECUTABLE} "$PYTHON_TEST_FILE"
${Python3_EXECUTABLE} "$PYTHON_TEST_FILE"
Loading