mROS-base / mros2-esp32

reference implementation of mROS 2 for ESP32 boards
Apache License 2.0
47 stars 9 forks source link

CMakeLists Command Escapes Python Virtual Environment #19

Open Foxei opened 11 months ago

Foxei commented 11 months ago

Short Summary

The CMakeLists file escapes the Espressif Python virtual environment when generating the template.hpp, if this project is used as a component.

Current State

The provided code generates the template.hpp when using mros2-esp32 as a component. It executes within the host's Python3 environment, and not the Espressif IDF virtual Python environment set by the export.sh script before the build step.

add_custom_command(
        OUTPUT templates.hpp
        COMMAND python3 ${COMPONENT_PATH}/mros2/mros2_header_generator/templates_generator.py --outdir ${COMPONENT_PATH}/platform --indir ${CMAKE_SOURCE_DIR}/main)
add_custom_target(Template SOURCES templates.hpp)
add_dependencies(${COMPONENT_LIB} Template)

Proposed Change

I suggest forcing CMake to use the Espressif IDF Python virtual environment to avoid mixing the host and the virtual environment. The following change makes this possible.

set(PYTHON "$ENV{HOME}/.espressif/python_env/idf5.2_py3.9_env/bin/python")
add_custom_command(
        OUTPUT templates.hpp
        COMMAND ${PYTHON} ${COMPONENT_PATH}/mros2/mros2_header_generator/templates_generator.py --outdir ${COMPONENT_PATH}/platform --indir ${CMAKE_SOURCE_DIR}/main)
add_custom_target(Template SOURCES templates.hpp)
add_dependencies(${COMPONENT_LIB} Template)

Final Remarks

In order to provide clarity on the expected behavior and environment requirements, the documentation should be updated to include information about the necessary Python environment. Currently, it only mentions the need to install Jinja2 not in which environment.

I'm more than happy to assist and create the pull request if this behavior aligns with the project's intentions. Please let me know your thoughts, and I'll proceed accordingly. ✌🏼

Simon

Foxei commented 11 months ago

Obviously I will not hardcode the idf5.2_py3.9_env version numbers in the pull request.