import inspect
import os
import types
import typing
import sys
import bpy

# TODO
# init_unreal.py
# usersetup.py

def __make_completer(mod):
    """
    make each meta modules

    Args:
        mod:

    Returns:

    """
    local = os.path.dirname(os.path.dirname(inspect.currentframe().f_code.co_filename))
    completer = os.path.join(local, "user", "stubs.pyi").replace(os.sep, "/")

    header = "\"\"\"this document generated by internal module.\"\"\"\n\n\n"
    module = __import__(mod)
    with open(completer, "w") as f:
        f.write(header)

        for fn, _ in inspect.getmembers(module):
            if fn.startswith("_"):
                continue

            f.write("def {0}(*args, **kwargsargs):\n".format(fn))
            f.write("   \"\"\"{0}\"\"\"\n".format(inspect.getdoc(fn)))
            f.write("   pass\n\n")

    sys.meta_path.append(local + "/user/stubs.pyi")


for i in [i for i in dir(yurlungur) if i[0] != "_" and i != "Qt"]:
    obj = getattr(yurlungur, i)

    if type(obj) == types.FunctionType:
        server.register_function(obj, "yurlungur.%s" % i)
    else:
        try:
            for m in [m for m in dir(obj) if m[0] != "_"]:
                meth = getattr(obj, m)
                if (type(meth) not in (types.MethodType, types.FunctionType)):
                    continue

                # if isinstance(meth, hou.EnumValue):
                #     client.register_function(meth.__repr__, "hou.%s.%s.__repr__" % (i, m))
                if (type(obj) in (type, type) and type(meth) == types.MethodType):
                    server.register_function(meth, "typeMethods.yurlungur.%s.%s" % (i, m))
                else:
                    for m in dir(obj):
                        meth = getattr(obj, m)
                        if (type(meth) not in (types.MethodType, types.FunctionType)) or m == "_":
                            continue

                        # if isinstance(meth, hou.EnumValue):
                        #     client.register_function(meth.__repr__, "hou.%s.%s.__repr__" % (i, m))
                        if (type(obj) in (type, type) and type(meth) == types.MethodType):
                            server.register_function(meth, "typeMethods.yurlungur.%s.%s" % (i, m))
                        else:
                            server.register_function(meth, "yurlungur.%s.%s" % (i, m))
        except TypeError:
            pass

import inspect
import os
import types
import typing
import sys
import bpy

# TODO
# init_unreal.py
# usersetup.py

def __make_completer(mod):
    """
    make each meta modules

    Args:
        mod:

    Returns:

    """
    local = os.path.dirname(os.path.dirname(inspect.currentframe().f_code.co_filename))
    completer = os.path.join(local, "user", "stubs.pyi").replace(os.sep, "/")

    header = "\"\"\"this document generated by internal module.\"\"\"\n\n\n"
    module = __import__(mod)
    with open(completer, "w") as f:
        f.write(header)

        for fn, _ in inspect.getmembers(module):
            if fn.startswith("_"):
                continue

            f.write("def {0}(*args, **kwargsargs):\n".format(fn))
            f.write("   \"\"\"{0}\"\"\"\n".format(inspect.getdoc(fn)))
            f.write("   pass\n\n")

    sys.meta_path.append(local + "/user/stubs.pyi")


for i in [i for i in dir(yurlungur) if i[0] != "_" and i != "Qt"]:
    obj = getattr(yurlungur, i)

    if type(obj) == types.FunctionType:
        server.register_function(obj, "yurlungur.%s" % i)
    else:
        try:
            for m in [m for m in dir(obj) if m[0] != "_"]:
                meth = getattr(obj, m)
                if (type(meth) not in (types.MethodType, types.FunctionType)):
                    continue

                # if isinstance(meth, hou.EnumValue):
                #     client.register_function(meth.__repr__, "hou.%s.%s.__repr__" % (i, m))
                if (type(obj) in (type, type) and type(meth) == types.MethodType):
                    server.register_function(meth, "typeMethods.yurlungur.%s.%s" % (i, m))
                else:
                    for m in dir(obj):
                        meth = getattr(obj, m)
                        if (type(meth) not in (types.MethodType, types.FunctionType)) or m == "_":
                            continue

                        # if isinstance(meth, hou.EnumValue):
                        #     client.register_function(meth.__repr__, "hou.%s.%s.__repr__" % (i, m))
                        if (type(obj) in (type, type) and type(meth) == types.MethodType):
                            server.register_function(meth, "typeMethods.yurlungur.%s.%s" % (i, m))
                        else:
                            server.register_function(meth, "yurlungur.%s.%s" % (i, m))
        except TypeError:
            pass

# TODO # init_unreal.py # usersetup.py make each meta modules      Args:         mod:      Returns: # if isinstance(meth, hou.EnumValue): #     client.register_function(meth.__repr__, "hou.%s.%s.__repr__" % (i, m)) # if isinstance(meth, hou.EnumValue): #     client.register_function(meth.__repr__, "hou.%s.%s.__repr__" % (i, m))