find a ModuleItem
1488
public static ModuleItem findModuleItem(String[] path) {
        if (disabled)
            return null;
        if (path == null || path[0].equals(APPSERVER_MODULE)) {
            return moduleRoot;
        }
        return moduleRoot.find(path, 0);
    }
846277
def find_module(cls, fullname, path=None):
        
        spec = cls.find_spec(fullname, path)
        if spec is None:
            return None
        elif spec.loader is None and spec.submodule_search_locations:
            # Here we need to create a namespace loader to handle namespaces since python2 doesn't...
            return NamespaceLoader2(spec.name, spec.submodule_search_locations)
        else:
            return spec.loader
981230
def get_module_path(module):
    """"""
    return pathlib.Path(
        os.path.dirname(os.path.abspath(inspect.getfile(module))))
587704
def get_module(mod_name):
    
    if mod_name is '':
        raise ImportError('Unable to import empty module')

    mod = __import__(mod_name)
    components = mod_name.split('.')

    for comp in components[1:]:
        mod = getattr(mod, comp)

    return mod
1177849
def get_modules(self, name):
        """"""
        result = []
        for module in self.names:
            if name in self.names[module]:
                result.append(module)
        return result
90118
def main_module(self):
        """"""
        if self.i_module.keyword == "submodule":
            return self.i_module.i_ctx.get_module(
                self.i_module.i_including_modulename)
        return self.i_module
380273
def is_defined_by_module(item, module, parent=None):
    
    flag = False
    if isinstance(item, types.ModuleType):
        if not hasattr(item, '__file__'):
            try:
                # hack for cv2 and xfeatures2d
                import utool as ut
                name = ut.get_modname_from_modpath(module.__file__)
                flag = name in str(item)
            except:
                flag = False
        else:
            item_modpath = os.path.realpath(dirname(item.__file__))
            mod_fpath = module.__file__.replace('.pyc', '.py')
            if not mod_fpath.endswith('__init__.py'):
                flag = False
            else:
                modpath = os.path.realpath(dirname(mod_fpath))
                modpath = modpath.replace('.pyc', '.py')
                flag = item_modpath.startswith(modpath)
    elif hasattr(item, '_utinfo'):
        # Capture case where there is a utool wrapper
        orig_func = item._utinfo['orig_func']
        flag = is_defined_by_module(orig_func, module, parent)
    else:
        if isinstance(item, staticmethod):
            # static methods are a wrapper around a function
            item = item.__func__
        try:
            func_globals = meta_util_six.get_funcglobals(item)
            func_module_name = func_globals['__name__']
            if func_module_name == 'line_profiler':
                valid_names = dir(module)
                if parent is not None:
                    valid_names += dir(parent)
                if item.func_name in valid_names:
                    # hack to prevent small names
                    #if len(item.func_name) > 8:
                    if len(item.func_name) > 6:
                        flag = True
            elif func_module_name == module.__name__:
                flag = True
        except  AttributeError:
            if hasattr(item, '__module__'):
                flag = item.__module__ == module.__name__
    return flag
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]
157945
def find_module_path():
    """"""
    master_modname = __name__.split(".", 1)[0]
    master_module = sys.modules[master_modname]
    #return os.path.dirname(os.path.realpath(os.path.join(inspect.getsourcefile(endpoints), "..")))
    path = os.path.dirname(inspect.getsourcefile(master_module))
    return path
97022
public function inModuleList(string $item, string $moduleName, string $listName)
    {
        try {
            $items = (new ModuleConfig(ConfigType::LISTS(), $moduleName, $listName))->parseToArray();
        } catch (InvalidArgumentException $e) {
            return $e->getMessage();
        }

        /** @var mixed[]|null $config */
        $inactive = $items['items'][$item]['inactive'] ?? null;
        if ($inactive === null || $inactive === true) {
            return (string)__('Invalid list item: `{0}`', $item);
        }

        return true;
    }
687590
def get_module_path(modname):
    """"""
    return osp.abspath(osp.dirname(sys.modules[modname].__file__))
1138041
function findModule(host, generateDir) {
    let dir = host.getDir('/' + generateDir);
    const moduleRe = /\.module\.ts$/;
    const routingModuleRe = /-routing\.module\.ts/;
    while (dir) {
        const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));
        if (matches.length == 1) {
            return core_1.join(dir.path, matches[0]);
        }
        else if (matches.length > 1) {
            throw new Error('More than one module matches. Use skip-import option to skip importing '
                + 'the component into the closest module.');
        }
        dir = dir.parent;
    }
    throw new Error('Could not find an NgModule for the new component. Use the skip-import '
        + 'option to skip importing components in NgModule.');
}
1091690
def find_model(config, obj, mods):
    """"""
    for mod in mods:
        if mod[0] != config:
            continue

        if len(mod) == 2:
            return mod[1]

        if len(mod) == 3 and mod[1] in obj:
            return mod[2]

    return None
1359919
def _get_calling_module(self):
        
        for frame in inspect.stack():
            mod = inspect.getmodule(frame[0])
            logger.debug(f'calling module: {mod}')
            if mod is not None:
                mod_name = mod.__name__
                if mod_name != __name__:
                    return mod
431548
function loadModule (baseLoader, fromDir, fromFile, item, opts) {
      var modulePath = item.from;
      var possibilities = util.resolveModulePath(modulePath, fromDir);
      for (var i = 0, p; p = possibilities[i]; ++i) {
        var path = possibilities[i].path;
        if (!opts.reload && (path in jsio.__modules)) {
          return possibilities[i];
        }

        if (path in failedFetch) { possibilities.splice(i--, 1); }
      }

      if (!possibilities.length) {
        if (opts.suppressErrors) { return false; }
        var e = new Error('Could not import `' + item.from + '`'
            + "\tImport Stack:\n"
            + "\t\t" + processStack().join("\n\t\t"));
        e.jsioLogged = true;
        e.code = MODULE_NOT_FOUND;
        throw e;
      }

      var moduleDef = findModule(possibilities);
      if (!moduleDef) {
        if (opts.suppressErrors) { return false; }
        var paths = [];
        for (var i = 0, p; p = possibilities[i]; ++i) { paths.push(p.path); }
        var e = new Error("Could not import `" + modulePath + "`\n"
          + "\tlooked in:\n"
            + "\t\t" + paths.join('\n\t\t') + "\n"
            + "\tImport Stack:\n"
            + "\t\t" + processStack().join("\n\t\t"));
        e.code = MODULE_NOT_FOUND;
        throw e;
      }

      // a (potentially) nicer way to refer to a module -- how it was referenced in code when it was first imported
      moduleDef.friendlyPath = modulePath;

      // cache the base module's path in the path cache so we don't have to
      // try out all paths the next time we see the same base module.
      if (moduleDef.baseMod && !(moduleDef.baseMod in jsioPath.cache)) {
        jsioPath.cache[moduleDef.baseMod] = moduleDef.basePath;
      }

      // don't apply the standard preprocessors to base.js.  If we're reloading
      // the source code, always apply them.  We also don't want to run them
      // if they've been run once -- moduleDef.pre is set to true already
      // if we're reading the code from the source cache.
      if (modulePath != 'base' && (opts.reload || !opts.dontPreprocess && !moduleDef.pre)) {
        moduleDef.pre = true;

        applyPreprocessors(fromDir, moduleDef, ["import", "inlineSlice"], opts);
      }

      // any additional preprocessors?
      if (opts.preprocessors) {
        applyPreprocessors(fromDir, moduleDef, opts.preprocessors, opts);
      }

      return moduleDef;
    }
484341
def getModulePath(project_path,module_name,verbose):
    ''''''
    if not module_name:
        return None
    sys.path.append(project_path)
    try:
        package = pkgutil.get_loader(module_name)
    except ImportError:
        if verbose:
            print("Parent module for "+module_name+" not found.")
        return None
    except:
        if verbose:
            print(module_name+" not loaded for bizarre reasons")
    try:
        if package: 
                if package.get_code(module_name):
                    filename = package.get_code(module_name).co_filename
                    return filename
                elif package.find_spec(module_name).has_location==False:
                    return None #built-in module such as itertools
                else:
                    pass #perhaps filename is in package.find_spec(module_name).origin?
                    pass #a good reference is https://www.python.org/dev/peps/pep-0302/
    except ImportError:
        if verbose:
            print("Code object unavailable for "+module_name)
        return None
    except AttributeError:
        if verbose:
            print(module_name+" is an ExtensionFileLoader object")
        return None
    except:
        if verbose:
            print(module_name+" not loaded for bizarre reasons")
        return None
    else:
        if verbose:
            print ("Module "+module_name+" not found.")
        return None
1347894
function findModuleNameByInteractive() {
        var scripts = document.getElementsByTagName('script'),
            re,
            i,
            name,
            script;

        for (i = scripts.length - 1; i >= 0; i--) {
            script = scripts[i];
            if (script.readyState === 'interactive') {
                re = script;
                break;
            }
        }
        if (re) {
            name = re.getAttribute('data-mod-name');
        } else {
            // sometimes when read module file from cache,
            // interactive status is not triggered
            // module code is executed right after inserting into dom
            // i has to preserve module name before insert module script into dom,
            // then get it back here
            logger.debug('can not find interactive script,time diff : ' + (+new Date() - startLoadModTime));
            logger.debug('old_ie get mod name from cache : ' + startLoadModName);
            name = startLoadModName;
        }
        return name;
    }