From 860bdbba4c11766b9be63136da3a9b9a3ad53f95 Mon Sep 17 00:00:00 2001 From: Yannick Daveluy Date: Fri, 29 Dec 2023 14:29:37 +0100 Subject: [PATCH] fix python binding on Windows --- .github/workflows/build.yml | 7 +++---- cmake/PytestAddTests.cmake | 10 +++++----- examples/project1/python/pytest.ini | 5 +++++ .../test_xsmp_example_project1.py | 7 +++++-- pyproject.toml | 7 +------ src/python/ecss_smp.h | 10 ++++++++++ 6 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 examples/project1/python/pytest.ini diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 653184e..96e45b1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - enable-tests-on-windows pull_request: branches: - main @@ -158,7 +157,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}} @@ -168,7 +167,7 @@ jobs: os: - ubuntu-latest - macos-latest -# - windows-latest + - windows-latest python-version: - '3.7' - '3.8' @@ -189,4 +188,4 @@ jobs: max_attempts: 3 retry_on: error timeout_minutes: 1 - command: python -m pytest python -v \ No newline at end of file + command: python -m pytest python -v diff --git a/cmake/PytestAddTests.cmake b/cmake/PytestAddTests.cmake index 0ca2ac1..34910f5 100644 --- a/cmake/PytestAddTests.cmake +++ b/cmake/PytestAddTests.cmake @@ -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() @@ -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}) @@ -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}) @@ -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}) diff --git a/examples/project1/python/pytest.ini b/examples/project1/python/pytest.ini new file mode 100644 index 0000000..a8d1c76 --- /dev/null +++ b/examples/project1/python/pytest.ini @@ -0,0 +1,5 @@ +# pytest.ini +[pytest] +#minversion = 6.0 +#addopts = -ra -q +pythonpath = . \ No newline at end of file diff --git a/examples/project1/python/xsmp_example_project1/test_xsmp_example_project1.py b/examples/project1/python/xsmp_example_project1/test_xsmp_example_project1.py index 85059e8..927f8aa 100644 --- a/examples/project1/python/xsmp_example_project1/test_xsmp_example_project1.py +++ b/examples/project1/python/xsmp_example_project1/test_xsmp_example_project1.py @@ -3,7 +3,7 @@ import xsmp_example_project1 -class Test(xsmp.unittest.TestCase): +class TestXsmpExampleProject1(xsmp.unittest.TestCase): try: sim: xsmp_example_project1._test_xsmp_example_project1.Simulator except AttributeError: @@ -14,5 +14,8 @@ def loadAssembly(self, sim: ecss_smp.Smp.ISimulator): sim.AddModel(sim.CreateInstance(xsmp_example_project1.Example.M1.uuid, "name", "", sim)) def test_Init(self): - self.sim.Exit() + pass + + def test_Init2(self): + pass \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index eadd505..2b4ab62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,12 +45,7 @@ wheel.packages = [ [tool.scikit-build.cmake.define] XSMP_BUILD_PYTHON_BINDINGS = "ON" -[tool.pytest.ini_options] -minversion = "6.0" -addopts = "-ra -q" -testpaths = [ - "tests" -] + [tool.cibuildwheel] test-extras = "test" test-command = "python -m pytest {project}/python -v" diff --git a/src/python/ecss_smp.h b/src/python/ecss_smp.h index 5c0535b..26a8cbe 100644 --- a/src/python/ecss_smp.h +++ b/src/python/ecss_smp.h @@ -61,6 +61,15 @@ namespace py = pybind11; namespace PYBIND11_NAMESPACE { + +template +struct polymorphic_type_hook>> { + static const void *get(const itype *src, const std::type_info *&type) { + type = src ? &typeid(*src) : nullptr; + return static_cast(src); + } +}; + struct TypeHierarchy { template @@ -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);