-
Notifications
You must be signed in to change notification settings - Fork 170
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 verbose info for topic list #351
Conversation
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.
Happy Hacktoberfest and thanks for submitting this PR! I would recommend using a function to handle the string formatting part, since publisher
and subscriber
use very similar lines to structure the print statement. The following are a few nitpicks.
ros2topic/ros2topic/verb/list.py
Outdated
if pub_cnt < 1: | ||
continue |
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 would suggest if pub_cnt:
ros2topic/ros2topic/verb/list.py
Outdated
if sub_cnt < 1: | ||
continue |
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.
same as above, if sub_cnt:
ros2topic/ros2topic/verb/list.py
Outdated
cnt_str = str(pub_cnt) + ' publisher' + ('s' if pub_cnt > 1 else '') | ||
msg = ' * {topic_name} [{topic_types_formatted}] {cnt_str}' | ||
print(msg.format_map(locals())) | ||
print('') |
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.
You can probably add new line to the string format than use print('')
ros2topic/ros2topic/verb/list.py
Outdated
cnt_str = str(sub_cnt) + ' subscriber' + ('s' if sub_cnt > 1 else '') | ||
msg = ' * {topic_name} [{topic_types_formatted}] {cnt_str}' | ||
print(msg.format_map(locals())) | ||
print('') |
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.
same as above
6865078
to
6d7aa20
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.
Thanks for following up! Looks good to me with green CI. I will run CI for you once a few nitpicks are adjusted.
5deab56
to
2f83aeb
Compare
@claireyywang Thanks for your suggestions. I think it's much more better. |
ros2topic/ros2topic/verb/list.py
Outdated
|
||
def main(self, *, args): | ||
with NodeStrategy(args) as node: | ||
topic_info = [] | ||
with DirectNode(args) as node: |
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.
Using aDirectNode
here instead of a NodeStrategy
will not use the darlin and therefore result in either a longer time to wait for discovery or incomplete information. So please using the NodeStrategy
here.
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 use NodeStrategy
instead now. However, I need to register count_publishers
and count_subscribers
to use these functions, so I also modified the daemon.
3f0d386
to
586eb0d
Compare
found error introduced by new change
@evshary Can you confirm that it works? The new change is giving me error.
|
@claireyywang You may need to rebuild ros2cli and restart the daemon again.
|
586eb0d
to
2c848ef
Compare
I think that might be a behaviour caused by outdated packages. We recently merged a fix into |
Update: process seems to be hanging on windows CI machines. Investigating... |
The hang is likely related to ros2/build_farmer#248. The hang has so far not been 100% reproducible so re-running CI is also an option. |
While this is a bummer for this PR. I'm a little excited because this might increase the likelihood of the hang in my attempts to reproduce. I've triggered which tests this PR against ros2/rclpy#456. |
2c848ef
to
22d5a3c
Compare
Since the PR seems to conflict with #420, I've rebased the branch to latest master. |
@nuclearsandwich Are all the |
Signed-off-by: evshary <[email protected]>
Co-Authored-By: Claire Wang <[email protected]> Signed-off-by: evshary <[email protected]>
Co-Authored-By: Claire Wang <[email protected]> Signed-off-by: evshary <[email protected]>
We also need to register functions for NodeStrategy: count_publishers and count_subscribers. Signed-off-by: evshary <[email protected]>
30987f4
to
b61a605
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: ChenYing Kuo <[email protected]>
a652693
to
a4c438b
Compare
@audrow I guess I need some help on adding tests to this feature. |
I'm not sure of the best way to run the tests. One thing that I've been doing lately is to create a Python file (can be outside of the package) that imports what is needed and runs what you want to test so that you can inspect it (this doesn't necessarily need tests, I often just use functions with assert statements). I've been doing this after sourcing my ROS 2 workspace. Then once it seems to be working, I move the code into the package's test files and run them with Colcon, as you're doing now. Hopefully this helps. |
The tests are run through pytest, and colcon supports
Which will only run the copyright test. |
Signed-off-by: ChenYing Kuo <[email protected]>
It works like a charm! Thank you @clalancette and @audrow . |
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.
lgtm with minor comment.
@audrow @clalancette CI green, i think it is okay to go in. could you do me a favor? |
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.
The test looks good. Now that I'm looking more closely at the code, I think it would be good to do some restructuring.
One possibility would be do something like the following:
for (topic_name, topic_types) in topic_names_and_types:
msg = f'{topic_name}'
topic_types_formatted = ', '.join(topic_types) # I think this can be moved into the next if statement
if args.show_types or args.verbose:
msg += f' [{topic_types_formatted}]'
if args.show_publishers or args.verbose:
msg += get_topic_publishers_list(topic_types)
if args.show_publishers or args.verbose:
msg += get_topic_subscriptions_list(topic_types)
print(msg)
Where get_topic_publishers_list
and get_topic_subscriptions_list
are quite similar to your show_topic_info
(maybe both using a common function).
What do you think @fujitatomoya?
ros2topic/ros2topic/verb/list.py
Outdated
@@ -18,6 +18,18 @@ | |||
from ros2topic.verb import VerbExtension | |||
|
|||
|
|||
def show_topic_info(topic_info, isPub): |
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.
A few nitpicks
isPub
isn't really Pythonic. Could you dois_publisher
instead? Although, maybe there's a better way to structure this as "subscription" isn't really the opposite of "publisher", as anything else would not be a publisher.- I prefer longer names, as I find it much more readable. For example, rather than using
cnt
, you can just writecount
. - I think this function should go to the bottom of the file, rather than be at the top. You could also make it a static method of the
ListVerb
class.
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 agree with you.
ros2topic/ros2topic/verb/list.py
Outdated
for (topic_name, topic_types) in topic_names_and_types: | ||
pub_cnt = node.count_publishers(topic_name) | ||
sub_cnt = node.count_subscribers(topic_name) | ||
topic_info.append((topic_name, topic_types, pub_cnt, sub_cnt)) |
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.
To me, having a list of tuples with four elements isn't desirable. In topic_names_and_types
, there are two and they're right there in the variable name. Maybe there is a better way to do this. Perhaps, just compute them as you need them in the show_topic_info
function.
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.
Why I compute them here is that I need the NodeStrategy. I'm not sure how to pass NodeStrategy to show_topic_info is a better way.
def show_topic_info(args, topic_info, isPub):
with NodeStrategy(args) as node:
....
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.
@audrow I add the if-condition to avoid running count_publishers and count_subscribers while there is no verbose. I'm not sure whether it's a better way, but I try to avoid pass args into another function just for with NodeStrategy(args) as node
.
What do you think about it?
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.
Sounds good.
ros2topic/ros2topic/verb/list.py
Outdated
parser.add_argument( | ||
'-v', '--verbose', action='store_true', | ||
help='list full details about each topic') |
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.
Perhaps the command should change to something like --show-connections
(maybe there's a better name) or be broken into --show-subscriptions
and --show-publishers
. You could also have a --verbose
command that enables everything, but it would be nice to have the ability to enable things individually.
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 prefer to add this feature in another PR.
@evshary, I wrote comments as I was reviewing things before coming to the opinion that it would be good to do some restructuring. They should be good anyways to see the kinds of things I'm looking for, e.g., consistent styling. Let me know if you have any questions or need any help. |
Signed-off-by: ChenYing Kuo <[email protected]>
Signed-off-by: ChenYing Kuo <[email protected]>
@evshary, is this ready for another review? |
Sure. Please let me know if there's anything which can be improved. |
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.
Looks okay to me, I'll rerun CI.
Windows CI warning is from Cyclone. Merging this. |
Thanks for the PR, @evshary! |
According to #347, the PR adds option
-v
to show more info for topic list.