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 66 67 68
|
#!/usr/bin/env python3
"""
Given a list of modules, extracts the help into a json file to be turned into
an API list for Mu.
"""
import json
import inspect
import importlib
modules = [
"random",
"sys",
"os",
"json",
"socket",
"datetime",
"collections",
"datetime",
"array",
"itertools",
"functools",
"os.path",
"csv",
"time",
"argparse",
"base64",
"hashlib",
"uuid",
"turtle",
]
api = []
for module in modules:
m = importlib.import_module(module)
content = [attr for attr in dir(m) if not attr.startswith("_")]
# Work out what each member of the module is.
for attr in content:
obj = getattr(m, attr)
name = ""
try:
name = obj.__name__
except Exception as ex:
print(ex)
print(obj)
try:
args = [
a.replace("(", "").replace(")", "")
for a in str(inspect.signature(obj)).split(", ")
]
except Exception as ex:
print(ex)
print(obj)
args = None
description = inspect.getdoc(obj)
if name and description:
api.append(
{
"name": module + "." + name,
"args": args,
"description": description,
}
)
with open("python_api.json", "w") as output:
json.dump(api, output, indent=2)
|