def module_list(path):
    """
    Return the list containing the names of the modules available in the given
    folder.
    """
    # sys.path has the cwd as an empty string, but isdir/listdir need it as '.'
    if path == '':
        path = '.'

    if os.path.isdir(path):
        folder_list = os.listdir(path)
    elif path.endswith('.egg'):
        try:
            folder_list = [f for f in zipimporter(path)._files]
        except:
            folder_list = []
    else:
        folder_list = []

    if not folder_list:
        return []

    # A few local constants to be used in loops below
    isfile = os.path.isfile
    pjoin = os.path.join
    basename = os.path.basename

    def is_importable_file(path):
        """Returns True if the provided path is a valid importable module"""
        name, extension = os.path.splitext( path )
        return import_re.match(path) and py3compat.isidentifier(name)

    # Now find actual path matches for packages or modules
    folder_list = [p for p in folder_list
                   if isfile(pjoin(path, p,'__init__.py'))
                   or is_importable_file(p) ]

    return [basename(p).split('.')[0] for p in folder_list]
Return the list containing the names of the modules available in the given
    folder.