Import functions in package from their implementation modules.
168052
def import_functions(names, src, dst):
    """"""
    for name in names:
        module = importlib.import_module('pygsp.' + src)
        setattr(sys.modules['pygsp.' + dst], name, getattr(module, name))
17795
def __push_import_modules(self):
        
        for module in self.__import_modules:
            sys.modules[module.__name__] = module
284322
def get_submodules(mod):
    """"""
    def catch_exceptions(module):
        pass
    try:
        m = __import__(mod)
        submodules = [mod]
        submods = pkgutil.walk_packages(m.__path__, m.__name__ + '.',
                                        catch_exceptions)
        for sm in submods:
            sm_name = sm[1]
            submodules.append(sm_name)
    except ImportError:
        return []
    except:
        return [mod]
    
    return submodules
953551
def scan_module(self, pkgpath, modpath, node):
        """"""

        def scan_imports(node):
            if node_type(node) == 'Import':
                for binding in node.names:
                    name, asname = binding.name, binding.asname
                    if asname:
                        self.add(modpath, asname, name)
                    else:
                        top_name = name.split('.')[0]
                        self.add(modpath, top_name, top_name)
                    self.add_package_origins(name)

            elif node_type(node) == 'ImportFrom':
                frompath = resolve_frompath(pkgpath, node.module, node.level)
                for binding in node.names:
                    name, asname = binding.name, binding.asname
                    if name == '*':
                        for name in self.get_star_names(frompath):
                            self.add(modpath, name, frompath + '.' + name)
                        self.add_package_origins(frompath)
                    else:
                        self.add(modpath, asname or name, frompath + '.' + name)
                        self.add_package_origins(frompath + '.' + name)

            else:
                for_each_child(node, scan_imports)

        for_each_child(node, scan_imports)
952928
public void addImportedPackages(String[] imports) {
        if (imports == null) { return; }

        for (String imported : imports) {
            this.mImports.add(imported);
        }
    }
683432
def visit_importfrom(self, node):
        """"""
        return "from %s import %s" % (
            "." * (node.level or 0) + node.modname,
            _import_string(node.names),
        )
1029332
def get_modules(package_name, module_names):
  
  def get_module(name):
    return __import__(".".join([package_name, name]), fromlist=[package_name])
  return [get_module(name) for name in module_names]
1181853
def import_module(module_name):
    """"""
    import sys, os
    import importlib
    sys.path.append(os.path.dirname(__file__))
    return importlib.import_module(module_name)
364266
def import_log_funcs():
    """"""
    global g_logger
 
    curr_mod = sys.modules[__name__]

    for func_name in _logging_funcs:
        func = getattr(g_logger, func_name)
        setattr(curr_mod, func_name, func)
164772
def named_module(name):
    """"""
    module = __import__(name)
    packages = name.split(".")[1:]
    m = module
    for p in packages:
        m = getattr(m, p)
    return m
734901
def _import_sub_module(module, name):
    """"""
    module = __import__(module.__name__ + "." + name)
    for level in name.split("."):
        module = getattr(module, level)
    return module
508285
def import_modules_from_package(package):
    
    path = [os.path.dirname(__file__), '..'] + package.split('.')
    path = os.path.join(*path)
    for root, dirs, files in os.walk(path):
        for filename in files:
            if filename.startswith('__') or not filename.endswith('.py'):
                continue
            new_package = ".".join(root.split(os.sep)).split("....")[1]
            module_name = '%s.%s' % (new_package, filename[:-3])
            if module_name not in sys.modules:
                __import__(module_name)
1003519
def import_related_module(package, pkg_path, related_name,
                          ignore_exceptions=False):
    """"""
    try:
        imp.find_module(related_name, pkg_path)
    except ImportError:
        return

    try:
        return getattr(
            __import__('%s' % (package), globals(), locals(), [related_name]),
            related_name
        )
    except Exception as e:
        if ignore_exceptions:
            current_app.logger.exception(
                'Can not import "{}" package'.format(package)
            )
        else:
            raise e
429756
def avail_approaches(pkg):
    '''
    '''
    methods = [modname for importer, modname, ispkg in
               pkgutil.walk_packages(path=pkg.__path__)
               if modname not in
               ['common_args', 'directions', 'sobol_sequence']]
    return methods
913118
def load_model_from_package(name, **overrides):
    """"""
    cls = importlib.import_module(name)
    return cls.load(**overrides)
465151
def import_file(filename, package_name=None):
    
    path = os.path.dirname(filename)

    if not path in sys.path:
        sys.path.append( path )
        remove_path = True

    else:
        remove_path = False

    name = os.path.splitext(os.path.basename(filename))[0]

    if name in sys.modules:
        force_reload = True
    else:
        force_reload = False


    if package_name is not None:
        mod = __import__('.'.join((package_name, name)), fromlist=[name])

    else:
        mod = __import__(name)

    if force_reload:
        reload(mod)

    if remove_path:
        sys.path.pop(-1)

    return mod
555282
def import_formulas(self):
        
        # TODO: unit tests!
        # TODO: move this to somewhere else and call it "importy", maybe
        # core.__init__.py since a lot of modules might use it.
        module = self.meta.module  # module read from parameters
        package = getattr(self.meta, 'package', None)  # package read from meta
        name = package + module if package else module  # concat pkg + name
        path = getattr(self.meta, 'path', None)  # path read from parameters
        # import module using module and package
        mod = None
        # SEE ALSO: http://docs.python.org/2/library/imp.html#examples
        try:
            # fast path: see if module was already imported
            mod = sys.modules[name]
        except KeyError:
            try:
                # import module specified in parameters
                mod = importlib.import_module(module, package)
            except ImportError as err:
                if not path:
                    msg = ('%s could not be imported either because it was not '
                           'on the PYTHONPATH or path was not given.')
                    LOGGER.exception(msg, name)
                    raise err
                else:
                    # import module using path
                    # expand ~, environmental variables and make path absolute
                    if not os.path.isabs(path):
                        path = os.path.expanduser(os.path.expandvars(path))
                        path = os.path.abspath(path)
                    # paths must be a list
                    paths = [path]
                    # imp does not find hierarchical module names, find and load
                    # packages recursively, then load module, see last paragraph
                    # https://docs.python.org/2/library/imp.html#imp.find_module
                    pname = ''  # full dotted name of package to load
                    # traverse namespace
                    while name:
                        # if dot in name get first package
                        if '.' in name:
                            pkg, name = name.split('.', 1)
                        else:
                            pkg, name = name, None  # pkg is the module
                        # Find package or module by name and path
                        fp, filename, desc = imp.find_module(pkg, paths)
                        # full dotted name of package to load
                        pname = pkg if not pname else '%s.%s' % (pname, pkg)
                        LOGGER.debug('package name: %s', pname)
                        # try to load the package or module
                        try:
                            mod = imp.load_module(pname, fp, filename, desc)
                        finally:
                            if fp:
                                fp.close()
                        # append package paths for imp.find_module
                        if name:
                            paths = mod.__path__
        formulas = {}  # an empty list of formulas
        formula_param = self.parameters  # formulas key
        # FYI: iterating over dictionary is equivalent to iterkeys()
        if isinstance(formula_param, (list, tuple, dict)):
            # iterate through formulas
            for f in formula_param:
                formulas[f] = getattr(mod, f)
        elif isinstance(formula_param, basestring):
            # only one formula
            # FYI: use basestring to test for str and unicode
            # SEE: http://docs.python.org/2/library/functions.html#basestring
            formulas[formula_param] = getattr(mod, formula_param)
        else:
            # autodetect formulas assuming first letter is f
            formulas = {f: getattr(mod, f) for f in dir(mod) if f[:2] == 'f_'}
        if not len(formulas):
            for f in dir(mod):
                mod_attr = getattr(mod, f)
                if inspect.isfunction(mod_attr):
                    formulas[f] = mod_attr
        return formulas