File: python3_api.py

package info (click to toggle)
mu-editor 1.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,492 kB
  • sloc: python: 33,326; makefile: 154; xml: 32; sh: 7
file content (68 lines) | stat: -rwxr-xr-x 1,475 bytes parent folder | download
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)