ros2 / ros2/rosidl_python

Python docstring for message documentation

Open
#196 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
EmberScript
Stars
26
Forks
68
Avg merge
2d 13h
Merged PRs (30d)
1

Description

Enhancement Request

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • Source
  • Version or commit hash:
    • git branch: Humble
  • DDS implementation:
    • N/A
  • Client library (if applicable):
    • rclpy
Steps to reproduce issue

When looking at a message class documentation in Python, the message comments don't really show making it more complicated to understand the message.

For example take the statistics_msgs/MetricsMessage, the source file has lots of good documentation for the message itself as well as for each of the fields contained in the message.
When looking at the python documentation for the message, we see:

Help on class MetricsMessage in module statistics_msgs.msg._metrics_message:

class MetricsMessage(builtins.object)
 |  MetricsMessage(**kwargs)
 |  
 |  Message class 'MetricsMessage'.
 |  
 |  Methods defined here:
 |  
 |  __eq__(self, other)
 |      Return self==value.
 |  
 |  __init__(self, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __repr__(self)
 |      Return repr(self).
 |  
 |  ----------------------------------------------------------------------
 |  Class methods defined here:
 |  
 |  get_fields_and_field_types() from statistics_msgs.msg._metrics_message.Metaclass_MetricsMessage
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  measurement_source_name
 |      Message field 'measurement_source_name'.
 |  
 |  metrics_source
 |      Message field 'metrics_source'.
 |  
 |  statistics
 |      Message field 'statistics'.
 |  
 |  unit
 |      Message field 'unit'.
 |  
 |  window_start
 |      Message field 'window_start'.
 |  
 |  window_stop
 |      Message field 'window_stop'.
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  SLOT_TYPES = (<rosidl_parser.definition.UnboundedString object>, <rosi...
 |  
 |  __hash__ = None

All of this without any of the message creator help data.

Expected behavior

Instead, we could build in the documentation comments from the original message documentation into the python class docstring making it better for developers to access the documentation.
A potential outcome for this message type:

 Help on class MetricsMessage in module statistics_msgs.msg._metrics_message:

class MetricsMessage(builtins.object)
 |  MetricsMessage(**kwargs)
 |  
 |  Message class 'MetricsMessage'.
 |  
 |  A generic metrics message providing statistics for measurements from different sources. For example,
 |  
 |  measure a system's CPU % for a given window yields the following data points over a window of time:
 |    - average cpu %
 |    - std deviation
 |    - min
 |    - max
 |    - sample count
 | 
 |  These are all represented as different 'StatisticDataPoint's.
 |  
 |  Fields:
 |    measurement_source_name (string): Name metric measurement source, e.g., node, topic, or process name
 |    metrics_source (string): Name of the metric being measured, e.g. cpu_percentage, free_memory_mb, message_age, etc.
 |    unit (string): Unit of measure of the metric, e.g. percent, mb, seconds, etc.
 |    window_start (builtin_interfaces/Time): Measurement window start time
 |    window_stop (builtin_interfaces/Time): Measurement window end time
 |    statistics (sequence<statistics_msgs/StatisticDataPoint>): A list of statistics data point, defined in StatisticDataPoint.msg
 |  
 |  Methods defined here:
 |  
 |  __eq__(self, other)
 |      Return self==value.
 |  
 |  __init__(self, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __repr__(self)
 |      Return repr(self).
 |  
 |  ----------------------------------------------------------------------
 |  Class methods defined here:
 |  
 |  get_fields_and_field_types() from statistics_msgs.msg._metrics_message.Metaclass_MetricsMessage
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
<..snip..>

Feature request

Feature description

Transfer message file documentation into python docstrings for the corresponding message.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare the source comments in statistics_msgs/msg/MetricsMessage.msg with the generated statistics_msgs.msg._metrics_message class shown in the issue. Start by locating the rosidl Python generation path that produces this class, then identify existing generation tests. Done means message and field documentation from the source appears in the corresponding Python docstrings and is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.