Skip to content

CMakeLists Command Escapes Python Virtual Environment #19

@Foxei

Description

@Foxei

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions