Created public get_topic_list() function for use in other scripts.#1154
Created public get_topic_list() function for use in other scripts.#1154mikepurvis merged 3 commits intoros:lunar-develfrom
Conversation
dirk-thomas
left a comment
There was a problem hiding this comment.
publishers, subscribers = rostopic.get_topic_list()
for topic, type, node_count in publishers:
The usage seems to be wrong. As far as I can see the code returns a list of publishers as the third element - not a count?
| topic_ns = rosgraph.names.make_global_ns(topic) | ||
| subs = (x for x in subs if x[0] == topic or x[0].startswith(topic_ns)) | ||
| pubs = (x for x in pubs if x[0] == topic or x[0].startswith(topic_ns)) | ||
| pubs, subs = get_topic_list() |
There was a problem hiding this comment.
Why is the filtering by the optional topic not needed here anymore?
tools/rostopic/test/test_rostopic.py
Outdated
| # test through public function | ||
| topics = ['/chatter', '/foo/chatter', '/bar/chatter', '/rosout', '/rosout_agg'] | ||
|
|
||
| with fakestdout() as b: |
There was a problem hiding this comment.
This shouldn't be necessary?
| topics.sort() | ||
| print('\n'.join(["%s%s"%(indent, t) for t in topics])) | ||
|
|
||
| def get_topic_list(): |
There was a problem hiding this comment.
It might be good to pass in the master since each caller already has a master variable.
| if not subscribers_only: | ||
| print("\n%sPublished topics:"%indent) | ||
| for t, l in pubs: | ||
| for t, y, l in pubs: |
There was a problem hiding this comment.
Please use a different variable name than y.
Same below.
| else: | ||
| if publishers_only: | ||
| topics = [t for t,_ in pubs] | ||
| topics = [t for t,_,_ in pubs] |
There was a problem hiding this comment.
Please add a space after each comma (PEP 8).
Same below.
There was a problem hiding this comment.
This comment is still pending.
There was a problem hiding this comment.
This comment is still pending.
|
@dirk-thomas Commits have been made resolving the issues you pushed, and the outdated usage example in the description has been fixed. |
dirk-thomas
left a comment
There was a problem hiding this comment.
While new / modified lines should follow PEP8 unchanged lines shouldn't be changed since that makes backporting changes to other branch much more difficult. Please revert any unrelated / unnecessary (whitespace) change in your patch.
| topic_ns = rosgraph.names.make_global_ns(topic) | ||
| subs = (x for x in subs if x[0] == topic or x[0].startswith(topic_ns)) | ||
| pubs, subs = get_topic_list(master=master) | ||
| if topic is not None: |
There was a problem hiding this comment.
Why was this condition changed from if topic to if topic is not None?
| topic_ns = rosgraph.names.make_global_ns(topic) | ||
| pubs = (x for x in pubs if x[0] == topic or x[0].startswith(topic_ns)) | ||
|
|
||
| subs = (x for x in subs if x[0] == topic or x[0].startswith(topic_ns)) |
There was a problem hiding this comment.
Please do not change the order of lines for no reason.
d511ea8 to
ab8fa1d
Compare
|
@dirk-thomas Sorry for the delay, I edited some of the commented lines. Please review these changes and provide feedback. |
|
@mikepurvis Did you just push a commit with my changes in it rather than merging my pull request with the base branch? |
|
@mastereric Yes, (Others are welcome to build from edge as well; we're the only current consumer that I'm directly aware of.) |
|
I've backed this PR out of our testing. Please see the regression below: |
|
@mikepurvis Fixed the error you're getting, a test looks fine on my machine |
|
Hey @mikepurvis, |
| topics.sort() | ||
| print('\n'.join(["%s%s"%(indent, t) for t in topics])) | ||
|
|
||
| def get_topic_list(master=rosgraph.Master('/rostopic')): |
There was a problem hiding this comment.
I actually ran into a small issue with this just today— it's a bit of a corner case, but when ROS_MASTER_URI isn't set, this bombs out on import, for example:
$ unset ROS_MASTER_URI
administrator@vm-mpurvis-xenial-ws:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rostopic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "workspace/lib/python2.7/dist-packages/rostopic/__init__.py", line 1152, in <module>
def get_topic_list(master=rosgraph.Master('/rostopic')):
File "workspace/lib/python2.7/dist-packages/rosgraph/masterapi.py", line 100, in __init__
self._reinit(master_uri)
File "workspace/lib/python2.7/dist-packages/rosgraph/masterapi.py", line 113, in _reinit
raise ValueError("ROS master URI is not set")
ValueError: ROS master URI is not set
>>>
I believe this will be corrected if you instead do:
def get_topic_list(master=None):
if not master:
master = rosgraph.Master('/rostopic')
Other than this, I'd be happy to merge this to mainline.
There was a problem hiding this comment.
Thanks for the fix. Please also address the style concern from @dirk-thomas and then this is good to go in.
|
@mikepurvis I am apparently blind and didn't notice the leftover spacing fix had yet to be done. The fix has been pushed for review. |
This comment still applies. |
ddd069c to
f7b683a
Compare
|
@dirk-thomas Sorry for making that mistake again, after my current PRs are done I'll look into making separate PEP8 pull requests for this and other repositories. |
|
My previous comment still applies. See the diff should not touch any line just for style adjustments. If the line isn't being changed fo a functional reason in this patch please avoid the change to keep this patch minimal.
For newly added code we aim to follow common style guides. But don't want to reformat existing code because this repository has currently three (soon four) actively maintained branches and a code reformatting patch would severely hinder the ability to backport changes to other branch. |
f7b683a to
a361328
Compare
a361328 to
30fc379
Compare
|
@dirk-thomas I have double-checked with the diff and ensured the changes are as requested. If you have any other issues please cite specific line numbers. |
|
@dirk-thomas It has been one week since I pushed these changes. Can you please review and approve them? I would like for them to be approved before the Melodic release. |
|
Please fix the remaining PEP8 issues (spacing around commas). |
04305a3 to
fb01aca
Compare
|
Looks great, thanks for this contribution— going to merge into |
|
The failing test on Melodic/debian is unrelated to this change (see #1358) |
| print(indent+" * %s [%s] %s subscribers"%(t, topic_type(t, topic_types), len(l))) | ||
| for t, ttype, tlist in subs: | ||
| if len(tlist) > 1: | ||
| print(indent+" * %s [%s] %s subscribers"%(t, ttype, len(llist))) |
There was a problem hiding this comment.
llist doesn't exist in this context. See #1407 for a follow up patch.
A third pull request since #1146 required changes and #1151 was based on kinetic-devel. I would have reopened #1146 but I broke it or something.
Resolves issue #946.
The only function in rostopic for listing the available topics is built exclusively for the command line interface; this adds a public function for other applications that want a list of topics.
Usage: