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
Add filtering mechanism for executable prefix application #522
Add filtering mechanism for executable prefix application #522
Conversation
…utables Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
ad4dc2c
to
1be7845
Compare
Signed-off-by: Cameron Miller <cammlle@amazon.com>
1be7845
to
7177e69
Compare
filter_str = perform_substitutions(context, self.__prefix_filter) | ||
regex_filter = None | ||
if len(filter_str): | ||
regex_filter = re.compile(filter_str) | ||
if regex_filter is not None and regex_filter.match(os.path.basename(cmd[0])): | ||
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd | ||
|
||
# Apply to all if no filter is provided or filter is overridden | ||
if regex_filter is None or self.__override_filter: | ||
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@camm73 meta: hmm, if I read this correctly the prefix filter is irrelevant when a prefix is explicitly given. Nevermind the potential code simplification, that's actually a bit counter-intuitive when attempting to target an specific executable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking behind this was based on the fact that whenever a user sets a specific prefix in their launch file it currently overrides any launch-prefix
provided in the launch configuration and applies the specific prefix:
launch/launch/launch/actions/execute_process.py
Lines 230 to 232 in f891aed
self.__prefix = normalize_to_list_of_substitutions( | |
LaunchConfiguration('launch-prefix', default='') if prefix is None else prefix | |
) |
Since the specific prefix already overrides a prefix passed via --launch-prefix
, I figured it should also do the same when --launch-prefix
and --launch-prefix-filter
are used in conjunction, for the sake of consistency.
If you think it's more intuitive to remove the override_filter
feature though, I can definitely do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured it should also do the same when --launch-prefix and --launch-prefix-filter are used in conjunction, for the sake of consistency.
That's fair. Should be fine so long as we document it.
If you think it's more intuitive to remove the override_filter feature though, I can definitely do that.
Not so much removing the feature. My naive (and wrong) expectation coming into launch
could be that ros2 launch --launch-prefix-filter some_executable --launch-prefix gdb --args
takes precedence for some_executable
over whatever was specified as prefix. So long as we document this is NOT the case, it'll be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, let's document this behavior in ExecuteProcess.__init__()
docstring.
filter_str = perform_substitutions(context, self.__prefix_filter) | ||
regex_filter = None | ||
if len(filter_str): | ||
regex_filter = re.compile(filter_str) | ||
if regex_filter is not None and regex_filter.match(os.path.basename(cmd[0])): | ||
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd | ||
|
||
# Apply to all if no filter is provided or filter is overridden | ||
if regex_filter is None or self.__override_filter: | ||
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, let's document this behavior in ExecuteProcess.__init__()
docstring.
Co-authored-by: Michel Hidalgo <michel@ekumenlabs.com> Signed-off-by: Cameron Miller <cammlle@amazon.com>
Co-authored-by: Michel Hidalgo <michel@ekumenlabs.com> Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
a23f33c
to
9db2e8d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Alright, going in! |
In order to support the
--launch-prefix-filter
argument proposed in ros2/launch_ros#257, the regex filter supplied via thelaunch-prefix-filter
LaunchConfiguration must be matched against the executable name. In the case of a match, the prefix passed via thelaunch-prefix
LaunchConfiguration is prepended to the executable command. If a match is not found, the prefix is not applied.Additionally, if the user provides a specific prefix for an executable in the launch file, the filter will be overridden and the prefix will be applied as expected.
Corresponding PR: ros2/launch_ros#261 will implement the
--launch-prefix-filter
argument intolaunch_ros
.