1
|
#!/usr/bin/env python
|
2
|
|
3
|
import inspect
|
4
|
|
5
|
from arvados.api import api_client, api_kwargs_from_config
|
6
|
|
7
|
MOD_NAME = 'arvados.api_resources'
|
8
|
|
9
|
def document_callable(decl, name, value=None, indent=None, doc=None):
|
10
|
if value is None:
|
11
|
signature = '()'
|
12
|
else:
|
13
|
signature = inspect.signature(value)
|
14
|
if indent is None:
|
15
|
indent = 0 if decl == 'class' else 1
|
16
|
if doc is None and value is not None:
|
17
|
doc = getattr(value, '__doc__', None)
|
18
|
prefix = ' ' * indent
|
19
|
if doc is None:
|
20
|
out_s = f"""
|
21
|
{prefix}{decl} {name}{signature}:
|
22
|
{prefix} ...
|
23
|
"""
|
24
|
else:
|
25
|
out_s = f"""
|
26
|
{prefix}{decl} {name}{signature}:
|
27
|
{prefix} {doc!r}
|
28
|
{prefix} ...
|
29
|
"""
|
30
|
print(out_s)
|
31
|
|
32
|
arv_kwargs = api_kwargs_from_config('v1')
|
33
|
arv_client = api_client(**arv_kwargs)
|
34
|
|
35
|
resources_to_document = {}
|
36
|
document_callable('class', 'ArvadosAPIClient')
|
37
|
for attr_name in sorted(dir(arv_client)):
|
38
|
attr_value = getattr(arv_client, attr_name)
|
39
|
if attr_name.startswith('_'):
|
40
|
pass
|
41
|
elif callable(attr_value):
|
42
|
if attr_value.__name__ == 'methodResource':
|
43
|
returned_classname = attr_name.title().replace('_', '')
|
44
|
resources_to_document[returned_classname] = attr_value()
|
45
|
doc = f"Return a `{MOD_NAME}.{returned_classname}` instance with associated API methods."
|
46
|
else:
|
47
|
doc = None
|
48
|
document_callable('def', attr_name, attr_value, doc=doc)
|
49
|
|
50
|
for cls_name, cls in resources_to_document.items():
|
51
|
document_callable('class', cls_name)
|
52
|
for attr_name in sorted(dir(cls)):
|
53
|
attr_value = getattr(cls, attr_name)
|
54
|
if attr_name.startswith('_'):
|
55
|
pass
|
56
|
elif callable(attr_value):
|
57
|
document_callable('def', attr_name, attr_value)
|