U 巀g(@s*dZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z ddl m Z mZmZddlmZddlmZddlmZdd lmZdd lmZdd lmZmZdd lmZee Z!d Z"e e#e#fe#dddZ$GdddZ%Gddde%Z&Gddde&Z'GdddZ(Gddde%Z)dS)zCache Management N)Path)AnyDictListOptional)Taginterpreter_nameinterpreter_version)canonicalize_name)InvalidWheelFilename) DirectUrl)Link)Wheel) TempDirectory tempdir_kinds) path_to_urlz origin.json)dreturncCs&tj|dddd}t|dS)z'Return a stable sha224 of a dictionary.T),:) sort_keys separators ensure_asciiascii)jsondumpshashlibsha224encode hexdigest)rsr!A/opt/hc_python/lib/python3.8/site-packages/pip/_internal/cache.py _hash_dictsr#cs~eZdZdZeddfdd ZeeedddZeeee d d d Z eedd d Z ee eee edddZZS)CachezuAn abstract class - provides cache directories for data from links :param cache_dir: The root of the cache. N cache_dirrcs,t|rtj|st|p$d|_dSN)super__init__ospathisabsAssertionErrorr&selfr& __class__r!r"r)&s zCache.__init__linkrcCsd|ji}|jdk r*|jdk r*|j||j<|jr:|j|d<t|d<t|d<t|}|dd|dd|dd|ddg}|S) zSsz)Cache._get_candidates..)r&get_path_for_linkr*r+isdirlistdir)r/r3rA can_not_cacher!rDr"_get_candidatesLs  zCache._get_candidatescCs tdS)z5Return a directory to store cached items in for link.NNotImplementedErrorr/r3r!r!r"rFVszCache.get_path_for_linkr3 package_namesupported_tagsrcCs tdS)zaReturns a link to a cached item if it exists, otherwise returns the passed link. NrK)r/r3rOrPr!r!r"getZs z Cache.get)__name__ __module__ __qualname____doc__strr)r rr@rrJrFrrrQ __classcell__r!r!r0r"r$ s! r$csTeZdZdZeddfdd ZeedddZeeee e ed d d Z Z S) SimpleWheelCachez&A cache of wheels for future installs.Nr%cst|dSr')r(r)r.r0r!r"r)iszSimpleWheelCache.__init__r2cCs*||}|jsttjj|jdf|S)aReturn a directory to store cached wheels for link Because there are M wheels for any one sdist, we provide a directory to cache them in, and then consult that directory when looking up cache hits. We only insert things into the cache if they have plausible version numbers, so that we don't contaminate the cache with things that were not unique. E.g. ./package might have dozens of installs done for it and build a version of 0.0...and if we built and cached a wheel, we'd end up using the same wheel even if the source has been edited. :param link: The link of the sdist for which this will cache wheels. wheels)r@r&r-r*r+join)r/r3r?r!r!r"rFls  z"SimpleWheelCache.get_path_for_linkrNc Csg}|s |St|}|||D]p\}}z t|}Wntk rLYq YnXt|j|krntd|||q ||szq || |||fq |s|St |\} }}t t t j||S)NzWIgnoring cached wheel %s for %s as it does not match the expected distribution name %s.)r rJrr nameloggerdebug supportedappendsupport_index_minminr rr*r+rZ) r/r3rOrP candidatesrA wheel_name wheel_dirwheel_r!r!r"rQs:   zSimpleWheelCache.get) rRrSrTrUrVr)r rFrrrrQrWr!r!r0r"rXfsrXcs&eZdZdZddfdd ZZS)EphemWheelCachezBA SimpleWheelCache that creates it's own temporary cache directoryN)rcs$ttjdd|_t|jjdS)NT)kindglobally_managed)rrEPHEM_WHEEL_CACHE _temp_dirr(r)r+)r/r0r!r"r)s zEphemWheelCache.__init__)rRrSrTrUr)rWr!r!r0r"rgsrgc@seZdZeedddZdS) CacheEntry)r3 persistentc Cs~||_||_d|_t|jjjt}|rzzt |j dd|_Wn4t k rx}zt d||j|W5d}~XYnXdS)Nutf-8encodingz7Ignoring invalid cache entry origin file %s for %s (%s))r3rmoriginr file_pathparentORIGIN_JSON_NAMEexistsr from_json read_text Exceptionr\warningfilename)r/r3rmorigin_direct_url_pather!r!r"r)s  zCacheEntry.__init__N)rRrSrTr boolr)r!r!r!r"rlsrlcseZdZdZeddfdd ZeedddZeedd d Zee ee e ed d d Z ee ee e e e d ddZeeeddddZZS) WheelCachezWraps EphemWheelCache and SimpleWheelCache into a single Cache This Cache allows for gracefully degradation, using the ephem wheel cache when a certain link is not found in the simple wheel cache first. Nr%cs"t|t||_t|_dSr')r(r)rX _wheel_cacherg _ephem_cacher.r0r!r"r)s  zWheelCache.__init__r2cCs |j|Sr')rrFrMr!r!r"rFszWheelCache.get_path_for_linkcCs |j|Sr')rrFrMr!r!r"get_ephem_path_for_linksz"WheelCache.get_ephem_path_for_linkrNcCs ||||}|dkr|S|jSr')get_cache_entryr3)r/r3rOrP cache_entryr!r!r"rQszWheelCache.getcCsP|jj|||d}||k r&t|ddS|jj|||d}||k rLt|ddSdS)zReturns a CacheEntry with a link to a cached item if it exists or None. The cache entry indicates if the item was found in the persistent or ephemeral cache. )r3rOrPT)rmFN)rrQrlr)r/r3rOrPretvalr!r!r"rs   zWheelCache.get_cache_entry)r& download_inforc Cst|t}|r|zt|jdd}Wn0tk rZ}ztd||W5d}~XYn"X|j |j kr|td|j ||j |j | dddS)NrnrozPCould not read origin file %s in cache entry (%s). Will attempt to overwrite it.zOrigin URL %s in cache entry %s does not match download URL %s. This is likely a pip bug or a cache corruption issue. Will overwrite it with the new value.) rrtrur rvrwrxr\ryr4 write_textto_json)r&r origin_pathrqr|r!r!r"record_download_origin s$  z!WheelCache.record_download_origin)rRrSrTrUrVr)r rFrrrrrQrlr staticmethodr rrWr!r!r0r"r~s   r~)*rUrrloggingr*pathlibrtypingrrrrZpip._vendor.packaging.tagsrrr Zpip._vendor.packaging.utilsr pip._internal.exceptionsr pip._internal.models.direct_urlr pip._internal.models.linkr pip._internal.models.wheelrpip._internal.utils.temp_dirrrpip._internal.utils.urlsr getLoggerrRr\rtrVr#r$rXrgrlr~r!r!r!r"s,        FF