Spaces:
Running
Running
File size: 1,703 Bytes
98caf15 c4a3947 98caf15 02673b4 98caf15 |
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 |
# bpydoc.py
import pickle
from fastapi import APIRouter
router = APIRouter()
with open("routers/tool_bpy_doc_v4_1.pkl", 'rb') as file:
bpy_doc_map = pickle.load(file)
bpy_doc_map['__info'] = {'bases': None}
def bpy_doc_get_documentation(api):
parts = api.split('.')
api = ""
data = bpy_doc_map
ctx = []
for part in parts:
try:
data = data[part]
api += part
ctx.append((api, data["__info"]['descr']))
api += '.'
except Exception as ex:
descr = f"{type(ex).__name__}: {ex}. Perhaps this object was implemented in a later version."
ctx.append((api, descr))
break
documentation = ""
for obj, descr in ctx:
documentation += f"{obj}:\n"
documentation += f"{descr}\n\n"
if len(data) > 1:
documentation += f"Members of {api}:\n"
info = data["__info"]
if info['bases']:
documentation += f"Inherits from {info['bases']}\n"
for key, val in data.items():
if key != "__info":
descr = ""
if isinstance(val, list):
val = val[0]
descr = "`bpy_prop_collection` of {}".format(
val['__info']["descr"].replace('\n', ' '))
else:
descr = val['__info']["descr"].replace('\n', ' ')
documentation += f"- {key}: {descr}\n"
return documentation
@router.get("/bpy_doc")
def bpy_doc(api: str = ""):
message = bpy_doc_get_documentation(api)
return {"message": message}
if __name__ == "__main__":
test = bpy_doc("bpy.context")
print(test)
|