U .e @sdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZddlmZdd lmZmZerdd lmZmZmZmZdd lmZdd lmZeeZGd dde Z!Gddde!Z"Gddde"Z#Gddde!Z$dS)zCache Management N)canonicalize_name)Link) expanduser) TempDirectory)MYPY_CHECK_RUNNING) path_to_url)InvalidWheelFilenameWheel)OptionalSetListAny) FormatControl) Pep425TagcsPeZdZdZfddZddZddZdd Zd d Zd d Z ddZ Z S)CacheaAn 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) csLtt||rt|nd|_||_||_ddh}|j||ksHtdS)Nsourcebinary) superr__init__r cache_dirformat_controlallowed_formatsunionAssertionError)selfrrrZ_valid_formats __class__7/usr/lib/python3.8/site-packages/pip/_internal/cache.pyr(s zCache.__init__cCs|jg}|jdk r4|jdk r4|d|j|jgd|}t|}|dd|dd|dd|ddg}|S)zEGet parts of part that must be os.path.joined with cache_dir N=#) Zurl_without_fragmentZ hash_namehashappendjoinhashlibZsha224encodeZ hexdigest)rlinkZ key_partsZkey_urlZhashedpartsrrr_get_cache_path_parts2s ,zCache._get_cache_path_partsc Cs|j p| p| }|rgSt|}|j|}|j|s@gS||}z t|WSt k r}z$|j t j t j hkrgWYSW5d}~XYnXdSN) rrrZget_allowed_formatsr intersectionget_path_for_linkoslistdirOSErrorerrnoZENOENTZENOTDIR)rr) package_nameZ can_not_cacheZcanonical_nameZformatsrooterrrrr_get_candidatesLs(    zCache._get_candidatescCs tdS)z>Return a directory to store cached items in for link. NNotImplementedErrorrr)rrrr.eszCache.get_path_for_linkcCs tdS)zaReturns a link to a cached item if it exists, otherwise returns the passed link. Nr7)rr)r3supported_tagsrrrgetks z Cache.getcCs$||}tj||}tt|Sr,)r.r/pathr&rr)rr) candidater4r<rrr_link_for_candidatews zCache._link_for_candidatecCsdSr,rrrrrcleanup~sz Cache.cleanup) __name__ __module__ __qualname____doc__rr+r6r.r;r>r@ __classcell__rrrrrs  rcs0eZdZdZfddZddZddZZS)SimpleWheelCachez+A cache of wheels for future installs. cstt|||dhdSNr)rrFrrrrrrrrs  zSimpleWheelCache.__init__cCs ||}tjj|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. Zwheels)r+r/r<r&r)rr)r*rrrr.s z"SimpleWheelCache.get_path_for_linkc Csxg}|||D]J}z t|}Wntk r8YqYnX||sFq||||fq|sd|S||t|dS)N)r6r rZ supportedr%Zsupport_index_minr>min)rr)r3r:Z candidatesZ wheel_nameZwheelrrrr;s    zSimpleWheelCache.get)rArBrCrDrr.r;rErrrrrFs rFcs(eZdZdZfddZddZZS)EphemWheelCachezGA SimpleWheelCache that creates it's own temporary cache directory cs&tdd|_tt||jj|dS)Nzephem-wheel-cache)Zkind)r _temp_dirrrKrr<)rrrrrrs   zEphemWheelCache.__init__cCs|jdSr,)rLr@r?rrrr@szEphemWheelCache.cleanup)rArBrCrDrr@rErrrrrKs rKcs@eZdZdZfddZddZddZdd Zd d ZZ 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. cs0tt|||dht|||_t||_dSrG)rrMrrF _wheel_cacherK _ephem_cacherHrrrrs  zWheelCache.__init__cCs |j|Sr,)rNr.r9rrrr.szWheelCache.get_path_for_linkcCs |j|Sr,)rOr.r9rrrget_ephem_path_for_linksz"WheelCache.get_ephem_path_for_linkcCs0|jj|||d}||k r|S|jj|||dS)N)r)r3r:)rNr;rO)rr)r3r:Zretvalrrrr;szWheelCache.getcCs|j|jdSr,)rNr@rOr?rrrr@s zWheelCache.cleanup) rArBrCrDrr.rPr;r@rErrrrrMs  rM)%rDr2r'Zloggingr/Zpip._vendor.packaging.utilsrZpip._internal.models.linkrZpip._internal.utils.compatrZpip._internal.utils.temp_dirrZpip._internal.utils.typingrZpip._internal.utils.urlsrZpip._internal.wheelrr typingr r r r Zpip._internal.indexrZpip._internal.pep425tagsrZ getLoggerrAZloggerobjectrrFrKrMrrrrs(         f: