3 Pfe@sddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZmZddlmZddlmZmZddlmZmZdd lmZd ZejeZGd d d eZGd ddeZ ddZ!ddZ"ddZ#dS))absolute_importN)lockfile)version) total_secondsWINDOWS)PyPI)USER_CACHE_DIRrunning_under_virtualenv) ensure_dirget_installed_version)check_path_ownerz%Y-%m-%dT%H:%M:%SZc@seZdZddZddZdS)VirtualenvSelfCheckStatecCs\tjjtjd|_y&t|j}tj||_ WdQRXWnt t fk rVi|_ YnXdS)Nzpip-selfcheck.json) ospathjoinsysprefixstatefile_pathopenjsonloadstateIOError ValueError)self statefiler/usr/lib/python3.6/outdated.py__init__s  z!VirtualenvSelfCheckState.__init__c Cs:t|jd$}tj|jt|d|dddWdQRXdS)Nw) last_check pypi_versionT,:) sort_keys separators)r"r#)rrrdumpstrftimeSELFCHECK_DATE_FMT)rr! current_timerrrrsave$szVirtualenvSelfCheckState.saveN)__name__ __module__ __qualname__rr*rrrrr s r c@seZdZddZddZdS)GlobalSelfCheckStatecCsbtjjtd|_y,t|j}tj|tj |_ WdQRXWn t t t fk r\i|_ YnXdS)Nzselfcheck.json)rrrrrrrrrrrrrKeyError)rrrrrr3s   zGlobalSelfCheckState.__init__cCsttjj|jsdSttjj|jtj|jztjj|jrft |j}t j |}WdQRXni}|j t |d|tj<t |jd}t j||dddWdQRXWdQRXdS)N)r r!rTr"r#)r$r%)r"r#)r rrdirnamerr rZLockFileexistsrrrr'r(rrr&)rr!r)rrrrrr*=s  zGlobalSelfCheckState.saveN)r+r,r-rr*rrrrr.2s r.cCstr tStSdS)N)r r r.rrrrload_selfcheck_statefileXsr2c CsFddl}y"|jd}|jdo*d|jdkS|jk r@dSXdS)zChecks whether pip was installed by pip This is used not to display the upgrade message when pip is in fact installed by system package manager, such as dnf on Fedora. rNpipZ INSTALLERF) pkg_resourcesZget_distributionZ has_metadataZget_metadata_linesZDistributionNotFound)r4Zdistrrrpip_installed_by_pip_s  r5c CsFtd}|dkrdStj|}d}yt}tjj}d|jkrxd|jkrxtjj|jdt}t ||dkrx|jd}|dkr|j t j dd id }|j d d tt|jd tjdDd}|j||tj|}||kr|j|jkrtrtrd} nd} tjd||| Wn$tk r@tjdddYnXdS)zCheck 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. r3Nr r!<ZAcceptzapplication/json)ZheaderscSsg|]}tj|js|qSr)packaging_versionparseZ is_prerelease).0vrrr sz%pip_version_check..Zreleases)keyz python -m pipzYou are using pip version %s, however version %s is available. You should consider upgrading via the '%s install --upgrade pip' command.z5There was an error checking the latest version of pipT)exc_infoi`'i: )r r9r:r2datetimeZutcnowrZstrptimer(rgetrZ pip_json_urlZraise_for_statussortedlistrr*Z base_versionr5rloggerZwarning Exceptiondebug) ZsessionZinstalled_versionZ pip_versionr!rr)r ZrespZremote_versionZpip_cmdrrrpip_version_checknsL        rJ)$Z __future__rrCrZloggingZos.pathrrZ pip._vendorrZpip._vendor.packagingrr9Z pip.compatrrZ pip.modelsrZ pip.locationsrr Z pip.utilsr r Zpip.utils.filesystemr r(Z getLoggerr+rGobjectr r.r2r5rJrrrrs&      &