From 6218071592a59101db70b1240381bf6bdff6abf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Mon, 8 Apr 2024 15:58:53 +0200 Subject: [PATCH 1/6] Refs #20763. Applying discovery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- fastdds_python/src/swig/CMakeLists.txt | 2 +- fastdds_python/test/api/test_datareader.py | 8 -------- fastdds_python/test/api/test_qos.py | 6 ------ fastdds_python/test/api/test_waitset.py | 8 -------- fastdds_python/test/types/CMakeLists.txt | 7 +++---- fastdds_python_examples/HelloWorldExample/CMakeLists.txt | 3 +-- .../HelloWorldExample/HelloWorldExample.py | 6 ------ 7 files changed, 5 insertions(+), 35 deletions(-) diff --git a/fastdds_python/src/swig/CMakeLists.txt b/fastdds_python/src/swig/CMakeLists.txt index 393643b4..e785b898 100644 --- a/fastdds_python/src/swig/CMakeLists.txt +++ b/fastdds_python/src/swig/CMakeLists.txt @@ -67,7 +67,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 diff --git a/fastdds_python/test/api/test_datareader.py b/fastdds_python/test/api/test_datareader.py index a7bcdde4..1b3f6204 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 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_waitset.py b/fastdds_python/test/api/test_waitset.py index 584a58c1..8c340816 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 diff --git a/fastdds_python/test/types/CMakeLists.txt b/fastdds_python/test/types/CMakeLists.txt index 7a99c986..856c27a4 100644 --- a/fastdds_python/test/types/CMakeLists.txt +++ b/fastdds_python/test/types/CMakeLists.txt @@ -105,7 +105,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 @@ -212,7 +212,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 @@ -320,7 +320,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 @@ -332,4 +332,3 @@ install(TARGETS ${PROJECT_NAME} 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}/) - diff --git a/fastdds_python_examples/HelloWorldExample/CMakeLists.txt b/fastdds_python_examples/HelloWorldExample/CMakeLists.txt index 25a2df56..08cc2db7 100644 --- a/fastdds_python_examples/HelloWorldExample/CMakeLists.txt +++ b/fastdds_python_examples/HelloWorldExample/CMakeLists.txt @@ -105,7 +105,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 @@ -117,4 +117,3 @@ install(TARGETS ${PROJECT_NAME} 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}/) - 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 From c5aba46d4ab74fce133fb58a06f463357a56be21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Wed, 10 Apr 2024 14:44:39 +0200 Subject: [PATCH 2/6] Refs #20763. Improve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- fastdds_python/src/swig/CMakeLists.txt | 9 +++---- fastdds_python/test/api/test_datareader.py | 2 +- fastdds_python/test/api/test_datawriter.py | 2 +- .../test/api/test_domainparticipant.py | 2 +- fastdds_python/test/api/test_publisher.py | 2 +- fastdds_python/test/api/test_subscriber.py | 2 +- fastdds_python/test/api/test_waitset.py | 2 +- fastdds_python/test/types/CMakeLists.txt | 25 ++++++------------- fastdds_python/test/types/test_complete.i | 1 - .../test/types/test_included_modules.i | 1 - fastdds_python/test/types/test_modules.i | 1 - .../HelloWorldExample/CMakeLists.txt | 2 +- .../HelloWorldExample/HelloWorld.i | 1 - 13 files changed, 18 insertions(+), 34 deletions(-) diff --git a/fastdds_python/src/swig/CMakeLists.txt b/fastdds_python/src/swig/CMakeLists.txt index e785b898..d0aa04bf 100644 --- a/fastdds_python/src/swig/CMakeLists.txt +++ b/fastdds_python/src/swig/CMakeLists.txt @@ -28,9 +28,8 @@ set(${PROJECT_NAME}_FILES ${${PROJECT_NAME}_MODULE}.i ) -SET_SOURCE_FILES_PROPERTIES( - ${${PROJECT_NAME}_FILES} - PROPERTIES CPLUSPLUS ON +set_source_files_properties(${${PROJECT_NAME}_FILES} PROPERTIES + CPLUSPLUS ON USE_TARGET_INCLUDE_DIRECTORIES TRUE ) @@ -75,8 +74,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/test/api/test_datareader.py b/fastdds_python/test/api/test_datareader.py index 1b3f6204..c0d020e8 100644 --- a/fastdds_python/test/api/test_datareader.py +++ b/fastdds_python/test/api/test_datareader.py @@ -16,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_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 8c340816..374a1280 100644 --- a/fastdds_python/test/api/test_waitset.py +++ b/fastdds_python/test/api/test_waitset.py @@ -8,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 856c27a4..8190cf7f 100644 --- a/fastdds_python/test/types/CMakeLists.txt +++ b/fastdds_python/test/types/CMakeLists.txt @@ -73,7 +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 @@ -91,10 +90,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}'))" @@ -105,7 +100,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}/${PROJECT_NAME} + ${_REL_PYTHON_MODULE_PATH}/eprosima/test2/${PROJECT_NAME} ) # Install @@ -114,9 +109,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 +175,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,10 +191,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}'))" @@ -212,7 +201,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}/${PROJECT_NAME} + ${_REL_PYTHON_MODULE_PATH}/eprosima/test/${PROJECT_NAME} ) # Install @@ -221,9 +210,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 @@ -331,4 +320,4 @@ install(TARGETS ${PROJECT_NAME} ) 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..1263958e 100644 --- a/fastdds_python/test/types/test_complete.i +++ b/fastdds_python/test/types/test_complete.i @@ -2843,4 +2843,3 @@ namespace swig { // Include the corresponding TopicDataType %include "test_completePubSubTypes.i" - diff --git a/fastdds_python/test/types/test_included_modules.i b/fastdds_python/test/types/test_included_modules.i index 1691cd7c..220e9643 100644 --- a/fastdds_python/test/types/test_included_modules.i +++ b/fastdds_python/test/types/test_included_modules.i @@ -252,4 +252,3 @@ namespace swig { // Include the corresponding TopicDataType %include "test_included_modulesPubSubTypes.i" - diff --git a/fastdds_python/test/types/test_modules.i b/fastdds_python/test/types/test_modules.i index 50f172aa..f15ecf87 100644 --- a/fastdds_python/test/types/test_modules.i +++ b/fastdds_python/test/types/test_modules.i @@ -2831,4 +2831,3 @@ namespace swig { // Include the corresponding TopicDataType %include "test_modulesPubSubTypes.i" - diff --git a/fastdds_python_examples/HelloWorldExample/CMakeLists.txt b/fastdds_python_examples/HelloWorldExample/CMakeLists.txt index 08cc2db7..e0b6a27d 100644 --- a/fastdds_python_examples/HelloWorldExample/CMakeLists.txt +++ b/fastdds_python_examples/HelloWorldExample/CMakeLists.txt @@ -116,4 +116,4 @@ install(TARGETS ${PROJECT_NAME} ) 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..6ae086d4 100644 --- a/fastdds_python_examples/HelloWorldExample/HelloWorld.i +++ b/fastdds_python_examples/HelloWorldExample/HelloWorld.i @@ -118,4 +118,3 @@ namespace swig { // Include the corresponding TopicDataType %include "HelloWorldPubSubTypes.i" - From e0070ef3b691cfa0bb24f6470e29900ab0737fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Thu, 11 Apr 2024 10:07:27 +0200 Subject: [PATCH 3/6] Refs #20763. Fix win32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González --- fastdds_python/colcon.pkg | 2 +- fastdds_python/src/swig/fastdds.i | 2 +- fastdds_python/test/types/test_complete.i | 2 +- fastdds_python/test/types/test_included_modules.i | 2 +- fastdds_python/test/types/test_modules.i | 2 +- fastdds_python_examples/HelloWorldExample/HelloWorld.i | 1 + 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fastdds_python/colcon.pkg b/fastdds_python/colcon.pkg index 2eae5c49..d91629b7 100644 --- a/fastdds_python/colcon.pkg +++ b/fastdds_python/colcon.pkg @@ -1,5 +1,5 @@ { "name": "fastdds_python", "type": "cmake", - "build-dependencies": ["fastdds"] + "dependencies": ["fastdds"] } diff --git a/fastdds_python/src/swig/fastdds.i b/fastdds_python/src/swig/fastdds.i index de53cae7..1cfd97a4 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('fastdds-3.0.dll')\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 diff --git a/fastdds_python/test/types/test_complete.i b/fastdds_python/test/types/test_complete.i index 1263958e..0329d758 100644 --- a/fastdds_python/test/types/test_complete.i +++ b/fastdds_python/test/types/test_complete.i @@ -19,7 +19,7 @@ * 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 // 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 220e9643..0f4e081a 100644 --- a/fastdds_python/test/types/test_included_modules.i +++ b/fastdds_python/test/types/test_included_modules.i @@ -19,7 +19,7 @@ * 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 // 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 f15ecf87..f543a8f1 100644 --- a/fastdds_python/test/types/test_modules.i +++ b/fastdds_python/test/types/test_modules.i @@ -19,7 +19,7 @@ * 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 // SWIG helper modules %include "stdint.i" diff --git a/fastdds_python_examples/HelloWorldExample/HelloWorld.i b/fastdds_python_examples/HelloWorldExample/HelloWorld.i index 6ae086d4..1bb53381 100644 --- a/fastdds_python_examples/HelloWorldExample/HelloWorld.i +++ b/fastdds_python_examples/HelloWorldExample/HelloWorld.i @@ -20,6 +20,7 @@ */ %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 // SWIG helper modules %include "stdint.i" From 2006de69216a69af35549ada3ba1947a05a26f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Thu, 11 Apr 2024 10:53:17 +0200 Subject: [PATCH 4/6] Refs #20763. Set fastdds version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- fastdds_python/colcon.pkg | 2 +- fastdds_python/src/swig/CMakeLists.txt | 15 ++++++++++----- fastdds_python/src/swig/fastdds.i | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/fastdds_python/colcon.pkg b/fastdds_python/colcon.pkg index d91629b7..2eae5c49 100644 --- a/fastdds_python/colcon.pkg +++ b/fastdds_python/colcon.pkg @@ -1,5 +1,5 @@ { "name": "fastdds_python", "type": "cmake", - "dependencies": ["fastdds"] + "build-dependencies": ["fastdds"] } diff --git a/fastdds_python/src/swig/CMakeLists.txt b/fastdds_python/src/swig/CMakeLists.txt index d0aa04bf..13204f9a 100644 --- a/fastdds_python/src/swig/CMakeLists.txt +++ b/fastdds_python/src/swig/CMakeLists.txt @@ -24,13 +24,16 @@ 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 +configure_file(${${PROJECT_NAME}_MODULE}.i ${${PROJECT_NAME}_FILE} @ONLY) + +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) @@ -41,11 +44,13 @@ 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) diff --git a/fastdds_python/src/swig/fastdds.i b/fastdds_python/src/swig/fastdds.i index 1cfd97a4..c6286a5b 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", moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('fastdds-3.0.dll')\nif __package__ or '.' in __name__:\n from . import _fastdds_python\nelse:\n import _fastdds_python") fastdds +%module(directors="1", threads="1", moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('fastdds-@fastdds_VERSION_MAJOR@.@fastdds_VERSION_MINOR@.dll')\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 From 3d16b9830d8b6d5f16c8fde6a269dca84d9a7e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Fri, 12 Apr 2024 07:36:37 +0200 Subject: [PATCH 5/6] Refs #20763. Fix fastdds dll library import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González --- fastdds_python/src/swig/CMakeLists.txt | 8 ++++++-- fastdds_python/src/swig/fastdds.i | 10 +++++++++- fastdds_python/test/types/test_complete.i | 8 ++++++++ fastdds_python/test/types/test_included_modules.i | 8 ++++++++ fastdds_python/test/types/test_modules.i | 8 ++++++++ fastdds_python_examples/HelloWorldExample/HelloWorld.i | 9 ++++++++- 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/fastdds_python/src/swig/CMakeLists.txt b/fastdds_python/src/swig/CMakeLists.txt index 13204f9a..0623526f 100644 --- a/fastdds_python/src/swig/CMakeLists.txt +++ b/fastdds_python/src/swig/CMakeLists.txt @@ -28,7 +28,10 @@ set(${PROJECT_NAME}_FILE ${CMAKE_CURRENT_BINARY_DIR}/${${PROJECT_NAME}_MODULE}.i ) -configure_file(${${PROJECT_NAME}_MODULE}.i ${${PROJECT_NAME}_FILE} @ONLY) +file(GENERATE + OUTPUT ${${PROJECT_NAME}_FILE} + INPUT ${${PROJECT_NAME}_MODULE}.i + ) set_source_files_properties(${${PROJECT_NAME}_FILE} PROPERTIES CPLUSPLUS ON @@ -44,7 +47,8 @@ endif (BUILD_DOCUMENTATION) swig_add_library(${PROJECT_NAME} TYPE SHARED LANGUAGE python - SOURCES ${${PROJECT_NAME}_FILE} + SOURCES + ${${PROJECT_NAME}_FILE} ) if(UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8) diff --git a/fastdds_python/src/swig/fastdds.i b/fastdds_python/src/swig/fastdds.i index c6286a5b..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", moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('fastdds-@fastdds_VERSION_MAJOR@.@fastdds_VERSION_MINOR@.dll')\nif __package__ or '.' in __name__:\n from . import _fastdds_python\nelse:\n import _fastdds_python") 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/types/test_complete.i b/fastdds_python/test/types/test_complete.i index 0329d758..9abf9a67 100644 --- a/fastdds_python/test/types/test_complete.i +++ b/fastdds_python/test/types/test_complete.i @@ -21,6 +21,14 @@ %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" %include "std_array.i" diff --git a/fastdds_python/test/types/test_included_modules.i b/fastdds_python/test/types/test_included_modules.i index 0f4e081a..0b66cfb8 100644 --- a/fastdds_python/test/types/test_included_modules.i +++ b/fastdds_python/test/types/test_included_modules.i @@ -21,6 +21,14 @@ %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" %include "std_array.i" diff --git a/fastdds_python/test/types/test_modules.i b/fastdds_python/test/types/test_modules.i index f543a8f1..b14a1556 100644 --- a/fastdds_python/test/types/test_modules.i +++ b/fastdds_python/test/types/test_modules.i @@ -21,6 +21,14 @@ %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" %include "std_array.i" diff --git a/fastdds_python_examples/HelloWorldExample/HelloWorld.i b/fastdds_python_examples/HelloWorldExample/HelloWorld.i index 1bb53381..0906684e 100644 --- a/fastdds_python_examples/HelloWorldExample/HelloWorld.i +++ b/fastdds_python_examples/HelloWorldExample/HelloWorld.i @@ -19,9 +19,16 @@ * 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" %include "std_array.i" From 9052c2976086ff53eb1de75e871bc76a52e4c22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Wed, 22 May 2024 10:20:43 +0200 Subject: [PATCH 6/6] Refs #20763. Regenerate code with fastddsgen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- fastdds_python/test/types/CMakeLists.txt | 17 ++++------------- fastdds_python/test/types/test_complete.i | 1 + .../test/types/test_included_modules.i | 1 + fastdds_python/test/types/test_modules.i | 1 + .../HelloWorldExample/CMakeLists.txt | 14 ++++---------- .../HelloWorldExample/HelloWorld.i | 1 + 6 files changed, 12 insertions(+), 23 deletions(-) diff --git a/fastdds_python/test/types/CMakeLists.txt b/fastdds_python/test/types/CMakeLists.txt index 8190cf7f..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,7 +73,6 @@ SET_SOURCE_FILES_PROPERTIES( USE_TARGET_INCLUDE_DIRECTORIES TRUE ) - SWIG_ADD_LIBRARY(${${PROJECT_NAME}_MODULE} TYPE SHARED LANGUAGE python @@ -90,7 +89,6 @@ target_link_libraries(${${PROJECT_NAME}_MODULE} ${PROJECT_NAME} ) - # 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 @@ -191,7 +189,6 @@ target_link_libraries(${${PROJECT_NAME}_MODULE} ${PROJECT_NAME} ) - # 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 @@ -277,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 @@ -295,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 @@ -318,6 +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}/ RENAME __init__.py) +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 9abf9a67..427c275e 100644 --- a/fastdds_python/test/types/test_complete.i +++ b/fastdds_python/test/types/test_complete.i @@ -2851,3 +2851,4 @@ namespace swig { // Include the corresponding TopicDataType %include "test_completePubSubTypes.i" + diff --git a/fastdds_python/test/types/test_included_modules.i b/fastdds_python/test/types/test_included_modules.i index 0b66cfb8..72eb5363 100644 --- a/fastdds_python/test/types/test_included_modules.i +++ b/fastdds_python/test/types/test_included_modules.i @@ -260,3 +260,4 @@ namespace swig { // Include the corresponding TopicDataType %include "test_included_modulesPubSubTypes.i" + diff --git a/fastdds_python/test/types/test_modules.i b/fastdds_python/test/types/test_modules.i index b14a1556..3e4ff7d2 100644 --- a/fastdds_python/test/types/test_modules.i +++ b/fastdds_python/test/types/test_modules.i @@ -2839,3 +2839,4 @@ namespace swig { // Include the corresponding TopicDataType %include "test_modulesPubSubTypes.i" + diff --git a/fastdds_python_examples/HelloWorldExample/CMakeLists.txt b/fastdds_python_examples/HelloWorldExample/CMakeLists.txt index e0b6a27d..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 @@ -114,6 +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}/ RENAME __init__.py) +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 0906684e..279f30f7 100644 --- a/fastdds_python_examples/HelloWorldExample/HelloWorld.i +++ b/fastdds_python_examples/HelloWorldExample/HelloWorld.i @@ -126,3 +126,4 @@ namespace swig { // Include the corresponding TopicDataType %include "HelloWorldPubSubTypes.i" +