From d116d7b7224bbba67c5a1b297bb66ce8d9687e76 Mon Sep 17 00:00:00 2001 From: Marc Bestmann Date: Tue, 27 Jun 2023 15:30:09 +0200 Subject: [PATCH 1/5] add option to set output_format via environment variable Signed-off-by: Marc Bestmann --- launch/launch/actions/execute_local.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/launch/launch/actions/execute_local.py b/launch/launch/actions/execute_local.py index 4b5dfca84..5662e1056 100644 --- a/launch/launch/actions/execute_local.py +++ b/launch/launch/actions/execute_local.py @@ -74,6 +74,8 @@ from ..utilities.type_utils import normalize_typed_substitution from ..utilities.type_utils import perform_typed_substitution +DEFAULT_OUTPUT_FORMAT = '[{this.process_description.final_name}] {line}' + class ExecuteLocal(Action): """Action that begins executing a process on the local system and sets up event handlers.""" @@ -89,7 +91,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: Text = DEFAULT_OUTPUT_FORMAT, cached_output: bool = False, log_cmd: bool = False, on_exit: Optional[Union[ @@ -199,7 +201,14 @@ def __init__( self.__output = normalize_to_list_of_substitutions(tmp_output) else: self.__output = tmp_output - self.__output_format = output_format + + # Check if an environment variable is set and use this as a default + self.__output_format = os.environ.get( + 'LAUNCH_OUTPUT_FORMAT', output_format + ) + # Setting it locally in the launch file still overwrites the default + if output_format != DEFAULT_OUTPUT_FORMAT: + self.__output_format = output_format self.__log_cmd = log_cmd self.__cached_output = cached_output From 46a3f819efe9d2d83dfaa7021151976493d3659e Mon Sep 17 00:00:00 2001 From: Marc Bestmann Date: Fri, 14 Jul 2023 10:29:50 +0200 Subject: [PATCH 2/5] change format envvar to override Signed-off-by: Marc Bestmann --- launch/launch/actions/execute_local.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/launch/launch/actions/execute_local.py b/launch/launch/actions/execute_local.py index 5662e1056..be450bf8c 100644 --- a/launch/launch/actions/execute_local.py +++ b/launch/launch/actions/execute_local.py @@ -74,8 +74,6 @@ from ..utilities.type_utils import normalize_typed_substitution from ..utilities.type_utils import perform_typed_substitution -DEFAULT_OUTPUT_FORMAT = '[{this.process_description.final_name}] {line}' - class ExecuteLocal(Action): """Action that begins executing a process on the local system and sets up event handlers.""" @@ -91,7 +89,7 @@ def __init__( 'sigkill_timeout', default=5), emulate_tty: bool = False, output: SomeSubstitutionsType = 'log', - output_format: Text = DEFAULT_OUTPUT_FORMAT, + output_format: Text = '[{this.process_description.final_name}] {line}', cached_output: bool = False, log_cmd: bool = False, on_exit: Optional[Union[ @@ -175,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. + Overridden externally by the OVERRIDE_LAUNCH_OUTPUT_FORMAT envvar value. :param: log_cmd if True, prints the final cmd before executing the process, which is useful for debugging when substitutions are involved. @@ -202,13 +201,11 @@ def __init__( else: self.__output = tmp_output - # Check if an environment variable is set and use this as a default + self.__output_format = output_format + # Check if an environment variable is set and override anything given as argument self.__output_format = os.environ.get( - 'LAUNCH_OUTPUT_FORMAT', output_format + 'OVERRIDE_LAUNCH_OUTPUT_FORMAT', self.__output_format ) - # Setting it locally in the launch file still overwrites the default - if output_format != DEFAULT_OUTPUT_FORMAT: - self.__output_format = output_format self.__log_cmd = log_cmd self.__cached_output = cached_output From 13eaf6ef127a0c529f14d8f01246a5969fc3cbf9 Mon Sep 17 00:00:00 2001 From: Marc Bestmann Date: Mon, 11 Sep 2023 10:42:08 +0200 Subject: [PATCH 3/5] change priority of setting output format Signed-off-by: Marc Bestmann --- launch/launch/actions/execute_local.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/launch/launch/actions/execute_local.py b/launch/launch/actions/execute_local.py index be450bf8c..9d6654089 100644 --- a/launch/launch/actions/execute_local.py +++ b/launch/launch/actions/execute_local.py @@ -173,7 +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. - Overridden externally by the OVERRIDE_LAUNCH_OUTPUT_FORMAT envvar value. + 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. @@ -201,11 +201,16 @@ def __init__( else: self.__output = tmp_output - self.__output_format = output_format - # Check if an environment variable is set and override anything given as argument - self.__output_format = os.environ.get( - 'OVERRIDE_LAUNCH_OUTPUT_FORMAT', self.__output_format - ) + # We use the following priorities to determine the output_format: + # 1. Passed value to the function + # 2. Environment variable + # 3. Default value + if output_format != "[{this.process_description.final_name}] {line}": + self.__output_format = output_format + else: + self.__output_format = os.environ.get( + "ROS_LAUNCH_OUTPUT_FORMAT", output_format + ) self.__log_cmd = log_cmd self.__cached_output = cached_output From 713a84225ab7d2b542897ee399b45c51e5741a3f Mon Sep 17 00:00:00 2001 From: Marc Bestmann Date: Tue, 16 Jan 2024 17:08:05 +0100 Subject: [PATCH 4/5] remove double string literal Signed-off-by: Marc Bestmann --- launch/launch/actions/execute_local.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/launch/launch/actions/execute_local.py b/launch/launch/actions/execute_local.py index 9d6654089..fd92205b4 100644 --- a/launch/launch/actions/execute_local.py +++ b/launch/launch/actions/execute_local.py @@ -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: Text = None, cached_output: bool = False, log_cmd: bool = False, on_exit: Optional[Union[ @@ -205,11 +205,11 @@ def __init__( # 1. Passed value to the function # 2. Environment variable # 3. Default value - if output_format != "[{this.process_description.final_name}] {line}": + if output_format is not None: self.__output_format = output_format else: self.__output_format = os.environ.get( - "ROS_LAUNCH_OUTPUT_FORMAT", output_format + 'ROS_LAUNCH_OUTPUT_FORMAT', '[{this.process_description.final_name}] {line}' ) self.__log_cmd = log_cmd From f93d958636f6536604bb3e7c1b3180ec54fdc3a3 Mon Sep 17 00:00:00 2001 From: Marc Bestmann Date: Tue, 6 Feb 2024 09:41:01 +0100 Subject: [PATCH 5/5] Update launch/launch/actions/execute_local.py Co-authored-by: Tomoya Fujita Signed-off-by: Marc Bestmann --- launch/launch/actions/execute_local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launch/launch/actions/execute_local.py b/launch/launch/actions/execute_local.py index fd92205b4..c737fa205 100644 --- a/launch/launch/actions/execute_local.py +++ b/launch/launch/actions/execute_local.py @@ -89,7 +89,7 @@ def __init__( 'sigkill_timeout', default=5), emulate_tty: bool = False, output: SomeSubstitutionsType = 'log', - output_format: Text = None, + output_format: Optional[Text] = None, cached_output: bool = False, log_cmd: bool = False, on_exit: Optional[Union[