From cdf63326c7370826b0c8233a30bc19b73254cd96 Mon Sep 17 00:00:00 2001 From: Till Maas Date: Feb 25 2020 09:24:55 +0000 Subject: Add doc string for virtual methods --- diff --git a/koji/__init__.py b/koji/__init__.py index 923d8a6..a2b1198 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -2175,6 +2175,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) @@ -2186,6 +2188,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;