From 8c2c7ee5ad9ea9a53d0618f522b730c6a147c5ba Mon Sep 17 00:00:00 2001 From: Till Maas Date: May 07 2018 17:36:43 +0000 Subject: Add doc string for virtual methods --- diff --git a/koji/__init__.py b/koji/__init__.py index 9d44488..1862f07 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -2002,6 +2002,8 @@ def is_conn_error(e): class VirtualMethod(object): + # cache for api documentation + _apidoc = None # some magic to bind an XML-RPC method to an RPC server. # supports "nested" methods (e.g. examples.getStateName) # supports named arguments (if server does) @@ -2013,6 +2015,31 @@ class VirtualMethod(object): def __call__(self, *args, **opts): return self.__func(self.__name, args, opts) + @property + def __doc__(self): + # try to fetch API docs + if VirtualMethod._apidoc is None: + try: + VirtualMethod._apidoc = dict( + [(f["name"], f) for f in self.__func("_listapi", [], {})] + ) + except: + VirtualMethod._apidoc = {} + + funcdoc = VirtualMethod._apidoc.get(self.__name) + if funcdoc: + # add argument description to docstring since the + # call signature is not updated, yet + argdesc = funcdoc["name"] + funcdoc["argdesc"] + "\n" + doc = funcdoc["doc"] + if doc: + return argdesc + doc + else: + return argdesc + else: + return None + + def grab_session_options(options): """Convert optparse options to a dict that ClientSession can handle;