ros2/rosidl_python

extra parenthesis in generated file

flynneva opened this issue · 4 comments

Bug report

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • binaries
  • Version or commit hash:
    • galactic
  • DDS implementation:
    • NA
  • Client library (if applicable):
    • N/A

Steps to reproduce issue

cd colcon_ws/src
git clone https://github.com/ros-realtime/reference-system.git

cd colcon_ws
colcon build
colcon test

the logs for reference_interfaces should show the error during the flake8 tests.

Expected behavior

generated files do not throw lint errors and can be run without error

Actual behavior

Generated file has this error when passed into the python interpreter:

build/reference_interfaces/rosidl_generator_py/reference_interfaces/msg$ python3 _transmission_stats.py 
  File "_transmission_stats.py", line 167
    all(val >= 0 and val) < 256 for val in value)), \
                                                 ^
SyntaxError: unmatched ')'

it looks like an extra parenthesis was added to the file.

Additional information

this is the offending idl file

UPDATE: update/fix broken links

looks like its coming from this line which I think does in fact have an extra parenthesis

if anyone else ends up here before the fix is released, just add this to the bottom of your package to automatically fix, modifying as needed. the key is the TARGET name being your package name + __python to wait for rosidl_generator_py to do its thing.

NOTE: just make sure to change the YOUR_MSG_NAME to your message name 😄

# fix rosidl_generator_py bug #143
# https://github.com/ros2/rosidl_python/issues/143
set(GENERATED_FILE "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_py/${PROJECT_NAME}/msg/_YOUR_MSG_NAME.py")

message(STATUS "checking generated file: ${GENERATED_FILE}")
add_custom_command(
  TARGET ${PROJECT_NAME}__python
  POST_BUILD
  COMMAND sed -i "s/all(val >= 0 and val) < 256/all(ord(val) >= 0 and ord(val) < 256/" ${GENERATED_FILE}
  COMMENT "Check generated IDL files for extra parenthesis..."
  VERBATIM)

This issue has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/call-cmake-add-custom-command-after-rosidl-generator-py-is-done/22299/2

Closing this as a duplicate of #124