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 1 commit
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
16 changes: 11 additions & 5 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 @@ -131,6 +133,7 @@ def generate(self):
tc.cache_variables["CLOE_ENGINE_WITH_SERVER"] = self.options.engine_server
tc.cache_variables["CLOE_ENGINE_WITH_LRDB"] = self.options.engine_lrdb
tc.cache_variables["CLOE_PYTHON_API"] = self.options.python_api
tc.cache_variables["PYTHON_BINDINGS_LOCAL_DEV"] = not self.in_local_cache
CzBalti marked this conversation as resolved.
Show resolved Hide resolved
tc.generate()

def build(self):
Expand Down Expand Up @@ -196,23 +199,26 @@ 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")
pydir = os.path.join(self.build_folder, "lib/cloe/python")
py_path = os.path.join(self.source_folder, "python/python_api")
CzBalti marked this conversation as resolved.
Show resolved Hide resolved
libdir = os.path.join(self.build_folder, "lib")
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")
py_path = pydir
libdir = None

self.output.info(f"Appending PATH environment variable: {bindir}")
self.runenv_info.prepend_path("PATH", bindir)
self.output.info(f"Appending CLOE_LUA_PATH environment variable: {luadir}")
self.runenv_info.prepend_path("CLOE_LUA_PATH", luadir)
if libdir is not None:
#TODO
CzBalti marked this conversation as resolved.
Show resolved Hide resolved
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 BASIC_CLOE_PYTHON_BINDINGS environment variables: {pydir}")
self.runenv_info.prepend_path("PYTHONPATH", str(py_path))
self.runenv_info.prepend_path("BASIC_CLOE_PYTHON_BINDINGS", str(pydir))
CzBalti marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions plugins/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ set_target_properties(_basic_bindings PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)

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

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

include(CTest)
Expand Down
11 changes: 4 additions & 7 deletions python/python_api/cloe/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def log_level(self, value):

def bind_plugin_types(self, lib: Path):
import importlib
import importlib.util
CzBalti marked this conversation as resolved.
Show resolved Hide resolved
import sys
components = str(lib.name).split('.')
module_name = components[0]
Expand All @@ -194,11 +195,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 All @@ -211,11 +208,11 @@ def __init__(self, stack: Optional[Dict[str, Any]] = None):

self._sim = _Simulation(full_config_stack, self.driver, uuid="123")

if "CLOE_PYTHON_BINDINGS" in os.environ:
if "BASIC_CLOE_PYTHON_BINDINGS" in os.environ:
import importlib.util
import sys
binding_libs = []
for binding_dir in os.environ["CLOE_PYTHON_BINDINGS"].split(":"):
for binding_dir in os.environ["BASIC_CLOE_PYTHON_BINDINGS"].split(":"):
if len(str(binding_dir)) > 1:
binding_path = Path(binding_dir)
if binding_path.exists():
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
33 changes: 26 additions & 7 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"
}
]
}
}
CzBalti marked this conversation as resolved.
Show resolved Hide resolved
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