(session, options)
Check for an update for pip.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.
Check for an update for pip.
Check for an update for pip .
def pip_version_check(session, options):
    # type: (PipSession, optparse.Values) -> None
    """Check for an update for pip.

    Limit the frequency of checks to once per week. State is stored either in
    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
    of the pip script path.
    """
    installed_version = get_installed_version("pip")
    if not installed_version:
        return

    pip_version = packaging_version.parse(installed_version)
    pypi_version = None

    try:
        state = SelfCheckState(cache_dir=options.cache_dir)

        current_time = datetime.datetime.utcnow()
        # Determine if we need to refresh the state
        if "last_check" in state.state and "pypi_version" in state.state:
            last_check = datetime.datetime.strptime(
                state.state["last_check"],
                SELFCHECK_DATE_FMT
            )
            if (current_time - last_check).total_seconds() < 7 * 24 * 60 * 60:
                pypi_version = state.state["pypi_version"]

        # Refresh the version if we need to or just see if we need to warn
        if pypi_version is None:
            # Lets use PackageFinder to see what the latest pip version is
            search_scope = make_search_scope(options, suppress_no_index=True)

            # Pass allow_yanked=False so we don't suggest upgrading to a
            # yanked version.
            selection_prefs = SelectionPreferences(
                allow_yanked=False,
                allow_all_prereleases=False,  # Explicitly set to False
            )

            finder = PackageFinder.create(
                search_scope=search_scope,
                selection_prefs=selection_prefs,
                trusted_hosts=options.trusted_hosts,
                session=session,
            )
            candidate = finder.find_candidates("pip").get_best()
            if candidate is None:
                return
            pypi_version = str(candidate.version)

            # save that we've performed a check
            state.save(pypi_version, current_time)

        remote_version = packaging_version.parse(pypi_version)

        local_version_is_older = (
            pip_version < remote_version and
            pip_version.base_version != remote_version.base_version and
            was_installed_by_pip('pip')
        )

        # Determine if our pypi_version is older
        if not local_version_is_older:
            return

        # Advise "python -m pip" on Windows to avoid issues
        # with overwriting pip.exe.
        if WINDOWS:
            pip_cmd = "python -m pip"
        else:
            pip_cmd = "pip"
        logger.warning(
            "You are using pip version %s, however version %s is "
            "available.\nYou should consider upgrading via the "
            "'%s install --upgrade pip' command.",
            pip_version, pypi_version, pip_cmd
        )
    except Exception:
        logger.debug(
            "There was an error checking the latest version of pip",
            exc_info=True,
        )
def pip_version_check ( session , options ) : # type: (PipSession, optparse.Values) -> None installed_version = get_installed_version ( "pip" ) if not installed_version : return pip_version = packaging_version . parse ( installed_version ) pypi_version = None try : state = SelfCheckState ( cache_dir = options . cache_dir ) current_time = datetime . datetime . utcnow ( ) # Determine if we need to refresh the state if "last_check" in state . state and "pypi_version" in state . state : last_check = datetime . datetime . strptime ( state . state [ "last_check" ] , SELFCHECK_DATE_FMT ) if ( current_time - last_check ) . total_seconds ( ) < 7 * 24 * 60 * 60 : pypi_version = state . state [ "pypi_version" ] # Refresh the version if we need to or just see if we need to warn if pypi_version is None : # Lets use PackageFinder to see what the latest pip version is search_scope = make_search_scope ( options , suppress_no_index = True ) # Pass allow_yanked=False so we don't suggest upgrading to a # yanked version. selection_prefs = SelectionPreferences ( allow_yanked = False , allow_all_prereleases = False , # Explicitly set to False ) finder = PackageFinder . create ( search_scope = search_scope , selection_prefs = selection_prefs , trusted_hosts = options . trusted_hosts , session = session , ) candidate = finder . find_candidates ( "pip" ) . get_best ( ) if candidate is None : return pypi_version = str ( candidate . version ) # save that we've performed a check state . save ( pypi_version , current_time ) remote_version = packaging_version . parse ( pypi_version ) local_version_is_older = ( pip_version < remote_version and pip_version . base_version != remote_version . base_version and was_installed_by_pip ( 'pip' ) ) # Determine if our pypi_version is older if not local_version_is_older : return # Advise "python -m pip" on Windows to avoid issues # with overwriting pip.exe. if WINDOWS : pip_cmd = "python -m pip" else : pip_cmd = "pip" logger . warning ( "You are using pip version %s, however version %s is " "available.\nYou should consider upgrading via the " "'%s install --upgrade pip' command." , pip_version , pypi_version , pip_cmd ) except Exception : logger . debug ( "There was an error checking the latest version of pip" , exc_info = True , )