parameters: (module_root, allowed_modules)
return_statement: return found_modules
docstring: Scan module_root for subdirectories that look like MongoDB modules.
  
      Return a list of imported build.py module objects.
docstring_summary: Scan module_root for subdirectories that look like MongoDB modules.
docstring_tokens: Scan module_root for subdirectories that look like MongoDB modules .
function: def discover_modules(module_root, allowed_modules):
      """Scan module_root for subdirectories that look like MongoDB modules.
  
      Return a list of imported build.py module objects.
      """
      found_modules = []
  
      if allowed_modules is not None:
          allowed_modules = allowed_modules.split(',')
  
      if not os.path.isdir(module_root):
          return found_modules
  
      for name in os.listdir(module_root):
          root = os.path.join(module_root, name)
          if name.startswith('.') or not os.path.isdir(root):
              continue
  
          build_py = os.path.join(root, 'build.py')
          module = None
  
          if allowed_modules is not None and name not in allowed_modules:
              print("skipping module: %s" % (name))
              continue
  
          try:
              print("adding module: %s" % (name))
              fp = open(build_py, "r")
              try:
                  module = imp.load_module("module_" + name, fp, build_py,
                                           (".py", "r", imp.PY_SOURCE))
                  if getattr(module, "name", None) is None:
                      module.name = name
                  found_modules.append(module)
              finally:
                  fp.close()
          except (FileNotFoundError, IOError):
              pass
  
      return found_modules
function_tokens: def discover_modules ( module_root , allowed_modules ) : found_modules = [ ] if allowed_modules is not None : allowed_modules = allowed_modules . split ( ',' ) if not os . path . isdir ( module_root ) : return found_modules for name in os . listdir ( module_root ) : root = os . path . join ( module_root , name ) if name . startswith ( '.' ) or not os . path . isdir ( root ) : continue build_py = os . path . join ( root , 'build.py' ) module = None if allowed_modules is not None and name not in allowed_modules : print ( "skipping module: %s" % ( name ) ) continue try : print ( "adding module: %s" % ( name ) ) fp = open ( build_py , "r" ) try : module = imp . load_module ( "module_" + name , fp , build_py , ( ".py" , "r" , imp . PY_SOURCE ) ) if getattr ( module , "name" , None ) is None : module . name = name found_modules . append ( module ) finally : fp . close ( ) except ( FileNotFoundError , IOError ) : pass return found_modules