pylint/utils/utils.py
def expand_modules(files_or_modules, black_list, black_list_re):
    """take a list of files/modules/packages and return the list of tuple
    (file, module name) which have to be actually checked
    """
    result = []
    errors = []
    for something in files_or_modules:
        if basename(something) in black_list:
            continue
        if _basename_in_blacklist_re(basename(something), black_list_re):
            continue
        if exists(something):
            # this is a file or a directory
            try:
                modname = ".".join(modutils.modpath_from_file(something))
            except ImportError:
                modname = splitext(basename(something))[0]
            if isdir(something):
                filepath = join(something, "__init__.py")
            else:
                filepath = something
        else:
            # suppose it's a module or package
            modname = something
            try:
                filepath = modutils.file_from_modpath(modname.split("."))
                if filepath is None:
                    continue
            except (ImportError, SyntaxError) as ex:
                # FIXME p3k : the SyntaxError is a Python bug and should be
                # removed as soon as possible http://bugs.python.org/issue10588
                errors.append({"key": "fatal", "mod": modname, "ex": ex})
                continue

        filepath = normpath(filepath)
        modparts = (modname or something).split(".")

        try:
            spec = modutils.file_info_from_modpath(modparts, path=sys.path)
        except ImportError:
            # Might not be acceptable, don't crash.
            is_namespace = False
            is_directory = isdir(something)
        else:
            is_namespace = modutils.is_namespace(spec)
            is_directory = modutils.is_directory(spec)

        if not is_namespace:
            result.append(
                {
                    "path": filepath,
                    "name": modname,
                    "isarg": True,
                    "basepath": filepath,
                    "basename": modname,
                }
            )

        has_init = (
            not (modname.endswith(".__init__") or modname == "__init__")
            and basename(filepath) == "__init__.py"
        )

        if has_init or is_namespace or is_directory:
            for subfilepath in modutils.get_module_files(
                dirname(filepath), black_list, list_all=is_namespace
            ):
                if filepath == subfilepath:
                    continue
                if _basename_in_blacklist_re(basename(subfilepath), black_list_re):
                    continue

                modpath = _modpath_from_file(subfilepath, is_namespace)
                submodname = ".".join(modpath)
                result.append(
                    {
                        "path": subfilepath,
                        "name": submodname,
                        "isarg": False,
                        "basepath": filepath,
                        "basename": modname,
                    }
                )
    return result, errors
def expand_modules(files_or_modules, black_list, black_list_re):
    """take a list of files/modules/packages and return the list of tuple
    (file, module name) which have to be actually checked
    """
    result = []
    errors = []
    for something in files_or_modules:
        if basename(something) in black_list:
            continue
        if _basename_in_blacklist_re(basename(something), black_list_re):
            continue
        if exists(something):
            # this is a file or a directory
            try:
                modname = ".".join(modutils.modpath_from_file(something))
            except ImportError:
                modname = splitext(basename(something))[0]
            if isdir(something):
                filepath = join(something, "__init__.py")
            else:
                filepath = something
        else:
            # suppose it's a module or package
            modname = something
            try:
                filepath = modutils.file_from_modpath(modname.split("."))
                if filepath is None:
                    continue
            except (ImportError, SyntaxError) as ex:
                # FIXME p3k : the SyntaxError is a Python bug and should be
                # removed as soon as possible http://bugs.python.org/issue10588
                errors.append({"key": "fatal", "mod": modname, "ex": ex})
                continue

        filepath = normpath(filepath)
        modparts = (modname or something).split(".")

        try:
            spec = modutils.file_info_from_modpath(modparts, path=sys.path)
        except ImportError:
            # Might not be acceptable, don't crash.
            is_namespace = False
            is_directory = isdir(something)
        else:
            is_namespace = modutils.is_namespace(spec)
            is_directory = modutils.is_directory(spec)

        if not is_namespace:
            result.append(
                {
                    "path": filepath,
                    "name": modname,
                    "isarg": True,
                    "basepath": filepath,
                    "basename": modname,
                }
            )

        has_init = (
            not (modname.endswith(".__init__") or modname == "__init__")
            and basename(filepath) == "__init__.py"
        )

        if has_init or is_namespace or is_directory:
            for subfilepath in modutils.get_module_files(
                dirname(filepath), black_list, list_all=is_namespace
            ):
                if filepath == subfilepath:
                    continue
                if _basename_in_blacklist_re(basename(subfilepath), black_list_re):
                    continue

                modpath = _modpath_from_file(subfilepath, is_namespace)
                submodname = ".".join(modpath)
                result.append(
                    {
                        "path": subfilepath,
                        "name": submodname,
                        "isarg": False,
                        "basepath": filepath,
                        "basename": modname,
                    }
                )
    return result, errors
def expand_modules ( files_or_modules , black_list , black_list_re ) : result = [ ] errors = [ ] for something in files_or_modules : if basename ( something ) in black_list : continue if _basename_in_blacklist_re ( basename ( something ) , black_list_re ) : continue if exists ( something ) : # this is a file or a directory try : modname = "." . join ( modutils . modpath_from_file ( something ) ) except ImportError : modname = splitext ( basename ( something ) ) [ 0 ] if isdir ( something ) : filepath = join ( something , "__init__.py" ) else : filepath = something else : # suppose it's a module or package modname = something try : filepath = modutils . file_from_modpath ( modname . split ( "." ) ) if filepath is None : continue except ( ImportError , SyntaxError ) as ex : # FIXME p3k : the SyntaxError is a Python bug and should be # removed as soon as possible http://bugs.python.org/issue10588 errors . append ( { "key" : "fatal" , "mod" : modname , "ex" : ex } ) continue filepath = normpath ( filepath ) modparts = ( modname or something ) . split ( "." ) try : spec = modutils . file_info_from_modpath ( modparts , path = sys . path ) except ImportError : # Might not be acceptable, don't crash. is_namespace = False is_directory = isdir ( something ) else : is_namespace = modutils . is_namespace ( spec ) is_directory = modutils . is_directory ( spec ) if not is_namespace : result . append ( { "path" : filepath , "name" : modname , "isarg" : True , "basepath" : filepath , "basename" : modname , } ) has_init = ( not ( modname . endswith ( ".__init__" ) or modname == "__init__" ) and basename ( filepath ) == "__init__.py" ) if has_init or is_namespace or is_directory : for subfilepath in modutils . get_module_files ( dirname ( filepath ) , black_list , list_all = is_namespace ) : if filepath == subfilepath : continue if _basename_in_blacklist_re ( basename ( subfilepath ) , black_list_re ) : continue modpath = _modpath_from_file ( subfilepath , is_namespace ) submodname = "." . join ( modpath ) result . append ( { "path" : subfilepath , "name" : submodname , "isarg" : False , "basepath" : filepath , "basename" : modname , } ) return result , errors
take a list of files/modules/packages and return the list of tuple
    (file, module name) which have to be actually checked
take a list of files / modules / packages and return the list of tuple ( file module name ) which have to be actually checked