-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapi_links.py
executable file
·65 lines (49 loc) · 1.85 KB
/
api_links.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
import sys
import inspect
import testflows.core
import testflows.core.name
import testflows.core.exceptions
import testflows.core.objects
import testflows.core.parallel
import testflows.core.utils
import testflows.exceptions
import testflows.settings
import testflows.version
import testflows._core.combinatorics
from testflows._core import __repository__, __commit__
github_root = f"{__repository__.rsplit('.git',1)[0]}/blob/{__commit__}"
def make_link(obj):
"""Make a link to a line of code in the github repository
for a given object.
"""
return f"{github_root}/testflows{inspect.getsourcefile(obj).split('/testflows', 1)[-1]}#L{inspect.getsourcelines(obj)[1]}"
def generate(obj, writer, prefix=""):
"""Generate API links to GitHub code."""
try:
if not inspect.getmodule(obj).__name__.startswith("testflows"):
return
members = inspect.getmembers(obj)
for member in members:
name, obj = member
if name.startswith("_"):
continue
if inspect.isfunction(obj):
writer.write(f"[{prefix}{name}() function]: {make_link(obj)}\n")
if inspect.isclass(obj):
writer.write(f"[{prefix}{name} class]: {make_link(obj)}\n")
generate(obj, prefix=f"{prefix}{name}.", writer=writer)
if inspect.ismethod(obj):
writer.write(f"[{prefix}{name}() method]: {make_link(obj)}\n")
if inspect.isgenerator(obj):
writer.write(f"[{prefix}{name}() generator]: {make_link(obj)}\n")
except BaseException:
pass
# generate API links
writer = sys.stdout
try:
generate(obj=testflows.core, writer=writer)
generate(obj=testflows._core.combinatorics, writer=writer)
generate(obj=testflows.core.name, writer=writer)
finally:
writer.flush()