#NEWLINE# def pip_version_check( session ) : #NEWLINE# #INDENT# "Check for an update for pip.\n\n    Limit the frequency of checks to once per week. State is stored either in\n    the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix\n    of the pip script path.\n    " #NEWLINE# import pip #NEWLINE# pypi_version = None #NEWLINE# try : #NEWLINE# #INDENT# state = load_selfcheck_statefile ( ) #NEWLINE# current_time = datetime . datetime . utcnow ( ) #NEWLINE# if ( ( 'last_check' in state . state ) and ( 'pypi_version' in state . state ) ) : #NEWLINE# #INDENT# last_check = datetime . datetime . strptime ( state . state [ 'last_check' ] , SELFCHECK_DATE_FMT ) #NEWLINE# if ( total_seconds ( ( current_time - last_check ) ) < ( ( ( 7 * 24 ) * 60 ) * 60 ) ) : #NEWLINE# #INDENT# pypi_version = state . state [ 'pypi_version' ] #NEWLINE# #UNINDENT# #UNINDENT# if ( remote_version is None ) : #NEWLINE# #INDENT# resp = session . get ( PyPI . pip_json_url , headers = { #NEWLINE# #INDENT# 'Accept' : 'application/json' , #NEWLINE# #UNINDENT# } ) #NEWLINE# resp . raise_for_status ( ) #NEWLINE# pypi_version = [ v for v in sorted ( list ( resp . json ( ) [ 'releases' ] ) , key = packaging_version . parse ) if ( not packaging_version . parse ( v ) . is_prerelease ) ] [ ( - 1 ) ] #NEWLINE# state . save ( pypi_version , current_time ) #NEWLINE# #UNINDENT# pip_version = packaging_version . parse ( pip . __version__ ) #NEWLINE# remote_version = packaging_version . parse ( pypi_version ) #NEWLINE# if ( ( pip_version < remote_version ) and ( pip_version . base_version != remote_version . base_version ) ) : #NEWLINE# #INDENT# logger . warning ( ( "You are using pip version %s, however version %s is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command." % ( pip . __version__ , pypi_version ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . debug ( 'There was an error checking the latest version of pip' , exc_info = True )