forked from M-Labs/artiq
1
0
Fork 0

artiq_rpctool: use inspect.formatargspec instead of a NIH formatter.

Fixes #1029.
This commit is contained in:
whitequark 2018-06-01 19:16:26 +00:00
parent f1a80f12f8
commit 985fd7377b
1 changed files with 2 additions and 27 deletions

View File

@ -6,6 +6,7 @@ import sys
import traceback import traceback
import numpy as np # Needed to use numpy in RPC call arguments on cmd line import numpy as np # Needed to use numpy in RPC call arguments on cmd line
import pprint import pprint
import inspect
from artiq.protocols.pc_rpc import AutoTarget, Client from artiq.protocols.pc_rpc import AutoTarget, Client
@ -46,33 +47,7 @@ def list_methods(remote):
print(doc["docstring"]) print(doc["docstring"])
print() print()
for name, (argspec, docstring) in sorted(doc["methods"].items()): for name, (argspec, docstring) in sorted(doc["methods"].items()):
args = "" print(name + inspect.formatargspec(**argspec))
for arg in argspec["args"]:
args += arg
if argspec["defaults"] is not None:
kword_index = len(argspec["defaults"]) - len(argspec["args"])\
+ argspec["args"].index(arg)
if kword_index >= 0:
if argspec["defaults"][kword_index] == Ellipsis:
args += "=..."
else:
args += "={}".format(argspec["defaults"][kword_index])
if argspec["args"].index(arg) < len(argspec["args"]) - 1:
args += ", "
if argspec["varargs"] is not None:
args += ", *{}".format(argspec["varargs"])
elif len(argspec["kwonlyargs"]) > 0:
args += ", *"
for kwonlyarg in argspec["kwonlyargs"]:
args += ", {}".format(kwonlyarg)
if kwonlyarg in argspec["kwonlydefaults"]:
if argspec["kwonlydefaults"][kwonlyarg] == Ellipsis:
args += "=..."
else:
args += "={}".format(argspec["kwonlydefaults"][kwonlyarg])
if argspec["varkw"] is not None:
args += ", **{}".format(argspec["varkw"])
print("{}({})".format(name, args))
if docstring is not None: if docstring is not None:
print(textwrap.indent(docstring, " ")) print(textwrap.indent(docstring, " "))
print() print()