Return specific referents of a module object.
162777
def _module_refs(obj, named):
    '''
    '''
     # ignore this very module
    if obj.__name__ == __name__:
        return ()
     # module is essentially a dict
    return _dict_refs(obj.__dict__, named)
49474
def get_module_plugins(module, classobj):
    
    try:
        names = module.__all__
    except AttributeError:
        names = [x for x in vars(module) if not x.startswith('_')]
    for name in names:
        try:
            obj = getattr(module, name)
        except AttributeError:
            continue
        try:
            if issubclass(obj, classobj):
                yield obj
        except TypeError:
            continue
747297
def _module_callers(parser, modname, result):
    
    if modname in result:
        #We have already processed this module.
        return
    
    module = parser.get(modname)
    mresult = {}
    if module is not None:
        for xname, xinst in module.executables():
            _exec_callers(xinst, mresult)
        result[modname] = mresult
        
        for depkey in module.dependencies:
            depmod = depkey.split('.')[0].lower()
            _module_callers(parser, depmod, result)
1268162
def get_modules(modulepath):
    """"""
    m = importlib.import_module(modulepath)
    mpath = m.__file__
    ret = set([m])

    if "__init__." in mpath.lower():
        mpath = os.path.dirname(mpath)

        # https://docs.python.org/2/library/pkgutil.html#pkgutil.iter_modules
        for module_info in pkgutil.iter_modules([mpath]):
            submodulepath = ".".join([modulepath, module_info[1]])
            if module_info[2]:
                # module is a package
                submodules = get_modules(submodulepath)
                ret.update(submodules)
            else:
                ret.add(importlib.import_module(submodulepath))

    return ret
599402
def process_kwargs(obj, kwargs):
    '''
    
    '''
    with Modules() as m:
        kwargs = m.kwargs(obj, kwargs)
    return kwargs
989842
def get_caller_module():
    
    stack = inspect.stack()
    assert len(stack) > 1
    caller = stack[2][0]
    return caller.f_globals['__name__']
229324
def fullqualname_py3(obj):
    """"""

    if type(obj).__name__ == 'builtin_function_or_method':

        return _fullqualname_builtin_py3(obj)

    elif type(obj).__name__ == 'function':

        return _fullqualname_function_py3(obj)

    elif type(obj).__name__ in ['member_descriptor', 'method_descriptor',
                                'wrapper_descriptor']:

        return obj.__objclass__.__module__ + '.' + obj.__qualname__

    elif type(obj).__name__ == 'method':

        return _fullqualname_method_py3(obj)

    elif type(obj).__name__ == 'method-wrapper':

        return fullqualname_py3(obj.__self__) + '.' + obj.__name__

    elif type(obj).__name__ == 'module':

        return obj.__name__

    elif type(obj).__name__ == 'property':

        return obj.fget.__module__ + '.' + obj.fget.__qualname__

    elif inspect.isclass(obj):

        return obj.__module__ + '.' + obj.__qualname__

    return obj.__class__.__module__ + '.' + obj.__class__.__qualname__
939094
def get_module_constant(module, symbol, default=-1, paths=None):
    """"""

    try:
        f, path, (suffix, mode, kind) = find_module(module, paths)
    except ImportError:
        # Module doesn't exist
        return None

    try:
        if kind == PY_COMPILED:
            f.read(8)  # skip magic & date
            code = marshal.load(f)
        elif kind == PY_FROZEN:
            code = imp.get_frozen_object(module)
        elif kind == PY_SOURCE:
            code = compile(f.read(), path, 'exec')
        else:
            # Not something we can parse; we'll have to import it.  :(
            if module not in sys.modules:
                imp.load_module(module, f, path, (suffix, mode, kind))
            return getattr(sys.modules[module], symbol, None)

    finally:
        if f:
            f.close()

    return extract_constant(code, symbol, default)
617976
def load_object_by_name(object_name):
    """"""
    mod_name, attr = object_name.rsplit('.', 1)
    mod = import_module(mod_name)
    return getattr(mod, attr)
979505
def compare(all_dict, others, names, module_name):
    """"""
    only_all = set()
    for name in all_dict:
        if name not in names:
            only_all.add(name)

    only_ref = set()
    missing = set()
    for name in names:
        if name not in all_dict:
            for pat in REFGUIDE_ALL_SKIPLIST:
                if re.match(pat, module_name + '.' + name):
                    if name not in others:
                        missing.add(name)
                    break
            else:
                only_ref.add(name)

    return only_all, only_ref, missing
360288
def get_imports(project, pydefined):
    """"""
    pymodule = pydefined.get_module()
    module = module_imports.ModuleImports(project, pymodule)
    if pymodule == pydefined:
        return [stmt.import_info for stmt in module.imports]
    return module.get_used_imports(pydefined)
595484
def get_obj_module(qualname):
    """"""
    modname = qualname
    classname = None
    attrname = None
    while modname not in sys.modules:
        attrname = classname
        modname, classname = modname.rsplit('.', 1)

    # retrieve object and find original module name
    if classname:
        cls = getattr(sys.modules[modname], classname)
        modname = cls.__module__
        obj = getattr(cls, attrname) if attrname else cls
    else:
        obj = None

    return obj, sys.modules[modname]
802495
def parse(self, module):
        """"""
        matches = self.RE_TYPE.finditer(module.contents)
        result = {}

        for match in matches:
            name = match.group("name")
            modifiers = match.group("modifiers")
            if modifiers is not None:
                cleanmods = re.split("[\s,]+", modifiers.strip())
            else:
                cleanmods = []

            contents = match.group("contents")
            result[name.lower()] = self._process_type(name, cleanmods, contents, module, match)
            if "public" in result[name.lower()].modifiers:
                module.publics[name.lower()] = 1

        #Set the types we found in the module and then move the embedded
        #ones into their correct parent executables.
        module.types = result
        module.update_embedded("types")
785929
def get_qualified_name(_object):
    """"""
    module = _object.__module__
    if hasattr(_object, '__name__'):
        _class = _object.__name__

    else:
        _class = _object.__class__.__name__

    return module + '.' + _class
1238524
def find_module(module, paths=None):
    """"""

    parts = module.split('.')

    while parts:
        part = parts.pop(0)
        f, path, (suffix, mode, kind) = info = imp.find_module(part, paths)

        if kind == PKG_DIRECTORY:
            parts = parts or ['__init__']
            paths = [path]

        elif parts:
            raise ImportError("Can't find %r in %s" % (parts, module))

    return info
1225913
def get_objects(self):
        """"""
        return rope.base.oi.soi.get_passed_objects(
            self.pyfunction, self.index)
981230
def get_module_path(module):
    """"""
    return pathlib.Path(
        os.path.dirname(os.path.abspath(inspect.getfile(module))))