Skip to content

Add option to set output_format via environment variable #713

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

Open
wants to merge 5 commits into
base: rolling
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions launch/launch/actions/execute_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(
'sigkill_timeout', default=5),
emulate_tty: bool = False,
output: SomeSubstitutionsType = 'log',
output_format: Text = '[{this.process_description.final_name}] {line}',
output_format: Optional[Text] = None,
cached_output: bool = False,
log_cmd: bool = False,
on_exit: Optional[Union[
Expand Down Expand Up @@ -173,6 +173,7 @@ def __init__(
:param: output_format for logging each output line, supporting `str.format()`
substitutions with the following keys in scope: `line` to reference the raw
output line and `this` to reference this action instance.
The default format can be set externally by the ROS_LAUNCH_OUTPUT_FORMAT envvar.
:param: log_cmd if True, prints the final cmd before executing the
process, which is useful for debugging when substitutions are
involved.
Expand All @@ -199,7 +200,17 @@ def __init__(
self.__output = normalize_to_list_of_substitutions(tmp_output)
else:
self.__output = tmp_output
self.__output_format = output_format

# We use the following priorities to determine the output_format:
# 1. Passed value to the function
# 2. Environment variable
# 3. Default value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says default is ROS_LAUNCH_OUTPUT_FORMAT, but here says [{this.process_description.final_name}] {line}? these comments are confusing for me.

As user perspective if they use ROS_LAUNCH_OUTPUT_FORMAT, that should be able to override the setting in the implementation. i think that what environmental variables does usually, so that they do not change the implementation at all.

so i would suggest that,

  1. ROS_LAUNCH_OUTPUT_FORMAT
  2. argument to the function.
  3. falls back to the default value [{this.process_description.final_name}] {line}

what do you think?

CC: @wjwwood

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring means that the default can be choosen by ROS_LAUNCH_OUTPUT_FORMAT. If it is not set it will fallback to [{this.process_description.final_name}] {line}. I see that it is confusingly written. I can adapt this, however we should first decide on the other question of the priority ordering.

The order or priorities was especially requested this way by @clalancette in this comment
I personally don't care if the environment variable or the function argument has a higher priority. I can understand both sides.
@wjwwood also proposed here to have an additional env var which overrides everything. I did not add it as I thought it might be a bit too much complexity. But if you would prefere it, I could change it. Then the priorities would be

  1. ROS_LAUNCH_OUTPUT_FORMAT_OVERRIDE
  2. argument of the function
  3. ROS_LAUNCH_OUTPUT_FORMAT_DEFAULT
  4. [{this.process_description.final_name}] {line}

Would you prefer this solution?

if output_format is not None:
self.__output_format = output_format
else:
self.__output_format = os.environ.get(
'ROS_LAUNCH_OUTPUT_FORMAT', '[{this.process_description.final_name}] {line}'
)

self.__log_cmd = log_cmd
self.__cached_output = cached_output
Expand Down