def get_modules(modulepath):
m = importlib.import_module(modulepath)<EOL>mpath = m.__file__<EOL>ret = set([m])<EOL>if "<STR_LIT>" in mpath.lower():<EOL><INDENT>mpath = os.path.dirname(mpath)<EOL>for module_info in pkgutil.iter_modules([mpath]):<EOL><INDENT>submodulepath = "<STR_LIT:.>".join([modulepath, module_info[<NUM_LIT:1>]])<EOL>if module_info[<NUM_LIT:2>]:<EOL><INDENT>submodules = get_modules(submodulepath)<EOL>ret.update(submodules)<EOL><DEDENT>else:<EOL><INDENT>ret.add(importlib.import_module(submodulepath))<EOL><DEDENT><DEDENT><DEDENT>return ret<EOL>
return all found modules at modulepath (eg, foo.bar) including modulepath module