I ii(RdZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZddlmZddlmZdd lmZdd lmZdd lmZdd lmZmZdd lmZej<eZ dZ!ddZ"GddZ#Gdde#Z$Gdde$Z%GddZ&Gdde#Z'y)zCache Management) annotationsN)Path)Any)Taginterpreter_nameinterpreter_version)canonicalize_name)InvalidWheelFilename) DirectUrl)Link)Wheel) TempDirectory tempdir_kinds) path_to_urlz origin.jsonctj|ddd}tj|j dj S)z'Return a stable sha224 of a dictionary.T),:) sort_keys separators ensure_asciiascii)jsondumpshashlibsha224encode hexdigest)dss Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pip/_internal/cache.py _hash_dictr!s7 1$OA >>!((7+ , 6 6 88cTeZdZdZdfd ZddZd dZd dZ d dZxZ S) CachezuAn abstract class - provides cache directories for data from links :param cache_dir: The root of the cache. c~t||r!tjj |sJ|xsd|_yN)super__init__ospathisabs cache_dirselfr, __class__s r r(zCache.__init__'s2  i 888"*dr"c(d|ji}|j%|j|j||j<|jr|j|d<t |d<t |d<t |}|dd|dd|dd|ddg}|S) z> %$))*?(, Idnn %  % %(,(B(BIn %)9(: $%+>+@ '( I& VAa[&1+vabzB r"c|j xs| xs| }|rgS|j|}tjj |r%tj |Dcgc]}||fc}SgScc}wr&)r,get_path_for_linkr)r*isdirlistdir)r.r:canonical_package_name can_not_cacher* candidates r _get_candidateszCache._get_candidatesMsq NN*T2H.HTPTH I%%d+ 77== 79zz$7GH)Y%H H Is# A3ct)z5Return a directory to store cached items in for link.NotImplementedErrorr.r:s r r@zCache.get_path_for_linkWs !##r"ct)zaReturns a link to a cached item if it exists, otherwise returns the passed link. rH)r.r: package_namesupported_tagss r getz Cache.get[s "##r"r,strreturnNone)r:r rQz list[str])r:r rCrPrQz list[Any]r:r rQrPr:r rL str | NonerM list[Tag]rQr ) __name__ __module__ __qualname____doc__r(r>rFr@rN __classcell__r/s@r r$r$!sH + B$ $ $! $" $  $r"r$cDeZdZdZdfd ZddZ ddZxZS)SimpleWheelCachez&A cache of wheels for future installs.c$t||yr&)r'r(r-s r r(zSimpleWheelCache.__init__js #r"c|j|}|jsJtjj|jdg|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*join)r.r:r=s r r@z"SimpleWheelCache.get_path_for_linkms>**40~~~ww||DNNH=u==r"cg}|s|St|}|j||D]n\}} t|}|j|k7rt j d|||:|j|sL|j|j|||fp|s|St|\} }}tttjj||S#t$rYwxYw)NzWIgnoring cached wheel %s for %s as it does not match the expected distribution name %s.)r rFr r nameloggerdebug supportedappendsupport_index_minminr rr)r*rb) r.r:rLrM candidatesrC wheel_name wheel_dirwheel_s r rNzSimpleWheelCache.gets  K!22   ++N; # 2K#&z? :yK Y CDEE5(  s C C&%C&rOrSrT)rWrXrYrZr(r@rNr[r\s@r r^r^gs@0$>()F)F!)F" )F  )Fr"r^c$eZdZdZdfd ZxZS)EphemWheelCachezBA SimpleWheelCache that creates it's own temporary cache directorycttjd|_t||jj y)NT)kindglobally_managed)rrEPHEM_WHEEL_CACHE _temp_dirr'r(r*)r.r/s r r(zEphemWheelCache.__init__s4&00!  ,,-r")rQrR)rWrXrYrZr(r[r\s@r rqrqsL..r"rqceZdZ ddZy) CacheEntrycv||_||_d|_t|jjj t z }|jr, tj|jd|_yy#t$r,}tjd||j|Yd}~yd}~wwxYw)Nutf-8encodingz7Ignoring invalid cache entry origin file %s for %s (%s))r: persistentoriginr file_pathparentORIGIN_JSON_NAMEexistsr from_json read_text Exceptionrewarningfilename)r.r:r}origin_direct_url_pathes r r(zCacheEntry.__init__s  $(, !%dii&9&9!:!A!ADT!T ! ( ( * '11*44g4F  +  M*MM  s*B B8 "B33B8N)r:r r}bool)rWrXrYr(r"r rxrxsr"rxcveZdZdZdfd Zd dZd dZ d dZ d dZe d dZ xZ S) 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. cbt||t||_t |_yr&)r'r(r^ _wheel_cacherq _ephem_cacher-s r r(zWheelCache.__init__s( #,Y7+-r"c8|jj|Sr&)rr@rJs r r@zWheelCache.get_path_for_link  22488r"c8|jj|Sr&)rr@rJs r get_ephem_path_for_linkz"WheelCache.get_ephem_path_for_linkrr"cH|j|||}||S|jSr&)get_cache_entryr:)r.r:rLrM cache_entrys r rNzWheelCache.gets/ **4~N  Kr"c|jj|||}||ur t|dS|jj|||}||ur t|dSy)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:rLrMT)r}FN)rrNrxr)r.r:rLrMretvals r rzWheelCache.get_cache_entrys}""&&%)'   f6 6""&&%)'   f7 7r"ct|tz }|jrl tj|j d}|j |j k7r-tjd|j ||j  |j|jdy#t$r!}tjd||Yd}~Gd}~wwxYw)Nrzr{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.zPCould not read origin file %s in cache entry (%s). Will attempt to overwrite it.) rrrr rrr1rerr write_textto_json)r, download_info origin_pathr~rs r record_download_originz!WheelCache.record_download_origin s9o(88     ",,[-B-BG-B-TU::!2!22NN@ !%))  }446I' 4  s%B11 C:CCrOrSrT)r:r rLrUrMrVrQzCacheEntry | None)r,rPrr rQrR) rWrXrYrZr(r@rrNr staticmethodrr[r\s@r rrs . 99    !  "    !"   8JJr"r)rzdict[str, str]rQrP)(rZ __future__rrrloggingr)pathlibrtypingrpip._vendor.packaging.tagsrrrpip._vendor.packaging.utilsr pip._internal.exceptionsr pip._internal.models.direct_urlr pip._internal.models.linkr pip._internal.models.wheelr pip._internal.utils.temp_dirrrpip._internal.utils.urlsr getLoggerrWrerr!r$r^rqrxrrr"r rs"  QQ995*,E0   8 $ 9 C$C$LCFuCFL .& .0RJRJr"