Skip to content
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

Merged
merged 10 commits into from
Apr 1, 2021
Merged

Conversation

evshary
Copy link
Contributor

@evshary evshary commented Oct 6, 2019

According to #347, the PR adds option -v to show more info for topic list.

Copy link
Contributor

@claireyywang claireyywang left a 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.

Comment on lines 57 to 58
if pub_cnt < 1:
continue
Copy link
Contributor

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:

Comment on lines 66 to 67
if sub_cnt < 1:
continue
Copy link
Contributor

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:

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('')
Copy link
Contributor

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('')

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('')
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

@evshary evshary force-pushed the topic_list_verbose branch from 6865078 to 6d7aa20 Compare October 9, 2019 04:40
@evshary evshary requested a review from claireyywang October 10, 2019 13:18
claireyywang
claireyywang previously approved these changes Oct 10, 2019
Copy link
Contributor

@claireyywang claireyywang left a 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.

ros2topic/ros2topic/verb/list.py Outdated Show resolved Hide resolved
ros2topic/ros2topic/verb/list.py Outdated Show resolved Hide resolved
@evshary evshary force-pushed the topic_list_verbose branch from 5deab56 to 2f83aeb Compare October 14, 2019 02:08
@evshary
Copy link
Contributor Author

evshary commented Oct 14, 2019

@claireyywang Thanks for your suggestions. I think it's much more better.


def main(self, *, args):
with NodeStrategy(args) as node:
topic_info = []
with DirectNode(args) as node:
Copy link
Member

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.

Copy link
Contributor Author

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.

@dirk-thomas dirk-thomas added enhancement New feature or request in progress Actively being worked on (Kanban column) requires-changes labels Oct 14, 2019
@evshary evshary force-pushed the topic_list_verbose branch 2 times, most recently from 3f0d386 to 586eb0d Compare October 20, 2019 07:52
@evshary evshary requested a review from dirk-thomas October 21, 2019 10:02
@claireyywang claireyywang dismissed their stale review October 21, 2019 23:05

found error introduced by new change

@claireyywang
Copy link
Contributor

claireyywang commented Oct 21, 2019

@evshary Can you confirm that it works? The new change is giving me error.

Traceback (most recent call last):
  File "/home/claire/ros2_ws/install/ros2cli/bin/ros2", line 11, in <module>
    load_entry_point('ros2cli==0.8.2', 'console_scripts', 'ros2')()
  File "/home/claire/ros2_ws/install/ros2cli/lib/python3.6/site-packages/ros2cli/cli.py", line 69, in main
    rc = extension.main(parser=parser, args=args)
  File "/home/claire/ros2_ws/install/ros2topic/lib/python3.6/site-packages/ros2topic/command/topic.py", line 43, in main
    return extension.main(args=args)
  File "/home/claire/ros2_ws/install/ros2topic/lib/python3.6/site-packages/ros2topic/verb/list.py", line 59, in main
    pub_cnt = node.count_publishers(topic_name)
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1452, in __request
    verbose=self.__verbose
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1154, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1170, in single_request
    return self.parse_response(resp)
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1342, in parse_response
    return u.close()
  File "/usr/lib/python3.6/xmlrpc/client.py", line 656, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: '<class \'Exception\'>:method "count_publishers" is not supported'>

@evshary
Copy link
Contributor Author

evshary commented Oct 22, 2019

@claireyywang You may need to rebuild ros2cli and restart the daemon again.

colcon build --packages-select roscli
ros2 daemon stop
ros2 daemon start

@claireyywang claireyywang self-assigned this Oct 25, 2019
@claireyywang
Copy link
Contributor

@claireyywang You may need to rebuild ros2cli and restart the daemon again.

colcon build --packages-select roscli
ros2 daemon stop
ros2 daemon start

I think that might be a behaviour caused by outdated packages. We recently merged a fix into master that resolved the daemon issue. I have rebased your forked branch with our latest master branch, and will run CI for you. If everything comes back green then it should be good to merge.

@claireyywang
Copy link
Contributor

claireyywang commented Oct 28, 2019

Linux Build Status
Linux-aarch64 Build Status
OSX Build Status
Windows Build Status

@nuclearsandwich
Copy link
Member

I've re-triggered the Windows CI job as the one above had stalled

Build Status

@claireyywang
Copy link
Contributor

Update: process seems to be hanging on windows CI machines. Investigating...

@nuclearsandwich
Copy link
Member

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.

@claireyywang
Copy link
Contributor

I've been running windows CI every day last week without explicitly posting here as part of investigation, but the process always hung. Here's another rerun
Build Status

@nuclearsandwich
Copy link
Member

I've been running windows CI every day last week without explicitly posting here as part of investigation, but the process always hung. Here's another rerun

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 Build Status which tests this PR against ros2/rclpy#456.

@evshary
Copy link
Contributor Author

evshary commented Dec 15, 2019

Since the PR seems to conflict with #420, I've rebased the branch to latest master.

@claireyywang
Copy link
Contributor

claireyywang commented Dec 30, 2019

here we go again
Linux Build Status
Linux-aarch64 Build Status
OSX Build Status
Windows Build Status

@claireyywang
Copy link
Contributor

@nuclearsandwich Are all the SIGINTs in windows CI supposed to terminate the process hang before?

evshary and others added 4 commits March 12, 2021 08:25
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]>
@audrow audrow force-pushed the topic_list_verbose branch from 30987f4 to b61a605 Compare March 12, 2021 16:55
@audrow
Copy link
Member

audrow commented Mar 12, 2021

I rebased and tested on my machine - here's another run of CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Copy link
Member

@audrow audrow left a comment

Choose a reason for hiding this comment

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

@evshary, this is a nice feature - thanks for the PR! Could you

  • fix the linter warnings, found in CI,
  • and add some tests for this feature? You can see similar tests around here.

Let me know if you need any help with these, and feel free to re-request a review from me once you've made these changes.

Signed-off-by: ChenYing Kuo <[email protected]>
@evshary evshary force-pushed the topic_list_verbose branch from a652693 to a4c438b Compare March 19, 2021 12:37
@evshary
Copy link
Contributor Author

evshary commented Mar 19, 2021

@audrow I guess I need some help on adding tests to this feature.
It seems like I need to parse the output of ros2 topic list -v and check whether it's correct or not.
However, I'm not really sure how to run the test and see what the output should be.
The only way I know to run the test is colcon test --packages-select ros2topic, but it takes time and I can't see the specific test output.
Could you give me some suggestions about how to write and run the test more simply?

@audrow
Copy link
Member

audrow commented Mar 19, 2021

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.

@clalancette
Copy link
Contributor

The only way I know to run the test is colcon test --packages-select ros2topic, but it takes time and I can't see the specific test output.
Could you give me some suggestions about how to write and run the test more simply?

The tests are run through pytest, and colcon supports --pytest-args. So you should be able to do something like:

colcon test --event-handlers console_direct+ --packages-select ros2topic --pytest-args -k copyright

Which will only run the copyright test.

@evshary
Copy link
Contributor Author

evshary commented Mar 20, 2021

colcon test --event-handlers console_direct+ --packages-select ros2topic --pytest-args -k copyright

Which will only run the copyright test.

It works like a charm! Thank you @clalancette and @audrow .
@audrow I've added the test item now. Please help me to check whether it's ok or not.

@evshary evshary requested a review from audrow March 20, 2021 02:58
Copy link
Collaborator

@fujitatomoya fujitatomoya left a 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.

ros2topic/ros2topic/verb/list.py Outdated Show resolved Hide resolved
@fujitatomoya
Copy link
Collaborator

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@fujitatomoya
Copy link
Collaborator

@audrow @clalancette CI green, i think it is okay to go in. could you do me a favor?

Copy link
Member

@audrow audrow left a 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 Show resolved Hide resolved
@@ -18,6 +18,18 @@
from ros2topic.verb import VerbExtension


def show_topic_info(topic_info, isPub):
Copy link
Member

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 do is_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 write count.
  • 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.

Copy link
Contributor Author

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 Show resolved Hide resolved
ros2topic/ros2topic/verb/list.py Outdated Show resolved Hide resolved
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))
Copy link
Member

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.

Copy link
Contributor Author

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:
....

Copy link
Contributor Author

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?

Copy link
Member

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 Show resolved Hide resolved
Comment on lines 49 to 51
parser.add_argument(
'-v', '--verbose', action='store_true',
help='list full details about each topic')
Copy link
Member

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.

Copy link
Contributor Author

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.

@audrow
Copy link
Member

audrow commented Mar 22, 2021

@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.

evshary added 2 commits March 23, 2021 19:01
Signed-off-by: ChenYing Kuo <[email protected]>
Signed-off-by: ChenYing Kuo <[email protected]>
@audrow
Copy link
Member

audrow commented Mar 26, 2021

@evshary, is this ready for another review?

@evshary
Copy link
Contributor Author

evshary commented Mar 27, 2021

@evshary, is this ready for another review?

Sure. Please let me know if there's anything which can be improved.

@evshary evshary requested a review from audrow March 27, 2021 00:58
Copy link
Member

@audrow audrow left a 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.

@audrow
Copy link
Member

audrow commented Mar 30, 2021

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@audrow
Copy link
Member

audrow commented Apr 1, 2021

Windows CI warning is from Cyclone. Merging this.

@audrow audrow merged commit d03ee6c into ros2:master Apr 1, 2021
@audrow
Copy link
Member

audrow commented Apr 1, 2021

Thanks for the PR, @evshary!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in progress Actively being worked on (Kanban column) requires-changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants