Skip to content

Commit

Permalink
artiq_rpctool: list-methods also prints class docstring
Browse files Browse the repository at this point in the history
fallen committed Jun 23, 2015
1 parent f0dddd9 commit 71721a1
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 4 additions & 2 deletions artiq/frontend/artiq_rpctool.py
Original file line number Diff line number Diff line change
@@ -36,8 +36,10 @@ def list_targets(target_names, id_parameters):


def list_methods(remote):
methods = remote.get_rpc_method_list()
for name, (argspec, docstring) in sorted(methods.items()):
doc = remote.get_rpc_method_list()
if doc["docstring"] is not None:
print(doc["docstring"])
for name, (argspec, docstring) in sorted(doc["methods"].items()):
args = ""
for arg in argspec["args"]:
args += arg
11 changes: 7 additions & 4 deletions artiq/protocols/pc_rpc.py
Original file line number Diff line number Diff line change
@@ -442,15 +442,18 @@ def _handle_connection_cr(self, reader, writer):
try:
if obj["action"] == "get_rpc_method_list":
members = inspect.getmembers(target, inspect.ismethod)
methods = {}
doc = {
"docstring": target.__doc__,

This comment has been minimized.

Copy link
@sbourdeauducq

sbourdeauducq Jun 23, 2015

Member

There are indentation problems, e.g. try it with the novatech controller.

This comment has been minimized.

Copy link
@sbourdeauducq

sbourdeauducq Jun 23, 2015

Member

This comment has been minimized.

Copy link
@sbourdeauducq

sbourdeauducq Jun 23, 2015

Member

I fixed it. Is there any reason why you did not use inspect.getdoc as below?

"methods": {}
}
for name, method in members:
if name.startswith("_"):
continue
method = getattr(target, name)
argspec = inspect.getfullargspec(method)
methods[name] = (dict(argspec.__dict__),
inspect.getdoc(method))
obj = {"status": "ok", "ret": methods}
doc["methods"][name] = (dict(argspec.__dict__),
inspect.getdoc(method))
obj = {"status": "ok", "ret": doc}
elif obj["action"] == "call":
logger.debug("calling %s", _PrettyPrintCall(obj))
method = getattr(target, obj["name"])

0 comments on commit 71721a1

Please sign in to comment.