o Ec$@s dZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z m Z mZddlmZddlmZddlmZddlmZdd lmZdd lmZmZdd lmZeeZ d ee!e!fd e!fddZ"GdddZ#Gddde#Z$Gddde$Z%GdddZ&Gddde#Z'dS)zCache Management N)AnyDictListOptionalSet)Taginterpreter_nameinterpreter_version)canonicalize_name)InvalidWheelFilename) FormatControl)Link)Wheel) TempDirectory tempdir_kinds) path_to_urldreturncCs&tj|dddd}t|dS)z'Return a stable sha224 of a dictionary.T),:)Z sort_keysZ separatorsZ ensure_asciiascii)jsondumpshashlibZsha224encodeZ hexdigest)rsrF/opt/alt/python310/lib/python3.10/site-packages/pip/_internal/cache.py _hash_dictsrcseZdZdZdededeeddffdd Zd ede efd d Z d ed ede e fd dZ d edefddZ d edeede edefddZZS)CacheanAn abstract class - provides cache directories for data from links :param cache_dir: The root of the cache. :param format_control: An object of FormatControl class to limit binaries being read from the cache. :param allowed_formats: which formats of files the cache should store. ('binary' and 'source' are the only allowed values) cache_dirformat_controlallowed_formatsrNcs,t|pd|_||_||_ddh}dS)Nsourcebinary)super__init__r r!r")selfr r!r"Z_valid_formats __class__rrr&(s   zCache.__init__linkcCsd|ji}|jdur|jdur|j||j<|jr|j|d<t|d<t|d<t|}|dd|dd|dd|ddg}|S) z)zaReturns a link to a cached item if it exists, otherwise returns the passed link. r?)r'r*rBrCrrrgetis z Cache.get)__name__ __module__ __qualname____doc__strr rr&r rr1rr=r5rrrD __classcell__rrr(rrs.  !rcsbeZdZdZdededdffdd Zdedefd d Zded e ed e e defd dZ Z S)SimpleWheelCachez&A cache of wheels for future installs.r r!rNcst||dhdSNr$)r%r&r'r r!r(rrr&xszSimpleWheelCache.__init__r*cCs"||}tjj|jdg|RS)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. Zwheels)r1r6r7joinr )r'r*r0rrrr5{s z"SimpleWheelCache.get_path_for_linkrBrCc Csg}|s|St|}|||D]5\}}zt|}Wn ty#Yqwt|j|kr4td|||q||s:q|| |||fq|sJ|St |\} }}t t t j||S)NzWIgnoring cached wheel %s for %s as it does not match the expected distribution name %s.)r r=rr nameloggerdebugZ supportedr:Zsupport_index_minminr rr6r7rN) r'r*rBrCr;r2Z wheel_nameZ wheel_dirZwheel_rrrrDs<   zSimpleWheelCache.get)rErFrGrHrIr r&r r5rrrrDrJrrr(rrKusrKcs*eZdZdZdeddffdd ZZS)EphemWheelCachezBA SimpleWheelCache that creates it's own temporary cache directoryr!rNcs&ttjdd|_t|jj|dS)NT)kindZglobally_managed)rrZEPHEM_WHEEL_CACHEZ _temp_dirr%r&r7)r'r!r(rrr&s zEphemWheelCache.__init__)rErFrGrHr r&rJrrr(rrTsrTc@seZdZdedefddZdS) CacheEntryr* persistentcCs||_||_dSr3)r*rW)r'r*rWrrrr&s zCacheEntry.__init__N)rErFrGr boolr&rrrrrVs rVc seZdZdZdededdffdd Zdedefd d Zdedefd d Z ded e ede e defddZ ded e ede e de efddZZS) 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. r r!rNcs,t||dht|||_t||_dSrL)r%r&rK _wheel_cacherT _ephem_cacherMr(rrr&s zWheelCache.__init__r*cC |j|Sr3)rZr5rArrrr5 zWheelCache.get_path_for_linkcCr\r3)r[r5rArrrget_ephem_path_for_linkr]z"WheelCache.get_ephem_path_for_linkrBrCcCs ||||}|dur |S|jSr3)get_cache_entryr*)r'r*rBrCZ cache_entryrrrrDszWheelCache.getcCsP|jj|||d}||urt|ddS|jj|||d}||ur&t|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. )r*rBrCT)rWFN)rZrDrVr[)r'r*rBrCZretvalrrrr_s   zWheelCache.get_cache_entry)rErFrGrHrIr r&r r5r^rrrrDrVr_rJrrr(rrYs.  rY)(rHrrZloggingr6typingrrrrrZpip._vendor.packaging.tagsrrr Zpip._vendor.packaging.utilsr Zpip._internal.exceptionsr Z#pip._internal.models.format_controlr Zpip._internal.models.linkr Zpip._internal.models.wheelrZpip._internal.utils.temp_dirrrZpip._internal.utils.urlsrZ getLoggerrErPrIrrrKrTrVrYrrrrs*       XF