Skip to content
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: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,15 @@ add_definitions( -DBOOST_ALL_DYN_LINK )
##########

if( Nymph_ENABLE_PYTHON )

find_package( Python3 REQUIRED COMPONENTS Interpreter Development )
set(PYBIND11_PYTHON_VERSION ${Python3_VERSION} CACHE STRING "")
find_package( pybind11 REQUIRED )
include_directories( ${Python3_INCLUDE_DIRS} )

add_compile_definitions( NYMPH_USING_PYTHON )
set_option( Scarab_BUILD_PYTHON TRUE )
add_subdirectory( Python/Bindings )

else( Nymph_ENABLE_PYTHON )
remove_definitions( NYMPH_USING_PYTHON )
set_option( Scarab_BUILD_PYTHON FALSE )
endif( Nymph_ENABLE_PYTHON )

Expand Down
12 changes: 12 additions & 0 deletions Cpp/Executables/Main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ if( Nymph_BUILD_NYMPH_EXE )
)
endif( Nymph_BUILD_NYMPH_EXE )

if( Nymph_ENABLE_PYTHON )
set( Nymph_SOURCES
${Nymph_SOURCES}
PyImportTest.cc
)
set( Nymph_EXE_LIBRARIES
${Nymph_EXE_LIBRARIES}
pybind11::embed
pybind11::module
)
endif()

if( Nymph_SOURCES )
set( Nymph_PROGRAMS )
pbuilder_executables(
Expand Down
15 changes: 15 additions & 0 deletions Cpp/Executables/Main/PyImportTest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#include <pybind11/pybind11.h>
#include <pybind11/embed.h>

namespace py = pybind11;

int main()
{
py::scoped_interpreter guard{};

py::module_ sys = py::module_::import("sys");
py::print(sys.attr("path"));

return 0;
}
11 changes: 10 additions & 1 deletion Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ set( testing_LIB_DEPENDENCIES
NymphTesting
)

set( testing_PUBLIC_LIBS Catch2::Catch2 )

if( Nymph_ENABLE_PYTHON )
set( testing_PUBLIC_LIBS
${testing_PUBLIC_LIBS}
pybind11::embed
)
endif( Nymph_ENABLE_PYTHON )

# Interface library was recommended for Catch:
# https://stackoverflow.com/questions/34896891/catch-lib-unit-testing-and-ctest-cmake-integration/34900012#34900012
#add_library( Catch INTERFACE )
Expand All @@ -99,7 +108,7 @@ pbuilder_executable(
EXECUTABLE RunTests
SOURCES ${testing_SOURCES}
PROJECT_LIBRARIES ${testing_LIB_DEPENDENCIES}
PUBLIC_EXTERNAL_LIBRARIES Catch2::Catch2
PUBLIC_EXTERNAL_LIBRARIES ${testing_PUBLIC_LIBS}
)
set( programs "RunTests" )

Expand Down
39 changes: 34 additions & 5 deletions Testing/Cpp/TestProcessorVisibility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

#include "catch2/catch_test_macros.hpp"

#ifdef NYMPH_USING_PYTHON
#include <pybind11/embed.h>
namespace py = pybind11;
#endif

LOGGER( testlog, "TestProcessorVisibility" );

TEST_CASE( "processor_visibility" )
Expand All @@ -32,10 +37,34 @@ TEST_CASE( "processor_visibility" )

}

// SECTION( "Python" )
// {
// LINFO( testlog, "Python Processor Visibility");
//
// }
SECTION( "Python - no import" )
{
LINFO( testlog, "Python Processor Visibility (no python import)");

REQUIRE_FALSE( tptToolbox.CouldBuild( "hello-world-python" ) );
}

#ifdef NYMPH_USING_PYTHON
SECTION( "Python - with import" )
{
py::scoped_interpreter guard{};
// py::module_ sys = py::module_::import("sys");
// py::print(sys.attr("path"));

LINFO( testlog, "Python Processor Visibility (with python import)");

try
{
py::module_ nymph = py::module_::import("nymph");
REQUIRE( tptToolbox.CouldBuild( "hello-world-py" ) );
}
catch(const std::exception& e)
{
LWARN( testlog, "Unable to import `nymph` ")
}


}
#endif

}
4 changes: 2 additions & 2 deletions Testing/Python/Bindings/testprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class TestPyProcCreator(unittest.TestCase):

def test_creating(self):

registrar = nymph_bindings.processor.register_py_processor('testprocessor', 'TestProcessor', 'processor-name')
test_proc = nymph_bindings.processor.create_processor('processor-name', 'test-proc')
registrar = nymph_bindings.processor._register('testprocessor', 'TestProcessor', 'processor-name')
test_proc = nymph_bindings.processor._create('processor-name', 'test-proc')

self.assertEqual(test_proc.name, 'test-proc')

Expand Down
4 changes: 2 additions & 2 deletions Testing/Python/Bindings/testprocfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class TestNoProc(unittest.TestCase):
'''Testing the situation where the processor type doesn't exist'''
def test_noproc(self):
with self.assertRaises(RuntimeError) as cm:
nb.processor.create( "blah", "blah-blah" )
nb.processor._create( "blah", "blah-blah" )
the_exception = cm.exception
self.assertEqual(str(the_exception), "Did not find processor with type <blah>")

class TestCppProc(unittest.TestCase):
'''Testing the creation of a C++ processor, which won't work'''
def test_cppproc(self):
with self.assertRaises(RuntimeError) as cm:
nb.processor.create( "hello-world-cpp", "hw" )
nb.processor._create( "hello-world-cpp", "hw" )
the_exception = cm.exception
self.assertEqual(str(the_exception), "Registrar did not cast correctly for <hello-world-cpp>")

Expand Down