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
|
#!/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 = ['screen', 'music', 'keyboard', 'clock', 'animation', 'actor', ]
api = []
for module in modules:
m = importlib.import_module('pgzero.{}'.format(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(obj)
print(ex)
try:
args = [a.replace('(', '').replace(')', '') for a in
str(inspect.signature(obj)).split(', ')]
except Exception as ex:
print(obj)
print(ex)
args = None
description = inspect.getdoc(obj)
if name and description:
api.append({
'name': module + '.' + name,
'args': args,
'description': description,
})
with open('pgzero_api.json', 'w') as output:
json.dump(api, output, indent=2)
|