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

CMakeLists Command Escapes Python Virtual Environment #19

Open
Foxei opened this issue Dec 13, 2023 · 1 comment
Open

CMakeLists Command Escapes Python Virtual Environment #19

Foxei opened this issue Dec 13, 2023 · 1 comment

Comments

@Foxei
Copy link

Foxei commented Dec 13, 2023

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
Copy link
Author

Foxei commented Dec 13, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant