diff --git a/fastdds_python/src/swig/CMakeLists.txt b/fastdds_python/src/swig/CMakeLists.txt index 393643b4..0623526f 100644 --- a/fastdds_python/src/swig/CMakeLists.txt +++ b/fastdds_python/src/swig/CMakeLists.txt @@ -24,14 +24,19 @@ set(${PROJECT_NAME}_MODULE fastdds ) -set(${PROJECT_NAME}_FILES - ${${PROJECT_NAME}_MODULE}.i +set(${PROJECT_NAME}_FILE + ${CMAKE_CURRENT_BINARY_DIR}/${${PROJECT_NAME}_MODULE}.i ) -SET_SOURCE_FILES_PROPERTIES( - ${${PROJECT_NAME}_FILES} - PROPERTIES CPLUSPLUS ON +file(GENERATE + OUTPUT ${${PROJECT_NAME}_FILE} + INPUT ${${PROJECT_NAME}_MODULE}.i + ) + +set_source_files_properties(${${PROJECT_NAME}_FILE} PROPERTIES + CPLUSPLUS ON USE_TARGET_INCLUDE_DIRECTORIES TRUE + INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ) option(BUILD_DOCUMENTATION "Use doxygen to create product documentation" OFF) @@ -42,11 +47,14 @@ endif (BUILD_DOCUMENTATION) swig_add_library(${PROJECT_NAME} TYPE SHARED LANGUAGE python - SOURCES ${${PROJECT_NAME}_FILES} + SOURCES + ${${PROJECT_NAME}_FILE} ) if(UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8) - set_property(TARGET ${PROJECT_NAME} PROPERTY SWIG_COMPILE_DEFINITIONS SWIGWORDSIZE64) + set_property(TARGET ${PROJECT_NAME} PROPERTY + SWIG_COMPILE_DEFINITIONS SWIGWORDSIZE64 + ) endif() if(MSVC OR MSVC_IDE) @@ -67,7 +75,7 @@ execute_process(COMMAND ${Python3_EXECUTABLE} -c "from distutils import sysconfi get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE) file (RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH}) SET (PYTHON_MODULE_PATH - ${_REL_PYTHON_MODULE_PATH} + ${_REL_PYTHON_MODULE_PATH}/${${PROJECT_NAME}_MODULE} ) # Install @@ -75,8 +83,8 @@ install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets DESTINATION ${PYTHON_MODULE_PATH} ) -get_property(support_files TARGET ${PROJECT_NAME} PROPERTY SWIG_SUPPORT_FILES) -install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH}) +get_property(generated_python_file TARGET ${PROJECT_NAME} PROPERTY SWIG_SUPPORT_FILES) +install(FILES ${generated_python_file} DESTINATION ${PYTHON_MODULE_PATH} RENAME __init__.py) export(TARGETS ${PROJECT_NAME} FILE ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}-targets.cmake) diff --git a/fastdds_python/src/swig/fastdds.i b/fastdds_python/src/swig/fastdds.i index de53cae7..5bb565e3 100644 --- a/fastdds_python/src/swig/fastdds.i +++ b/fastdds_python/src/swig/fastdds.i @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -%module(directors="1", threads="1") fastdds +%module(directors="1", threads="1", moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('$')\nif __package__ or '.' in __name__:\n from . import _fastdds_python\nelse:\n import _fastdds_python") fastdds // Handle exceptions on python callbacks and send them back to C++ so that they can be catched // Also, add some meaningful description of the error @@ -43,6 +43,14 @@ } } +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} + %exception { try { $action } catch (Swig::DirectorException &e) { SWIG_fail; } diff --git a/fastdds_python/test/api/test_datareader.py b/fastdds_python/test/api/test_datareader.py index a7bcdde4..c0d020e8 100644 --- a/fastdds_python/test/api/test_datareader.py +++ b/fastdds_python/test/api/test_datareader.py @@ -1,11 +1,3 @@ -# until https://bugs.python.org/issue46276 is not fixed we can apply this -# workaround on windows -import os -if os.name == 'nt': - import win32api - win32api.LoadLibrary('test_complete') - win32api.LoadLibrary('test_modules') - import fastdds import pytest import time @@ -24,7 +16,7 @@ def data_type(request): pytest.dds_type = __import__("test_complete") else: pytest.dds_type = __import__("eprosima.test.test_modules", - fromlist=[None]) + fromlist=["test_modules"]) @pytest.fixture def participant(): diff --git a/fastdds_python/test/api/test_datawriter.py b/fastdds_python/test/api/test_datawriter.py index 1e73dd82..504fd368 100644 --- a/fastdds_python/test/api/test_datawriter.py +++ b/fastdds_python/test/api/test_datawriter.py @@ -15,7 +15,7 @@ def data_type(request): pytest.dds_type = __import__("test_complete") else: pytest.dds_type = __import__("eprosima.test.test_modules", - fromlist=[None]) + fromlist=["test_modules"]) @pytest.fixture def participant(): diff --git a/fastdds_python/test/api/test_domainparticipant.py b/fastdds_python/test/api/test_domainparticipant.py index 7e7fa9d8..f0084c2d 100644 --- a/fastdds_python/test/api/test_domainparticipant.py +++ b/fastdds_python/test/api/test_domainparticipant.py @@ -28,7 +28,7 @@ def data_type(request): pytest.dds_type = __import__("test_complete") else: pytest.dds_type = __import__("eprosima.test.test_modules", - fromlist=[None]) + fromlist=["test_modules"]) @pytest.fixture def not_autoenable_factory(): diff --git a/fastdds_python/test/api/test_publisher.py b/fastdds_python/test/api/test_publisher.py index e87b4d05..39ddc0e0 100644 --- a/fastdds_python/test/api/test_publisher.py +++ b/fastdds_python/test/api/test_publisher.py @@ -17,7 +17,7 @@ def data_type(request): pytest.dds_type = __import__("test_complete") else: pytest.dds_type = __import__("eprosima.test.test_modules", - fromlist=[None]) + fromlist=["test_modules"]) @pytest.fixture def participant_qos(): diff --git a/fastdds_python/test/api/test_qos.py b/fastdds_python/test/api/test_qos.py index 6d4d6fc1..8a80e0f5 100644 --- a/fastdds_python/test/api/test_qos.py +++ b/fastdds_python/test/api/test_qos.py @@ -1,11 +1,5 @@ import os -# until https://bugs.python.org/issue46276 is not fixed we can apply this -# workaround on windows -if os.name == 'nt': - import win32api - win32api.LoadLibrary('_fastdds_python.pyd') - import fastdds import inspect diff --git a/fastdds_python/test/api/test_subscriber.py b/fastdds_python/test/api/test_subscriber.py index 5354d95e..7155acb9 100644 --- a/fastdds_python/test/api/test_subscriber.py +++ b/fastdds_python/test/api/test_subscriber.py @@ -18,7 +18,7 @@ def data_type(request): pytest.dds_type = __import__("test_complete") else: pytest.dds_type = __import__("eprosima.test.test_modules", - fromlist=[None]) + fromlist=["test_modules"]) @pytest.fixture def participant_qos(): diff --git a/fastdds_python/test/api/test_waitset.py b/fastdds_python/test/api/test_waitset.py index 584a58c1..374a1280 100644 --- a/fastdds_python/test/api/test_waitset.py +++ b/fastdds_python/test/api/test_waitset.py @@ -1,11 +1,3 @@ -# until https://bugs.python.org/issue46276 is not fixed we can apply this -# workaround on windows -import os -if os.name == 'nt': - import win32api - win32api.LoadLibrary('test_complete') - win32api.LoadLibrary('test_modules') - import fastdds import pytest @@ -16,7 +8,7 @@ def data_type(request): pytest.dds_type = __import__("test_complete") else: pytest.dds_type = __import__("eprosima.test.test_modules", - fromlist=[None]) + fromlist=["test_modules"]) @pytest.fixture def participant(): diff --git a/fastdds_python/test/types/CMakeLists.txt b/fastdds_python/test/types/CMakeLists.txt index 7a99c986..876c696a 100644 --- a/fastdds_python/test/types/CMakeLists.txt +++ b/fastdds_python/test/types/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 3.20) # SWIG: use standard target name. if(POLICY CMP0078) @@ -73,8 +73,6 @@ SET_SOURCE_FILES_PROPERTIES( USE_TARGET_INCLUDE_DIRECTORIES TRUE ) -set_property(SOURCE ${PROJECT_NAME}.i PROPERTY OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/eprosima/test2") - SWIG_ADD_LIBRARY(${${PROJECT_NAME}_MODULE} TYPE SHARED LANGUAGE python @@ -91,11 +89,6 @@ target_link_libraries(${${PROJECT_NAME}_MODULE} ${PROJECT_NAME} ) -set_target_properties(${${PROJECT_NAME}_MODULE} - PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/eprosima/test2" - ) - - # Find the installation path execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))" OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH @@ -105,7 +98,7 @@ execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE) file (RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH}) SET (PYTHON_MODULE_PATH - ${_REL_PYTHON_MODULE_PATH} + ${_REL_PYTHON_MODULE_PATH}/eprosima/test2/${PROJECT_NAME} ) # Install @@ -114,9 +107,9 @@ install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ ) -install(TARGETS ${${PROJECT_NAME}_MODULE} DESTINATION ${PYTHON_MODULE_PATH}/eprosima/test2) +install(TARGETS ${${PROJECT_NAME}_MODULE} DESTINATION ${PYTHON_MODULE_PATH}) get_property(support_files TARGET ${${PROJECT_NAME}_MODULE} PROPERTY SWIG_SUPPORT_FILES) -install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH}/eprosima/test2) +install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH} RENAME __init__.py) ############################################################################### # Library for types defined in test_modules IDL @@ -180,8 +173,6 @@ SET_SOURCE_FILES_PROPERTIES( USE_TARGET_INCLUDE_DIRECTORIES TRUE ) -set_property(SOURCE ${PROJECT_NAME}.i PROPERTY OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/eprosima/test") - SWIG_ADD_LIBRARY(${${PROJECT_NAME}_MODULE} TYPE SHARED LANGUAGE python @@ -198,11 +189,6 @@ target_link_libraries(${${PROJECT_NAME}_MODULE} ${PROJECT_NAME} ) -set_target_properties(${${PROJECT_NAME}_MODULE} - PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/eprosima/test" - ) - - # Find the installation path execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))" OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH @@ -212,7 +198,7 @@ execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE) file (RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH}) SET (PYTHON_MODULE_PATH - ${_REL_PYTHON_MODULE_PATH} + ${_REL_PYTHON_MODULE_PATH}/eprosima/test/${PROJECT_NAME} ) # Install @@ -221,9 +207,9 @@ install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ ) -install(TARGETS ${${PROJECT_NAME}_MODULE} DESTINATION ${PYTHON_MODULE_PATH}/eprosima/test) +install(TARGETS ${${PROJECT_NAME}_MODULE} DESTINATION ${PYTHON_MODULE_PATH}) get_property(support_files TARGET ${${PROJECT_NAME}_MODULE} PROPERTY SWIG_SUPPORT_FILES) -install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH}/eprosima/test) +install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH} RENAME __init__.py) ############################################################################### # Library for types defined in test_complete IDL @@ -288,8 +274,6 @@ SET_SOURCE_FILES_PROPERTIES( USE_TARGET_INCLUDE_DIRECTORIES TRUE ) -set_property(SOURCE ${PROJECT_NAME}.i PROPERTY OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/") - SWIG_ADD_LIBRARY(${${PROJECT_NAME}_MODULE} TYPE SHARED LANGUAGE python @@ -306,11 +290,6 @@ target_link_libraries(${${PROJECT_NAME}_MODULE} ${PROJECT_NAME} ) -set_target_properties(${${PROJECT_NAME}_MODULE} - PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" - ) - - # Find the installation path execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))" OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH @@ -320,7 +299,7 @@ execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE) file (RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH}) SET (PYTHON_MODULE_PATH - ${_REL_PYTHON_MODULE_PATH} + ${_REL_PYTHON_MODULE_PATH}/${PROJECT_NAME} ) # Install @@ -329,7 +308,7 @@ install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ ) -install(TARGETS ${${PROJECT_NAME}_MODULE} DESTINATION ${PYTHON_MODULE_PATH}/) +install(TARGETS ${${PROJECT_NAME}_MODULE} DESTINATION ${PYTHON_MODULE_PATH}) get_property(support_files TARGET ${${PROJECT_NAME}_MODULE} PROPERTY SWIG_SUPPORT_FILES) -install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH}/) +install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH} RENAME __init__.py) diff --git a/fastdds_python/test/types/test_complete.i b/fastdds_python/test/types/test_complete.i index b934ef7c..427c275e 100644 --- a/fastdds_python/test/types/test_complete.i +++ b/fastdds_python/test/types/test_complete.i @@ -19,7 +19,15 @@ * This file was generated by the tool fastddsgen. */ -%module test_complete +%module(moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('test_complete.dll')\nif __package__ or '.' in __name__:\n from . import _test_completeWrapper\nelse:\n import _test_completeWrapper") test_complete + +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} // SWIG helper modules %include "stdint.i" diff --git a/fastdds_python/test/types/test_included_modules.i b/fastdds_python/test/types/test_included_modules.i index 1691cd7c..72eb5363 100644 --- a/fastdds_python/test/types/test_included_modules.i +++ b/fastdds_python/test/types/test_included_modules.i @@ -19,7 +19,15 @@ * This file was generated by the tool fastddsgen. */ -%module test_included_modules +%module(moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('test_included_modules.dll')\nif __package__ or '.' in __name__:\n from . import _test_included_modulesWrapper\nelse:\n import _test_included_modulesWrapper") test_included_modules + +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} // SWIG helper modules %include "stdint.i" diff --git a/fastdds_python/test/types/test_modules.i b/fastdds_python/test/types/test_modules.i index 50f172aa..3e4ff7d2 100644 --- a/fastdds_python/test/types/test_modules.i +++ b/fastdds_python/test/types/test_modules.i @@ -19,7 +19,15 @@ * This file was generated by the tool fastddsgen. */ -%module test_modules +%module(moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('test_modules.dll')\nif __package__ or '.' in __name__:\n from . import _test_modulesWrapper\nelse:\n import _test_modulesWrapper") test_modules + +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} // SWIG helper modules %include "stdint.i" diff --git a/fastdds_python_examples/HelloWorldExample/CMakeLists.txt b/fastdds_python_examples/HelloWorldExample/CMakeLists.txt index 25a2df56..84a53ee6 100644 --- a/fastdds_python_examples/HelloWorldExample/CMakeLists.txt +++ b/fastdds_python_examples/HelloWorldExample/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 3.20) # SWIG: use standard target name. if(POLICY CMP0078) @@ -73,8 +73,6 @@ SET_SOURCE_FILES_PROPERTIES( USE_TARGET_INCLUDE_DIRECTORIES TRUE ) -set_property(SOURCE ${PROJECT_NAME}.i PROPERTY OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/") - SWIG_ADD_LIBRARY(${${PROJECT_NAME}_MODULE} TYPE SHARED LANGUAGE python @@ -91,11 +89,6 @@ target_link_libraries(${${PROJECT_NAME}_MODULE} ${PROJECT_NAME} ) -set_target_properties(${${PROJECT_NAME}_MODULE} - PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" - ) - - # Find the installation path execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}'))" OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH @@ -105,7 +98,7 @@ execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE) file (RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH}) SET (PYTHON_MODULE_PATH - ${_REL_PYTHON_MODULE_PATH} + ${_REL_PYTHON_MODULE_PATH}/${PROJECT_NAME} ) # Install @@ -114,7 +107,7 @@ install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ ) -install(TARGETS ${${PROJECT_NAME}_MODULE} DESTINATION ${PYTHON_MODULE_PATH}/) +install(TARGETS ${${PROJECT_NAME}_MODULE} DESTINATION ${PYTHON_MODULE_PATH}) get_property(support_files TARGET ${${PROJECT_NAME}_MODULE} PROPERTY SWIG_SUPPORT_FILES) -install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH}/) +install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH} RENAME __init__.py) diff --git a/fastdds_python_examples/HelloWorldExample/HelloWorld.i b/fastdds_python_examples/HelloWorldExample/HelloWorld.i index 662991c7..279f30f7 100644 --- a/fastdds_python_examples/HelloWorldExample/HelloWorld.i +++ b/fastdds_python_examples/HelloWorldExample/HelloWorld.i @@ -19,7 +19,15 @@ * This file was generated by the tool fastddsgen. */ -%module HelloWorld +%module(moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('HelloWorld.dll')\nif __package__ or '.' in __name__:\n from . import _HelloWorldWrapper\nelse:\n import _HelloWorldWrapper") HelloWorld + +// If using windows in debug, it would try to use python_d, which would not be found. +%begin %{ +#ifdef _MSC_VER +#define SWIG_PYTHON_INTERPRETER_NO_DEBUG +#endif +#include +%} // SWIG helper modules %include "stdint.i" diff --git a/fastdds_python_examples/HelloWorldExample/HelloWorldExample.py b/fastdds_python_examples/HelloWorldExample/HelloWorldExample.py index f3b0b513..bb332161 100644 --- a/fastdds_python_examples/HelloWorldExample/HelloWorldExample.py +++ b/fastdds_python_examples/HelloWorldExample/HelloWorldExample.py @@ -19,12 +19,6 @@ import argparse from threading import Condition -# until https://bugs.python.org/issue46276 is not fixed we can apply this -# workaround on windows -if os.name == 'nt': - import win32api - win32api.LoadLibrary('HelloWorld') - import fastdds import HelloWorld