def _import_modules(dir_path):
    """ Attempts to import modules in the specified directory path.

        `dir_path`
            Base directory path to attempt to import modules.
        """

    def _import_module(module):
        """ Imports the specified module.
            """
        # already loaded, skip
        if module in mods_loaded:
            return False

        __import__(module)
        mods_loaded.append(module)

    mods_loaded = []

    # check if provided path exists
    if not os.path.isdir(dir_path):
        return

    try:
        # update import search path
        sys.path.insert(0, dir_path)

        # check for modules in the dir path
        for entry in os.listdir(dir_path):
            path = os.path.join(dir_path, entry)

            if os.path.isdir(path):  # directory
                _import_module(entry)

            elif _RE_PY_EXT.search(entry):  # python file
                if not _RE_INIT_PY.match(entry):  # exclude init
                    name = _RE_PY_EXT.sub('', entry)
                    _import_module(name)
    finally:
        # remove inserted path
        sys.path.pop(0)
def _import_modules ( dir_path ) : def _import_module ( module ) : if module in mods_loaded : return False __import__ ( module ) mods_loaded . append ( module ) mods_loaded = [ ] if not os . path . isdir ( dir_path ) : return try : sys . path . insert ( 0 , dir_path ) for entry in os . listdir ( dir_path ) : path = os . path . join ( dir_path , entry ) if os . path . isdir ( path ) : _import_module ( entry ) elif _RE_PY_EXT . search ( entry ) : if not _RE_INIT_PY . match ( entry ) : name = _RE_PY_EXT . sub ( '' , entry ) _import_module ( name ) finally : sys . path . pop ( 0 )
Attempts to import modules in the specified directory path.

        `dir_path`
            Base directory path to attempt to import modules.