Beispiel #1
0
def main():
    import rna_info
    struct = rna_info.BuildRNAInfo()[0]
    data = []
    for struct_id, v in sorted(struct.items()):
        struct_id_str = v.identifier  # "".join(sid for sid in struct_id if struct_id)

        for base in v.get_bases():
            struct_id_str = base.identifier + "|" + struct_id_str

        props = [(prop.identifier, prop) for prop in v.properties]
        for prop_id, prop in sorted(props):
            # if prop.type == "boolean":
            #     continue
            prop_type = prop.type
            if prop.array_length > 0:
                prop_type += "[%d]" % prop.array_length

            data.append(
                "%s.%s -> %s:    %s%s    %s" %
                (struct_id_str, prop.identifier, prop.identifier, prop_type,
                 ", (read-only)" if prop.is_readonly else "",
                 prop.description))
        data.sort()

    if bpy.app.background:
        import sys
        sys.stderr.write("\n".join(data))
        sys.stderr.write("\n\nEOF\n")
    else:
        text = bpy.data.texts.new(name="api.py")
        text.from_string(data)
Beispiel #2
0
    def rna_ids():
        import rna_info
        struct = rna_info.BuildRNAInfo()[0]
        for struct_id, v in sorted(struct.items()):
            props = [(prop.identifier, prop) for prop in v.properties]
            struct_path = "bpy.types.%s" % struct_id[1]
            for prop_id, prop in props:
                yield (struct_path, "%s.%s" % (struct_path, prop_id))

        for submod_id in dir(bpy.ops):
            op_path = "bpy.ops.%s" % submod_id
            for op_id in dir(getattr(bpy.ops, submod_id)):
                yield (op_path, "%s.%s" % (op_path, op_id))
Beispiel #3
0
def check_duplicates():
    import rna_info

    DUPLICATE_IGNORE_FOUND = set()
    DUPLICATE_WHITELIST_FOUND = set()

    structs, funcs, ops, props = rna_info.BuildRNAInfo()

    # This is mainly useful for operators,
    # other types have too many false positives

    # for t in (structs, funcs, ops, props):
    for t in (ops, ):
        description_dict = {}
        print("")
        for k, v in t.items():
            if v.description not in DUPLICATE_IGNORE:
                id_str = ".".join([
                    s if isinstance(s, str) else s.identifier for s in k if s
                ])
                description_dict.setdefault(v.description, []).append(id_str)
            else:
                DUPLICATE_IGNORE_FOUND.add(v.description)
        # sort for easier viewing
        sort_ls = [(tuple(sorted(v)), k) for k, v in description_dict.items()]
        sort_ls.sort()

        for v, k in sort_ls:
            if len(v) > 1:
                if v not in DUPLICATE_WHITELIST:
                    print("found %d: %r, \"%s\"" % (len(v), v, k))
                    #print("%r," % (v,))
                else:
                    DUPLICATE_WHITELIST_FOUND.add(v)

    test = (DUPLICATE_IGNORE - DUPLICATE_IGNORE_FOUND)
    if test:
        print("Invalid 'DUPLICATE_IGNORE': %r" % test)
    test = (set(DUPLICATE_WHITELIST) - DUPLICATE_WHITELIST_FOUND)
    if test:
        print("Invalid 'DUPLICATE_WHITELIST': %r" % test)
def bpy2predef(BASEPATH, title):
    ''' Creates the bpy.predef file. It contains the bpy.dta, bpy.ops, bpy.types
        Arguments:
        BASEPATH (string): path for the output file
        title(string): descriptive title (the comment for the whole module)
    '''
    def property2predef(ident, fw, module, name):
        ''' writes definition of a named property
            Details:
            @ident (string): the required prefix (spaces)
            @fw (function): the unified shortcut to print() or file.write() function
            @module (string): one of bpy.ops names ("actions", for example)
            @name (string): name of the property
        '''
        value = getattr(module, name, None)
        if value:
            value_type = getattr(value, "rna_type", None)
            if value_type:
                fw("{0} = types.{1}\n".format(name, value_type.identifier))
            else:
                pyclass2predef(fw, modulr, name, value)
        fw("\n\n")

    #read all data:
    structs, funcs, ops, props = rna_info.BuildRNAInfo()
    #open the file:
    filepath = os.path.join(BASEPATH, "bpy.py")
    file = open(filepath, "w")
    fw = file.write
    #Start the file:
    definition = doc2definition(title,"") #skip the leading spaces at the first line...
    fw(definition["docstring"])
    fw("\n\n")

    #group operators by modules: (dictionary of list of the operators)
    op_modules = {}
    for op in ops.values():
        op_modules.setdefault(op.module_name, []).append(op)

    #Special declaration of non-existing structiure just fo the ops member:
    fw("class ops:\n")
    fw(_IDENT+"'''Spcecial class, created just to reflect content of bpy.ops'''\n\n")
    for op_module_name, ops_mod in sorted(op_modules.items(),key = lambda m : m[0]):
        if op_module_name == "import":
            continue
        ops_struct2predef(_IDENT, fw, op_module_name, ops_mod)

    #classes (Blender structures:)
    fw("class types:\n")
    fw(_IDENT+"'''A container for all Blender types'''\n" + _IDENT + "\n")

    #base structure
    bpy_base2predef(_IDENT, fw)

    #sort the type names:
    classes = list(structs.values())
    classes.sort(key=lambda cls: cls.identifier)

    for cls in classes:
        # skip the operators!
        if "_OT_" not in cls.identifier:
            rna_struct2predef(_IDENT, fw, cls)

    #the data members:
    property2predef("", fw, bpy, "context")

    property2predef("", fw, bpy, "data")

    file.close()
Beispiel #5
0
def api_dump(args):
    import rna_info
    import inspect

    version, version_key = api_version()
    if version is None:
        raise(ValueError("API dumps can only be generated from within Blender."))

    dump = {}
    dump_module = dump["bpy.types"] = {}

    struct = rna_info.BuildRNAInfo()[0]
    for struct_id, struct_info in sorted(struct.items()):

        struct_id_str = struct_info.identifier

        if rna_info.rna_id_ignore(struct_id_str):
            continue

        for base in struct_info.get_bases():
            struct_id_str = base.identifier + "." + struct_id_str

        dump_class = dump_module[struct_id_str] = {}

        props = [(prop.identifier, prop) for prop in struct_info.properties]
        for prop_id, prop in sorted(props):
            # if prop.type == 'boolean':
            #     continue
            prop_type = prop.type
            prop_length = prop.array_length
            prop_range = round(prop.min, 4), round(prop.max, 4)
            prop_default = prop.default
            if type(prop_default) is float:
                prop_default = round(prop_default, 4)

            if prop_range[0] == -1 and prop_range[1] == -1:
                prop_range = None

            dump_class[prop_id] = (
                "prop_rna",                 # basic_type
                prop.name,                  # name
                prop_type,                  # type
                prop_range,                 # range
                prop_length,                # length
                prop.default,               # default
                prop.description,           # descr
                Ellipsis,                   # f_args
                Ellipsis,                   # f_arg_types
                Ellipsis,                   # f_ret_types
            )
        del props

        # python props, tricky since we don't know much about them.
        for prop_id, attr in struct_info.get_py_properties():

            dump_class[prop_id] = (
                "prop_py",                  # basic_type
                Ellipsis,                   # name
                Ellipsis,                   # type
                Ellipsis,                   # range
                Ellipsis,                   # length
                Ellipsis,                   # default
                attr.__doc__,               # descr
                Ellipsis,                   # f_args
                Ellipsis,                   # f_arg_types
                Ellipsis,                   # f_ret_types
            )

        # kludge func -> props
        funcs = [(func.identifier, func) for func in struct_info.functions]
        for func_id, func in funcs:

            func_ret_types = tuple([prop.type for prop in func.return_values])
            func_args_ids = tuple([prop.identifier for prop in func.args])
            func_args_type = tuple([prop.type for prop in func.args])

            dump_class[func_id] = (
                "func_rna",                 # basic_type
                Ellipsis,                   # name
                Ellipsis,                   # type
                Ellipsis,                   # range
                Ellipsis,                   # length
                Ellipsis,                   # default
                func.description,           # descr
                func_args_ids,              # f_args
                func_args_type,             # f_arg_types
                func_ret_types,             # f_ret_types
            )
        del funcs

        # kludge func -> props
        funcs = struct_info.get_py_functions()
        for func_id, attr in funcs:
            # arg_str = inspect.formatargspec(*inspect.getargspec(py_func))

            sig = inspect.signature(attr)
            func_args_ids = [k for k, v in sig.parameters.items()]

            dump_class[func_id] = (
                "func_py",                  # basic_type
                Ellipsis,                   # name
                Ellipsis,                   # type
                Ellipsis,                   # range
                Ellipsis,                   # length
                Ellipsis,                   # default
                attr.__doc__,               # descr
                func_args_ids,              # f_args
                Ellipsis,                   # f_arg_types
                Ellipsis,                   # f_ret_types
            )
        del funcs

    filepath_out = args.filepath_out
    with open(filepath_out, 'w', encoding='utf-8') as file_handle:
        json.dump((version, dump), file_handle, cls=JSONEncoderAPIDump)

    indexpath = args.indexpath
    rootpath = os.path.dirname(indexpath)
    if os.path.exists(indexpath):
        with open(indexpath, 'r', encoding='utf-8') as file_handle:
            index = json.load(file_handle)
    else:
        index = {}
    index[version_key] = os.path.relpath(filepath_out, rootpath)
    with open(indexpath, 'w', encoding='utf-8') as file_handle:
        json.dump(index, file_handle)

    print("API version %s dumped into %r, and index %r has been updated" % (version_key, filepath_out, indexpath))
def api_dump(use_properties=True, use_functions=True):
    def prop_type(prop):
        if prop.type == "pointer":
            return prop.fixed_type.identifier
        else:
            return prop.type

    def func_to_str(struct_id_str, func_id, func):

        args = []
        for prop in func.args:
            data_str = "%s %s" % (prop_type(prop), prop.identifier)
            if prop.array_length:
                data_str += "[%d]" % prop.array_length
            if not prop.is_required:
                data_str += "=%s" % prop.default_str
            args.append(data_str)

        data_str = "%s.%s(%s)" % (struct_id_str, func_id, ", ".join(args))
        if func.return_values:
            return_args = ", ".join(
                prop_type(arg) for arg in func.return_values)
            if len(func.return_values) > 1:
                data_str += "  -->  (%s)" % return_args
            else:
                data_str += "  -->  %s" % return_args
        return data_str

    def prop_to_str(struct_id_str, prop_id, prop):

        prop_str = "  <--  %s" % prop_type(prop)
        if prop.array_length:
            prop_str += "[%d]" % prop.array_length

        data_str = "%s.%s %s" % (struct_id_str, prop_id, prop_str)
        return data_str

    def struct_full_id(v):
        struct_id_str = v.identifier  # "".join(sid for sid in struct_id if struct_id)

        for base in v.get_bases():
            struct_id_str = base.identifier + "|" + struct_id_str

        return struct_id_str

    def dump_funcs():
        data = []
        for struct_id, v in sorted(struct.items()):
            struct_id_str = struct_full_id(v)

            funcs = [(func.identifier, func) for func in v.functions]

            for func_id, func in funcs:
                data.append(func_to_str(struct_id_str, func_id, func))

            for prop in v.properties:
                if prop.collection_type:
                    funcs = [(prop.identifier + "." + func.identifier, func)
                             for func in prop.collection_type.functions]
                    for func_id, func in funcs:
                        data.append(func_to_str(struct_id_str, func_id, func))
        data.sort()
        data.append("# * functions *")
        return data

    def dump_props():
        data = []
        for struct_id, v in sorted(struct.items()):
            struct_id_str = struct_full_id(v)

            props = [(prop.identifier, prop) for prop in v.properties]

            for prop_id, prop in props:
                data.append(prop_to_str(struct_id_str, prop_id, prop))

            for prop in v.properties:
                if prop.collection_type:
                    props = [(prop.identifier + "." + prop_sub.identifier,
                              prop_sub)
                             for prop_sub in prop.collection_type.properties]
                    for prop_sub_id, prop_sub in props:
                        data.append(
                            prop_to_str(struct_id_str, prop_sub_id, prop_sub))
        data.sort()
        data.insert(0, "# * properties *")
        return data

    import rna_info
    struct = rna_info.BuildRNAInfo()[0]
    data = []

    if use_functions:
        data.extend(dump_funcs())

    if use_properties:
        data.extend(dump_props())

    if bpy.app.background:
        import sys
        sys.stderr.write("\n".join(data))
        sys.stderr.write("\n\nEOF\n")
    else:
        text = bpy.data.texts.new(name="api.py")
        text.from_string(data)

    print("END")
def pyrna2sphinx(BASEPATH):
    """ bpy.types and bpy.ops
    """
    structs, funcs, ops, props = rna_info.BuildRNAInfo()
    if FILTER_BPY_TYPES is not None:
        structs = {
            k: v
            for k, v in structs.items() if k[1] in FILTER_BPY_TYPES
        }

    if FILTER_BPY_OPS is not None:
        ops = {k: v for k, v in ops.items() if v.module_name in FILTER_BPY_OPS}

    def write_param(ident, fw, prop, is_return=False):
        if is_return:
            id_name = "return"
            id_type = "rtype"
            kwargs = {"as_ret": True}
            identifier = ""
        else:
            id_name = "arg"
            id_type = "type"
            kwargs = {"as_arg": True}
            identifier = " %s" % prop.identifier

        kwargs["class_fmt"] = ":class:`%s`"

        kwargs["collection_id"] = _BPY_PROP_COLLECTION_ID

        type_descr = prop.get_type_description(**kwargs)

        enum_text = pyrna_enum2sphinx(prop)

        if prop.name or prop.description or enum_text:
            fw(ident + ":%s%s:\n\n" % (id_name, identifier))

            if prop.name or prop.description:
                fw(ident + "   " +
                   ", ".join(val
                             for val in (prop.name, prop.description) if val) +
                   "\n\n")

            # special exception, cant use genric code here for enums
            if enum_text:
                write_indented_lines(ident + "   ", fw, enum_text)
                fw("\n")
            del enum_text
            # end enum exception

        fw(ident + ":%s%s: %s\n" % (id_type, identifier, type_descr))

    def write_struct(struct):
        #if not struct.identifier.startswith("Sc") and not struct.identifier.startswith("I"):
        #    return

        #if not struct.identifier == "Object":
        #    return

        filepath = os.path.join(BASEPATH,
                                "bpy.types.%s.rst" % struct.identifier)
        file = open(filepath, "w")
        fw = file.write

        base_id = getattr(struct.base, "identifier", "")

        if _BPY_STRUCT_FAKE:
            if not base_id:
                base_id = _BPY_STRUCT_FAKE

        if base_id:
            title = "%s(%s)" % (struct.identifier, base_id)
        else:
            title = struct.identifier

        write_title(fw, title, "=")

        fw(".. module:: bpy.types\n\n")

        # docs first?, ok
        write_example_ref("", fw, "bpy.types.%s" % struct.identifier)

        base_ids = [base.identifier for base in struct.get_bases()]

        if _BPY_STRUCT_FAKE:
            base_ids.append(_BPY_STRUCT_FAKE)

        base_ids.reverse()

        if base_ids:
            if len(base_ids) > 1:
                fw("base classes --- ")
            else:
                fw("base class --- ")

            fw(", ".join((":class:`%s`" % base_id) for base_id in base_ids))
            fw("\n\n")

        subclass_ids = [
            s.identifier for s in structs.values() if s.base is struct
            if not rna_info.rna_id_ignore(s.identifier)
        ]
        if subclass_ids:
            fw("subclasses --- \n" + ", ".join(
                (":class:`%s`" % s) for s in subclass_ids) + "\n\n")

        base_id = getattr(struct.base, "identifier", "")

        if _BPY_STRUCT_FAKE:
            if not base_id:
                base_id = _BPY_STRUCT_FAKE

        if base_id:
            fw(".. class:: %s(%s)\n\n" % (struct.identifier, base_id))
        else:
            fw(".. class:: %s\n\n" % struct.identifier)

        fw("   %s\n\n" % struct.description)

        # properties sorted in alphabetical order
        sorted_struct_properties = struct.properties[:]
        sorted_struct_properties.sort(key=lambda prop: prop.identifier)

        for prop in sorted_struct_properties:
            type_descr = prop.get_type_description(
                class_fmt=":class:`%s`", collection_id=_BPY_PROP_COLLECTION_ID)
            # readonly properties use "data" directive, variables properties use "attribute" directive
            if 'readonly' in type_descr:
                fw("   .. data:: %s\n\n" % prop.identifier)
            else:
                fw("   .. attribute:: %s\n\n" % prop.identifier)
            if prop.description:
                fw("      %s\n\n" % prop.description)

            # special exception, cant use genric code here for enums
            if prop.type == "enum":
                enum_text = pyrna_enum2sphinx(prop)
                if enum_text:
                    write_indented_lines("      ", fw, enum_text)
                    fw("\n")
                del enum_text
            # end enum exception

            fw("      :type: %s\n\n" % type_descr)

        # python attributes
        py_properties = struct.get_py_properties()
        py_prop = None
        for identifier, py_prop in py_properties:
            pyprop2sphinx("   ", fw, identifier, py_prop)
        del py_properties, py_prop

        for func in struct.functions:
            args_str = ", ".join(
                prop.get_arg_default(force=False) for prop in func.args)

            fw("   .. %s:: %s(%s)\n\n" %
               ("classmethod" if func.is_classmethod else "method",
                func.identifier, args_str))
            fw("      %s\n\n" % func.description)

            for prop in func.args:
                write_param("      ", fw, prop)

            if len(func.return_values) == 1:
                write_param("      ",
                            fw,
                            func.return_values[0],
                            is_return=True)
            elif func.return_values:  # multiple return values
                fw("      :return (%s):\n" %
                   ", ".join(prop.identifier for prop in func.return_values))
                for prop in func.return_values:
                    # TODO, pyrna_enum2sphinx for multiple return values... actually dont think we even use this but still!!!
                    type_descr = prop.get_type_description(
                        as_ret=True,
                        class_fmt=":class:`%s`",
                        collection_id=_BPY_PROP_COLLECTION_ID)
                    descr = prop.description
                    if not descr:
                        descr = prop.name
                    fw("         `%s`, %s, %s\n\n" %
                       (prop.identifier, descr, type_descr))

            write_example_ref(
                "      ", fw,
                "bpy.types." + struct.identifier + "." + func.identifier)

            fw("\n")

        # python methods
        py_funcs = struct.get_py_functions()
        py_func = None

        for identifier, py_func in py_funcs:
            pyfunc2sphinx("   ", fw, identifier, py_func, is_class=True)
        del py_funcs, py_func

        py_funcs = struct.get_py_c_functions()
        py_func = None

        for identifier, py_func in py_funcs:
            py_c_func2sphinx("   ",
                             fw,
                             "bpy.types",
                             struct.identifier,
                             identifier,
                             py_func,
                             is_class=True)

        lines = []

        if struct.base or _BPY_STRUCT_FAKE:
            bases = list(reversed(struct.get_bases()))

            # props
            lines[:] = []

            if _BPY_STRUCT_FAKE:
                descr_items = [(key, descr) for key, descr in sorted(
                    bpy.types.Struct.__bases__[0].__dict__.items())
                               if not key.startswith("__")]

            if _BPY_STRUCT_FAKE:
                for key, descr in descr_items:
                    if type(descr) == GetSetDescriptorType:
                        lines.append("   * :class:`%s.%s`\n" %
                                     (_BPY_STRUCT_FAKE, key))

            for base in bases:
                for prop in base.properties:
                    lines.append("   * :class:`%s.%s`\n" %
                                 (base.identifier, prop.identifier))

                for identifier, py_prop in base.get_py_properties():
                    lines.append("   * :class:`%s.%s`\n" %
                                 (base.identifier, identifier))

                for identifier, py_prop in base.get_py_properties():
                    lines.append("   * :class:`%s.%s`\n" %
                                 (base.identifier, identifier))

            if lines:
                fw(".. rubric:: Inherited Properties\n\n")

                fw(".. hlist::\n")
                fw("   :columns: 2\n\n")

                for line in lines:
                    fw(line)
                fw("\n")

            # funcs
            lines[:] = []

            if _BPY_STRUCT_FAKE:
                for key, descr in descr_items:
                    if type(descr) == MethodDescriptorType:
                        lines.append("   * :class:`%s.%s`\n" %
                                     (_BPY_STRUCT_FAKE, key))

            for base in bases:
                for func in base.functions:
                    lines.append("   * :class:`%s.%s`\n" %
                                 (base.identifier, func.identifier))
                for identifier, py_func in base.get_py_functions():
                    lines.append("   * :class:`%s.%s`\n" %
                                 (base.identifier, identifier))

            if lines:
                fw(".. rubric:: Inherited Functions\n\n")

                fw(".. hlist::\n")
                fw("   :columns: 2\n\n")

                for line in lines:
                    fw(line)
                fw("\n")

            lines[:] = []

        if struct.references:
            # use this otherwise it gets in the index for a normal heading.
            fw(".. rubric:: References\n\n")

            fw(".. hlist::\n")
            fw("   :columns: 2\n\n")

            for ref in struct.references:
                ref_split = ref.split(".")
                if len(ref_split) > 2:
                    ref = ref_split[-2] + "." + ref_split[-1]
                fw("   * :class:`%s`\n" % ref)
            fw("\n")

        # docs last?, disable for now
        # write_example_ref("", fw, "bpy.types.%s" % struct.identifier)
        file.close()

    if "bpy.types" not in EXCLUDE_MODULES:
        for struct in structs.values():
            # TODO, rna_info should filter these out!
            if "_OT_" in struct.identifier:
                continue
            write_struct(struct)

        def fake_bpy_type(class_value,
                          class_name,
                          descr_str,
                          use_subclasses=True):
            filepath = os.path.join(BASEPATH, "bpy.types.%s.rst" % class_name)
            file = open(filepath, "w")
            fw = file.write

            write_title(fw, class_name, "=")

            fw(".. module:: bpy.types\n")
            fw("\n")

            if use_subclasses:
                subclass_ids = [
                    s.identifier for s in structs.values() if s.base is None
                    if not rna_info.rna_id_ignore(s.identifier)
                ]
                if subclass_ids:
                    fw("subclasses --- \n" + ", ".join(
                        (":class:`%s`" % s)
                        for s in sorted(subclass_ids)) + "\n\n")

            fw(".. class:: %s\n\n" % class_name)
            fw("   %s\n\n" % descr_str)
            fw("   .. note::\n\n")
            fw("      Note that bpy.types.%s is not actually available from within blender, it only exists for the purpose of documentation.\n\n"
               % class_name)

            descr_items = [
                (key, descr)
                for key, descr in sorted(class_value.__dict__.items())
                if not key.startswith("__")
            ]

            for key, descr in descr_items:
                if type(
                        descr
                ) == MethodDescriptorType:  # GetSetDescriptorType, GetSetDescriptorType's are not documented yet
                    py_descr2sphinx("   ", fw, descr, "bpy.types", class_name,
                                    key)

            for key, descr in descr_items:
                if type(descr) == GetSetDescriptorType:
                    py_descr2sphinx("   ", fw, descr, "bpy.types", class_name,
                                    key)
            file.close()

        # write fake classes
        if _BPY_STRUCT_FAKE:
            class_value = bpy.types.Struct.__bases__[0]
            fake_bpy_type(class_value,
                          _BPY_STRUCT_FAKE,
                          "built-in base class for all classes in bpy.types.",
                          use_subclasses=True)

        if _BPY_PROP_COLLECTION_FAKE:
            class_value = bpy.data.objects.__class__
            fake_bpy_type(class_value,
                          _BPY_PROP_COLLECTION_FAKE,
                          "built-in class used for all collections.",
                          use_subclasses=False)

    # operators
    def write_ops():
        API_BASEURL = "http://svn.blender.org/svnroot/bf-blender/trunk/blender/release/scripts"
        API_BASEURL_ADDON = "http://svn.blender.org/svnroot/bf-extensions/trunk/py/scripts"
        API_BASEURL_ADDON_CONTRIB = "http://svn.blender.org/svnroot/bf-extensions/contrib/py/scripts"

        op_modules = {}
        for op in ops.values():
            op_modules.setdefault(op.module_name, []).append(op)
        del op

        for op_module_name, ops_mod in op_modules.items():
            filepath = os.path.join(BASEPATH,
                                    "bpy.ops.%s.rst" % op_module_name)
            file = open(filepath, "w")
            fw = file.write

            title = "%s Operators" % op_module_name.replace("_", " ").title()

            write_title(fw, title, "=")

            fw(".. module:: bpy.ops.%s\n\n" % op_module_name)

            ops_mod.sort(key=lambda op: op.func_name)

            for op in ops_mod:
                args_str = ", ".join(
                    prop.get_arg_default(force=True) for prop in op.args)
                fw(".. function:: %s(%s)\n\n" % (op.func_name, args_str))

                # if the description isn't valid, we output the standard warning
                # with a link to the wiki so that people can help
                if not op.description or op.description == "(undocumented operator)":
                    operator_description = undocumented_message(
                        'bpy.ops', op.module_name, op.func_name)
                else:
                    operator_description = op.description

                fw("   %s\n\n" % operator_description)
                for prop in op.args:
                    write_param("   ", fw, prop)
                if op.args:
                    fw("\n")

                location = op.get_location()
                if location != (None, None):
                    if location[0].startswith("addons_contrib" + os.sep):
                        url_base = API_BASEURL_ADDON_CONTRIB
                    elif location[0].startswith("addons" + os.sep):
                        url_base = API_BASEURL_ADDON
                    else:
                        url_base = API_BASEURL

                    fw("   :file: `%s <%s/%s>`_:%d\n\n" %
                       (location[0], url_base, location[0], location[1]))

            file.close()

    if "bpy.ops" not in EXCLUDE_MODULES:
        write_ops()
def api_dump():
    dump = {}
    dump_module = dump["bpy.types"] = {}

    import rna_info
    import inspect

    struct = rna_info.BuildRNAInfo()[0]
    for struct_id, struct_info in sorted(struct.items()):

        struct_id_str = struct_info.identifier

        if rna_info.rna_id_ignore(struct_id_str):
            continue

        for base in struct_info.get_bases():
            struct_id_str = base.identifier + "." + struct_id_str

        dump_class = dump_module[struct_id_str] = {}

        props = [(prop.identifier, prop) for prop in struct_info.properties]
        for prop_id, prop in sorted(props):
            # if prop.type == 'boolean':
            #     continue
            prop_type = prop.type
            prop_length = prop.array_length
            prop_range = round(prop.min, 4), round(prop.max, 4)
            prop_default = prop.default
            if type(prop_default) is float:
                prop_default = round(prop_default, 4)

            if prop_range[0] == -1 and prop_range[1] == -1:
                prop_range = None

            dump_class[prop_id] = (
                "prop_rna",  # basic_type
                prop.name,  # name
                prop_type,  # type
                prop_range,  # range
                prop_length,  # length
                prop.default,  # default
                prop.description,  # descr
                Ellipsis,  # f_args
                Ellipsis,  # f_arg_types
                Ellipsis,  # f_ret_types
            )
        del props

        # python props, tricky since we don't know much about them.
        for prop_id, attr in struct_info.get_py_properties():

            dump_class[prop_id] = (
                "prop_py",  # basic_type
                Ellipsis,  # name
                Ellipsis,  # type
                Ellipsis,  # range
                Ellipsis,  # length
                Ellipsis,  # default
                attr.__doc__,  # descr
                Ellipsis,  # f_args
                Ellipsis,  # f_arg_types
                Ellipsis,  # f_ret_types
            )

        # kludge func -> props
        funcs = [(func.identifier, func) for func in struct_info.functions]
        for func_id, func in funcs:

            func_ret_types = tuple([prop.type for prop in func.return_values])
            func_args_ids = tuple([prop.identifier for prop in func.args])
            func_args_type = tuple([prop.type for prop in func.args])

            dump_class[func_id] = (
                "func_rna",  # basic_type
                Ellipsis,  # name
                Ellipsis,  # type
                Ellipsis,  # range
                Ellipsis,  # length
                Ellipsis,  # default
                func.description,  # descr
                func_args_ids,  # f_args
                func_args_type,  # f_arg_types
                func_ret_types,  # f_ret_types
            )
        del funcs

        # kludge func -> props
        funcs = struct_info.get_py_functions()
        for func_id, attr in funcs:
            # arg_str = inspect.formatargspec(*inspect.getargspec(py_func))

            sig = inspect.signature(attr)
            func_args_ids = [k for k, v in sig.parameters.items()]

            dump_class[func_id] = (
                "func_py",  # basic_type
                Ellipsis,  # name
                Ellipsis,  # type
                Ellipsis,  # range
                Ellipsis,  # length
                Ellipsis,  # default
                attr.__doc__,  # descr
                func_args_ids,  # f_args
                Ellipsis,  # f_arg_types
                Ellipsis,  # f_ret_types
            )
        del funcs

    import pprint

    filename = api_dunp_fname()
    filehandle = open(filename, 'w', encoding='utf-8')
    tot = filehandle.write(pprint.pformat(dump, width=1))
    filehandle.close()
    print("%s, %d bytes written" % (filename, tot))
Beispiel #9
0
            if rna_prop:
                GetInfoOperatorRNA(rna_prop.bl_rna)

    for rna_info in InfoOperatorRNA.global_lookup.values():
        rna_info.build()
        for rna_prop in rna_info.args:
            rna_prop.build()

    #for rna_info in InfoStructRNA.global_lookup.values():
    #    print(rna_info)
    return InfoStructRNA.global_lookup, InfoFunctionRNA.global_lookup, InfoOperatorRNA.global_lookup, InfoPropertyRNA.global_lookup


if __name__ == "__main__":
    import rna_info
    struct = rna_info.BuildRNAInfo()[0]
    data = []
    for struct_id, v in sorted(struct.items()):
        struct_id_str = v.identifier  #~ "".join(sid for sid in struct_id if struct_id)

        for base in v.get_bases():
            struct_id_str = base.identifier + "|" + struct_id_str

        props = [(prop.identifier, prop) for prop in v.properties]
        for prop_id, prop in sorted(props):
            # if prop.type == "boolean":
            #     continue
            prop_type = prop.type
            if prop.array_length > 0:
                prop_type += "[%d]" % prop.array_length