def import_modules(modnames, pkg, msg='Failed to import {module}', log=lgr.debug):
    "Helper to import a list of modules without failing if N/A\n\n    Parameters\n    ----------\n    modnames: list of str\n      List of module names to import\n    pkg: str\n      Package under which to import\n    msg: str, optional\n      Message template for .format() to log at DEBUG level if import fails.\n      Keys {module} and {package} will be provided and ': {exception}' appended\n    log: callable, optional\n      Logger call to use for logging messages\n    "
    from importlib import import_module
    _globals = globals()
    mods_loaded = []
    if (pkg and (not (pkg in sys.modules))):
        import_module(pkg)
    for modname in modnames:
        try:
            _globals[modname] = mod = import_module('.{}'.format(modname), pkg)
            mods_loaded.append(mod)
        except Exception as exc:
            from datalad.support.exceptions import CapturedException
            ce = CapturedException(exc)
            log((msg + ': {exception}').format(module=modname, package=pkg, exception=ce.message))
    return mods_loaded
Helper to import a list of modules without failing if N/A

Parameters
----------
modnames: list of str
  List of module names to import
pkg: str
  Package under which to import
msg: str, optional
  Message template for .format() to log at DEBUG level if import fails.
  Keys {module} and {package} will be provided and ': {exception}' appended
log: callable, optional
  Logger call to use for logging messages
def import_modules(modnames, pkg, msg='Failed to import {module}', log=lgr.debug):
    "Helper to import a list of modules without failing if N/A\n\n    Parameters\n    ----------\n    modnames: list of str\n      List of module names to import\n    pkg: str\n      Package under which to import\n    msg: str, optional\n      Message template for .format() to log at DEBUG level if import fails.\n      Keys {module} and {package} will be provided and ': {exception}' appended\n    log: callable, optional\n      Logger call to use for logging messages\n    "
    from importlib import import_module
    _globals = globals()
    mods_loaded = []
    if (pkg and (not (pkg in sys.modules))):
        import_module(pkg)
    for modname in modnames:
        try:
            _globals[modname] = mod = import_module('.{}'.format(modname), pkg)
            mods_loaded.append(mod)
        except Exception as exc:
            from datalad.support.exceptions import CapturedException
            ce = CapturedException(exc)
            log((msg + ': {exception}').format(module=modname, package=pkg, exception=ce.message))
    return mods_loaded