Skip to content

Commit

Permalink
fix python binding on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ydaveluy committed Dec 29, 2023
1 parent 0310d60 commit da0a2f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:
- name: Run tests
working-directory: build
run: |
ctest -C Release --output-on-failure -E "XsmpSchedulerTest|PythonTest|xsmp_example_project1Test"
ctest -C Release --output-on-failure -E "XsmpSchedulerTest"
python:
name: '${{matrix.os}} :: Python ${{matrix.python-version}}'
runs-on: ${{matrix.os}}
Expand All @@ -168,7 +168,7 @@ jobs:
os:
- ubuntu-latest
- macos-latest
# - windows-latest
- windows-latest
python-version:
- '3.7'
- '3.8'
Expand All @@ -189,4 +189,4 @@ jobs:
max_attempts: 3
retry_on: error
timeout_minutes: 1
command: python -m pytest python -v
command: python -m pytest python -v
10 changes: 5 additions & 5 deletions cmake/PytestAddTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function(pytest_discover_tests_impl)

# Use platform specific path separator (";" on windows else ":") and convert path to native platform (replace "/" by "\" on Windows)
if (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
string(REPLACE "][" "\\;" _LIBRARY_PATH "${_LIBRARY_PATH}")
string(REPLACE "][" "\\;" _PYTHON_PATH "${_PYTHON_PATH}")
string(REPLACE "][" "\\\\;" _LIBRARY_PATH "${_LIBRARY_PATH}")
string(REPLACE "][" "\\\\;" _PYTHON_PATH "${_PYTHON_PATH}")
string(REPLACE "/" "\\\\" _LIBRARY_PATH "${_LIBRARY_PATH}")
string(REPLACE "/" "\\\\" _PYTHON_PATH "${_PYTHON_PATH}")
else()
Expand All @@ -29,7 +29,7 @@ function(pytest_discover_tests_impl)
string(APPEND _content
"add_test(\"${_TEST_GROUP_NAME}\" ${_PYTHON_EXECUTABLE} -m pytest \"${_WORKING_DIRECTORY}\"\)\n"
"set_tests_properties(\"${_TEST_GROUP_NAME}\" PROPERTIES ENVIRONMENT \"${_LIB_ENV_PATH}=${_LIBRARY_PATH}\")\n"
"set_tests_properties(\"${_TEST_GROUP_NAME}\" APPEND PROPERTIES ENVIRONMENT \"PYTHONPATH=${_PYTHON_PATH}\")\n"
"set_tests_properties(\"${_TEST_GROUP_NAME}\" PROPERTIES ENVIRONMENT \"PYTHONPATH=${_PYTHON_PATH}\")\n"
)

foreach(env ${_ENVIRONMENT})
Expand Down Expand Up @@ -90,7 +90,7 @@ function(pytest_discover_tests_impl)
string(APPEND _content
"add_test(\"${test_name}\" ${_PYTHON_EXECUTABLE} -m pytest \"${test_case}\")\n"
"set_tests_properties(\"${test_name}\" PROPERTIES ENVIRONMENT \"${_LIB_ENV_PATH}=${_LIBRARY_PATH}\")\n"
"set_tests_properties(\"${test_name}\" APPEND PROPERTIES ENVIRONMENT \"PYTHONPATH=${_PYTHON_PATH}\")\n"
"set_tests_properties(\"${test_name}\" PROPERTIES ENVIRONMENT \"PYTHONPATH=${_PYTHON_PATH}\")\n"
)

foreach(env ${_ENVIRONMENT})
Expand All @@ -105,7 +105,7 @@ function(pytest_discover_tests_impl)
string(APPEND _content
"add_test(\"${_TEST_GROUP_NAME}\" ${_PYTHON_EXECUTABLE} -m pytest \"${_WORKING_DIRECTORY}\"\)\n"
"set_tests_properties(\"${_TEST_GROUP_NAME}\" PROPERTIES ENVIRONMENT \"${_LIB_ENV_PATH}=${_LIBRARY_PATH}\")\n"
"set_tests_properties(\"${_TEST_GROUP_NAME}\" APPEND PROPERTIES ENVIRONMENT \"PYTHONPATH=${_PYTHON_PATH}\")\n"
"set_tests_properties(\"${_TEST_GROUP_NAME}\" PROPERTIES ENVIRONMENT \"PYTHONPATH=${_PYTHON_PATH}\")\n"
)

foreach(env ${_ENVIRONMENT})
Expand Down
10 changes: 10 additions & 0 deletions src/python/ecss_smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
namespace py = pybind11;

namespace PYBIND11_NAMESPACE {

template <typename itype>
struct polymorphic_type_hook<itype, std::enable_if_t<std::is_base_of_v<Smp::IObject, itype>>> {
static const void *get(const itype *src, const std::type_info *&type) {
type = src ? &typeid(*src) : nullptr;
return static_cast<const Smp::IObject *>(src);
}
};

struct TypeHierarchy {

template<typename T>
Expand Down Expand Up @@ -220,6 +229,7 @@ class SmpClass: public detail::generic_type {
record.dealloc = dealloc;
record.default_holder = true;
record.module_local = true;
record.is_final = true;

processHierarchy(IObjectHierarchy, obj, record);

Expand Down

0 comments on commit da0a2f3

Please sign in to comment.