(scripts)
return "\n".join(msg_lines)
Determine if any scripts are not on PATH and format a warning.

    Returns a warning message if one or more scripts are not on PATH,
    otherwise None.
Determine if any scripts are not on PATH and format a warning.
Determine if any scripts are not on PATH and format a warning .
def message_about_scripts_not_on_PATH(scripts):
    # type: (Sequence[str]) -> Optional[str]
    """Determine if any scripts are not on PATH and format a warning.

    Returns a warning message if one or more scripts are not on PATH,
    otherwise None.
    """
    if not scripts:
        return None

    # Group scripts by the path they were installed in
    grouped_by_dir = collections.defaultdict(set)  # type: Dict[str, set]
    for destfile in scripts:
        parent_dir = os.path.dirname(destfile)
        script_name = os.path.basename(destfile)
        grouped_by_dir[parent_dir].add(script_name)

    # We don't want to warn for directories that are on PATH.
    not_warn_dirs = [
        os.path.normcase(i).rstrip(os.sep) for i in
        os.environ.get("PATH", "").split(os.pathsep)
    ]
    # If an executable sits with sys.executable, we don't warn for it.
    #     This covers the case of venv invocations without activating the venv.
    not_warn_dirs.append(os.path.normcase(os.path.dirname(sys.executable)))
    warn_for = {
        parent_dir: scripts for parent_dir, scripts in grouped_by_dir.items()
        if os.path.normcase(parent_dir) not in not_warn_dirs
    }
    if not warn_for:
        return None

    # Format a message
    msg_lines = []
    for parent_dir, scripts in warn_for.items():
        sorted_scripts = sorted(scripts)  # type: List[str]
        if len(sorted_scripts) == 1:
            start_text = "script {} is".format(sorted_scripts[0])
        else:
            start_text = "scripts {} are".format(
                ", ".join(sorted_scripts[:-1]) + " and " + sorted_scripts[-1]
            )

        msg_lines.append(
            "The {} installed in '{}' which is not on PATH."
            .format(start_text, parent_dir)
        )

    last_line_fmt = (
        "Consider adding {} to PATH or, if you prefer "
        "to suppress this warning, use --no-warn-script-location."
    )
    if len(msg_lines) == 1:
        msg_lines.append(last_line_fmt.format("this directory"))
    else:
        msg_lines.append(last_line_fmt.format("these directories"))

    # Returns the formatted multiline message
    return "\n".join(msg_lines)
def message_about_scripts_not_on_PATH ( scripts ) : # type: (Sequence[str]) -> Optional[str] if not scripts : return None # Group scripts by the path they were installed in grouped_by_dir = collections . defaultdict ( set ) # type: Dict[str, set] for destfile in scripts : parent_dir = os . path . dirname ( destfile ) script_name = os . path . basename ( destfile ) grouped_by_dir [ parent_dir ] . add ( script_name ) # We don't want to warn for directories that are on PATH. not_warn_dirs = [ os . path . normcase ( i ) . rstrip ( os . sep ) for i in os . environ . get ( "PATH" , "" ) . split ( os . pathsep ) ] # If an executable sits with sys.executable, we don't warn for it. #     This covers the case of venv invocations without activating the venv. not_warn_dirs . append ( os . path . normcase ( os . path . dirname ( sys . executable ) ) ) warn_for = { parent_dir : scripts for parent_dir , scripts in grouped_by_dir . items ( ) if os . path . normcase ( parent_dir ) not in not_warn_dirs } if not warn_for : return None # Format a message msg_lines = [ ] for parent_dir , scripts in warn_for . items ( ) : sorted_scripts = sorted ( scripts ) # type: List[str] if len ( sorted_scripts ) == 1 : start_text = "script {} is" . format ( sorted_scripts [ 0 ] ) else : start_text = "scripts {} are" . format ( ", " . join ( sorted_scripts [ : - 1 ] ) + " and " + sorted_scripts [ - 1 ] ) msg_lines . append ( "The {} installed in '{}' which is not on PATH." . format ( start_text , parent_dir ) ) last_line_fmt = ( "Consider adding {} to PATH or, if you prefer " "to suppress this warning, use --no-warn-script-location." ) if len ( msg_lines ) == 1 : msg_lines . append ( last_line_fmt . format ( "this directory" ) ) else : msg_lines . append ( last_line_fmt . format ( "these directories" ) ) # Returns the formatted multiline message return "\n" . join ( msg_lines )