Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build the python poc #239

Open
wants to merge 3 commits into
base: moritz/pyapi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Cloe(ConanFile):
"cloe-plugin-noisy-sensor",
"cloe-plugin-speedometer",
"cloe-plugin-virtue",
"cloe-databroker-bindings",
"cloe-python-api"
)
options = {
"shared": [True, False],
Expand Down Expand Up @@ -99,7 +101,7 @@ def requirements(self):
if self.options.engine_server:
self.requires("oatpp/1.3.0")
if self.options.python_api:
self.requires("pybind11/2.10.1")
self.requires("pybind11/2.11.1")

def build_requirements(self):
self.test_requires("gtest/1.13.0")
Expand Down Expand Up @@ -196,13 +198,17 @@ def package_info(self):
self.cpp_info.includedirs.append(os.path.join(self.build_folder, "include"))
bindir = os.path.join(self.build_folder, "bin")
luadir = os.path.join(self.source_folder, "engine/lua")
pydir = os.path.join(self.source_folder, "python/python_api")
pypath_build = os.path.join(self.build_folder, "lib/cloe/python")
pypath_source = os.path.join(self.source_folder, "python/python_api")
libdir = os.path.join(self.build_folder, "lib")
cloe_bindings_path = libdir
else:
self.cpp_info.builddirs.append(os.path.join("lib", "cmake", "cloe"))
bindir = os.path.join(self.package_folder, "bin")
luadir = os.path.join(self.package_folder, "lib/cloe/lua")
pydir = os.path.join(self.package_folder, "lib/cloe/python")
pypath_build = os.path.join(self.package_folder, "lib/cloe/python")
pypath_source = pypath_build
cloe_bindings_path = os.path.join(self.package_folder, "lib/cloe/python/cloe")
libdir = None

self.output.info(f"Appending PATH environment variable: {bindir}")
Expand All @@ -213,6 +219,7 @@ def package_info(self):
self.output.info(f"Appending LD_LIBRARY_PATH environment variable: {libdir}")
self.runenv_info.append_path("LD_LIBRARY_PATH", libdir)
if self.options.python_api:
self.output.info(f"Appending PYHTONPATH and CLOE_PYTHON_BINDINGS environment variables: {pydir}")
self.runenv_info.prepend_path("PYTHONPATH", str(pydir))
self.runenv_info.prepend_path("CLOE_PYTHON_BINDINGS", str(pydir))
self.output.info(f"Appending PYHTONPATH and CLOE_PYTHON_BINDINGS environment variables")
self.runenv_info.prepend_path("PYTHONPATH", str(pypath_source))
self.runenv_info.prepend_path("PYTHONPATH", str(cloe_bindings_path))
self.runenv_info.prepend_path("CLOE_PYTHON_BINDINGS", str(pypath_build))
8 changes: 8 additions & 0 deletions plugins/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ set_target_properties(_basic_bindings PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)

set_target_properties(_basic_bindings
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cloe/python"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cloe/python"
)


install(TARGETS _basic_bindings LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/cloe/python)

include(CTest)
Expand Down
2 changes: 1 addition & 1 deletion python/python_api/cloe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from ._runner import TestRunner, Simulation
from ._cloe_bindings import CallbackResult
from _cloe_bindings import CallbackResult
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary / safe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above you're still importing from ._runner, implying that mechanism still works.
So what is removing relative import gaining here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In editable mode the _cloe_bindings.so file is not next to the python file so relative import won't work.
Python finds it through the PYTHONPATH env variable.

14 changes: 5 additions & 9 deletions python/python_api/cloe/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from datetime import timedelta
from pathlib import Path
import os
import sys
from time import sleep
from typing import Optional, Dict, Any
from queue import Queue, Empty

from ._cloe_bindings import SimulationDriver, CallbackResult, DataBrokerAdapter, SimulationDriver, Stack
from ._cloe_bindings import Simulation as _Simulation
from _cloe_bindings import SimulationDriver, CallbackResult, DataBrokerAdapter, SimulationDriver, Stack
from _cloe_bindings import Simulation as _Simulation


@dataclass
Expand Down Expand Up @@ -176,8 +177,7 @@ def log_level(self, value):
self._sim.log_level = value

def bind_plugin_types(self, lib: Path):
import importlib
import sys
import importlib.util
CzBalti marked this conversation as resolved.
Show resolved Hide resolved
components = str(lib.name).split('.')
module_name = components[0]
print(f"Attempting to load module {module_name} from {lib}")
Expand All @@ -194,11 +194,7 @@ def bind_plugin_types(self, lib: Path):
def __init__(self, stack: Optional[Dict[str, Any]] = None):
self.databroker_adapter = DataBrokerAdapter()
self.driver = SimulationDriver(self.databroker_adapter)
if "CLOE_PLUGIN_PATH" not in os.environ:
# todo this is just here for debugging
plugin_paths = ["/home/ohf4fe/dev/sil/cloe/build/linux-x86_64-gcc-8/Debug/lib/cloe"]
else:
plugin_paths = os.environ["CLOE_PLUGIN_PATH"].split(":")
plugin_paths = os.environ["CLOE_PLUGIN_PATH"].split(":")
full_config_stack = Stack(plugin_paths)
if not stack:
# todo this is just here for debugging
Expand Down
9 changes: 0 additions & 9 deletions python/python_api/cloe/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
set(PYTHON_BINDINGS_LOCAL_DEV OFF CACHE BOOL "This sets the compiler output to the local source tree so
the cloe python project can be simply imported.")
set(CLOE_FIND_PACKAGES ON CACHE BOOL "Call find_package() for cloe packages")
set(CLOE_ENGINE_VERSION ${CLOE_PROJECT_VERSION})
if(CLOE_FIND_PACKAGES)
Expand All @@ -24,13 +22,6 @@ set_target_properties(_cloe_bindings PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
if(PYTHON_BINDINGS_LOCAL_DEV)
set_target_properties(_cloe_bindings
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/.."
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/.."
)
endif()

target_link_libraries(_cloe_bindings PUBLIC cloe::stacklib cloe::databroker-bindings cloe::simulation)
target_include_directories(_cloe_bindings PRIVATE ${PROJECT_SOURCE_DIR}/engine/src)
Expand Down
31 changes: 29 additions & 2 deletions python/python_api/cloe/test/config_minimator_infinite.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,35 @@
},
"simulators": [
{
"binding": "minimator"
// name is automatically "minimator"
"binding": "minimator",
"args": {
"vehicles": {
"ego1": {
"ego_sensor_mockup": {
"ego_object": {
"velocity": 20.0,
"position": {
"x": 0.0,
"y": 0.0,
"z": 0.0
}
}
},
"object_sensor_mockup": {
"objects": [
{
"velocity": 0.0,
"position": {
"x": 10.0,
"y": 0.0,
"z": 0.0
}
}
]
}
}
}
}
}
],
"vehicles": [
Expand Down
31 changes: 25 additions & 6 deletions python/python_api/cloe/test/config_minimator_smoketest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,37 @@
"include": [
"config_minimator_infinite.json"
],
"logging": [
{
"name": "*",
"level": "error"
}
],
"server": {
"listen": false,
"listen_port": 23456
},
"triggers": [
{"event": "virtue/failure", "action": "fail"},
{
"label": "Vehicle default should never move with the minimator binding.",
"event": "default_speed/kmph=>0.0", "action": "fail"
"event": "virtue/failure",
"action": "fail"
},
{"event": "start", "action": "log=info: Running minimator/basic smoketest."},
{"event": "start", "action": "realtime_factor=-1"},
{"event": "time=60", "action": "succeed"}
{
"label": "Vehicle default should never move at a velocity greater that 72 kmph with the minimator binding.",
"event": "default_speed/kmph=>80.0",
"action": "fail"
},
{
"event": "start",
"action": "log=info: Running minimator/basic smoketest."
},
{
"event": "start",
"action": "realtime_factor=-1"
},
{
"event": "time=60",
"action": "succeed"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <typeindex>
#include <any>
#include <unordered_map>
#include <string>

namespace cloe {
/**
Expand Down
Loading