def get_public_modules(path, base_package=None):
 result = []
 for (subdir, _, files) in os.walk(path):
  if any([part.startswith('_') for part in subdir.split(os.path.sep)]):
   continue
  (_, rel_dir) = subdir.split(path)
  rel_dir = rel_dir.lstrip(os.path.sep)
  for filename in files:
   if is_valid_module(filename):
    (mod_name, _) = os.path.splitext(filename)
    rel_path = os.path.join(rel_dir, mod_name)
    if (base_package is not None):
     rel_path = os.path.join(base_package, rel_path)
    rel_path = rel_path.replace(os.path.sep, '.')
    if (mod_name == '__init__'):
     result.append(rel_path[:(- len('.__init__'))])
    else:
     result.append(rel_path)
 return result

def get_public_modules ( path , base_package = None ) : result = [ ] for ( subdir , _ , files ) in os . walk ( path ) : if any ( [ part . startswith ( '_' ) for part in subdir . split ( os . path . sep ) ] ) : continue ( _ , rel_dir ) = subdir . split ( path ) rel_dir = rel_dir . lstrip ( os . path . sep ) for filename in files : if is_valid_module ( filename ) : ( mod_name , _ ) = os . path . splitext ( filename ) rel_path = os . path . join ( rel_dir , mod_name ) if ( base_package is not None ) : rel_path = os . path . join ( base_package , rel_path ) rel_path = rel_path . replace ( os . path . sep , '.' ) if ( mod_name == '__init__' ) : result . append ( rel_path [ : ( - len ( '.__init__' ) ) ] ) else : result . append ( rel_path ) return result
get list of all public modules relative to a path .