Ensure that the given module is loaded as a submodule.

    Returns:
        str: The name that the module should be imported as.
358689
def _ensure_package_loaded(path, component):
    

    logger = logging.getLogger(__name__)

    packages = component.find_products('support_package')
    if len(packages) == 0:
        return None
    elif len(packages) > 1:
        raise ExternalError("Component had multiple products declared as 'support_package", products=packages)

    if len(path) > 2 and ':' in path[2:]:  # Don't flag windows C: type paths
        path, _, _ = path.rpartition(":")

    package_base = packages[0]
    relative_path = os.path.normpath(os.path.relpath(path, start=package_base))
    if relative_path.startswith('..'):
        raise ExternalError("Component had python product output of support_package",
                            package=package_base, product=path, relative_path=relative_path)

    if not relative_path.endswith('.py'):
        raise ExternalError("Python product did not end with .py", path=path)

    relative_path = relative_path[:-3]
    if os.pathsep in relative_path:
        raise ExternalError("Python support wheels with multiple subpackages not yet supported",
                            relative_path=relative_path)

    support_distro = component.support_distribution
    if support_distro not in sys.modules:
        logger.debug("Creating dynamic support wheel package: %s", support_distro)
        file, path, desc = imp.find_module(os.path.basename(package_base), [os.path.dirname(package_base)])
        imp.load_module(support_distro, file, path, desc)

    return "{}.{}".format(support_distro, relative_path)
78158
def is_submodule_included(src, tgt):
    """"""
    if tgt is None or not hasattr(tgt, 'i_orig_module'):
        return True
    if (tgt.i_orig_module.keyword == 'submodule' and
        src.i_orig_module != tgt.i_orig_module and
        src.i_orig_module.i_modulename == tgt.i_orig_module.i_modulename):
        if src.i_orig_module.search_one('include',
                                        tgt.i_orig_module.arg) is None:
            return False
    return True
280033
def import_module(modulename):
    
    module = None
    try:
        module = importlib.import_module(modulename)
    except ImportError:
        # If importing fails we see if the modulename has dots in it, split the name.
        if "." in modulename:
            modules = modulename.split(".")
            package = ".".join(modules[1:len(modules)])
            # Might raise an ImportError again. If so, we really failed to import the module.
            module = importlib.import_module(package)
        else:
            # No dots, really unable to import the module. Raise.
            raise
    return module
945060
def load_module(module):
    
    try:
        m = importlib.import_module(module)
        return m
    except ModuleNotFoundError:  # pragma: no cover
        raise TImportError("Module `%s` is not installed. It is required for "
                           "running this function." % module)
980541
def import_apps_submodule(submodule):
    
    found_apps = []
    for appconfig in apps.get_app_configs():
        app = appconfig.name
        if import_module_or_none('{0}.{1}'.format(app, submodule)) is not None:
            found_apps.append(app)

    return found_apps
623655
def import_submodules(package_name: str) -> None:
    
    importlib.invalidate_caches()

    # For some reason, python doesn't always add this by default to your path, but you pretty much
    # always want it when using `--include-package`.  And if it's already there, adding it again at
    # the end won't hurt anything.
    sys.path.append('.')

    # Import at top level
    module = importlib.import_module(package_name)
    path = getattr(module, '__path__', [])
    path_string = '' if not path else path[0]

    # walk_packages only finds immediate children, so need to recurse.
    for module_finder, name, _ in pkgutil.walk_packages(path):
        # Sometimes when you import third-party libraries that are on your path,
        # `pkgutil.walk_packages` returns those too, so we need to skip them.
        if path_string and module_finder.path != path_string:
            continue
        subpackage = f"{package_name}.{name}"
        import_submodules(subpackage)
66563
def _is_module_included(self, module):
        
        if module in self.exclude_modules:
            return False

        if self.include_modules is None:
            return True

        return module in self.include_modules
326566
def tryImportModule(self, name):
        
        self._name = name
        try:
            import importlib
            self._module = importlib.import_module(name)
        except ImportError:
            self._module = None
            self._version = ''
            self._packagePath = ''
        else:
            if self._versionAttribute:
                self._version = getattr(self._module, self._versionAttribute, '???')
            if self._pathAttribute:
                self._packagePath = getattr(self._module, self._pathAttribute, '???')
999995
def _module_name(self) -> str:
        """"""
        name = self.f.__module__
        if name == '__main__':
            return importer.main_module_name()
        return name
191361
def visit_importfrom(self, node):
        ''''''
        module_filename = node.root().file
        if fnmatch.fnmatch(module_filename, '__init__.py*') and \
                not fnmatch.fnmatch(module_filename, 'test_*.py*'):
            return
        basename = node.modname
        self._check_blacklisted_module(node, basename)
721533
def list_submodules(module_name: str) -> List[str]:   # pylint: disable=invalid-sequence-index
    
    _module = importlib.import_module(module_name)
    return [module_name+'.'+submodule_name for _, submodule_name, _ in pkgutil.iter_modules(_module.__path__)]
17200
def load_module(self, module):
        
        # pylint: disable=unused-variable
        for name, obj in inspect.getmembers(module,
                                            lambda member: hasattr(member, '__module__')
                                            and member.__module__ == module.__name__
                                            and inspect.isclass):
            self.load_class(obj)
848756
def import_module(mod_str):
    

    _module = __import__(mod_str)
    _mod_parts = mod_str.split('.')
    for _mod_part in _mod_parts[1:]:
        _module = getattr(_module, _mod_part)
    return _module
1050918
def import_submodules(package):
    """"""

    if isinstance(package, str):
        package = importlib.import_module(package)

    results = {}

    for _, full_name, is_pkg in pkgutil.walk_packages(package.__path__, package.__name__ + '.'):
        results[full_name] = importlib.import_module(full_name)

        if is_pkg:
            results.update(import_submodules(full_name))

    return results
1191989
def get_imported_module(self, context):
        
        if self.level == 0:
            return context.project.get_module(
                self.module_name, context.folder)
        else:
            return context.project.get_relative_module(
                self.module_name, context.folder, self.level)
146406
def namedModule(name):
    """"""
    topLevel = __import__(name)
    packages = name.split(".")[1:]
    m = topLevel
    for p in packages:
        m = getattr(m, p)
    return m
687139
public String getSubmoduleName() {
        if (path != null && path.length > SUBMODULE_INDEX)
            return path[SUBMODULE_INDEX];
        else
            return null;
    }