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 860bdbb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- enable-tests-on-windows
pull_request:
branches:
- main
Expand Down Expand Up @@ -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}}
Expand All @@ -168,7 +167,7 @@ jobs:
os:
- ubuntu-latest
- macos-latest
# - windows-latest
- windows-latest
python-version:
- '3.7'
- '3.8'
Expand All @@ -189,4 +188,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
5 changes: 5 additions & 0 deletions examples/project1/python/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# pytest.ini
[pytest]
#minversion = 6.0
#addopts = -ra -q
pythonpath = .
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 860bdbb

Please sign in to comment.