U ÀÒ.e³ ã@sþdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZddlmZdd lmZmZer°dd lmZmZmZmZdd lmZdd lmZe e¡ZGd d„de ƒZ!Gdd„de!ƒZ"Gdd„de"ƒZ#Gdd„de!ƒZ$dS)zCache Management éN)Úcanonicalize_name)ÚLink)Ú expanduser)Ú TempDirectory)ÚMYPY_CHECK_RUNNING)Ú path_to_url)ÚInvalidWheelFilenameÚWheel)ÚOptionalÚSetÚListÚAny)Ú FormatControl)Ú Pep425TagcsPeZdZdZ‡fdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z ‡Z S)ÚCachea‚An 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) cs8tt|ƒ ¡|rt|ƒnd|_||_||_ddh}dS)NÚsourceÚbinary)ÚsuperrÚ__init__rÚ cache_dirÚformat_controlÚallowed_formats)Ú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|jg¡¡d |¡}t | ¡¡ ¡}|dd…|dd…|dd…|dd…g}|S)zEGet parts of part that must be os.path.joined with cache_dir Nú=ú#ééé) Zurl_without_fragmentZ hash_nameÚhashÚappendÚjoinÚhashlibZsha224ÚencodeZ hexdigest)rÚlinkZ key_partsZkey_urlZhashedÚpartsrrrÚ_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 hkr†gWY¢S‚W5d}~XYnXdS©N) rrrZget_allowed_formatsrÚ intersectionÚget_path_for_linkÚosÚlistdirÚOSErrorÚerrnoZENOENTZENOTDIR)rr'Ú package_nameZ can_not_cacheZcanonical_nameZformatsÚrootÚerrrrrÚ_get_candidatesLs(ÿýÿ    zCache._get_candidatescCs tƒ‚dS)z>Return a directory to store cached items in for link. N©ÚNotImplementedError©rr'rrrr,eszCache.get_path_for_linkcCs tƒ‚dS)zaReturns a link to a cached item if it exists, otherwise returns the passed link. Nr5)rr'r1Úsupported_tagsrrrÚgetks z Cache.getcCs$| |¡}tj ||¡}tt|ƒƒSr*)r,r-Úpathr$rr)rr'Ú candidater2r:rrrÚ_link_for_candidatews zCache._link_for_candidatecCsdSr*r©rrrrÚcleanup~sz Cache.cleanup) Ú__name__Ú __module__Ú __qualname__Ú__doc__rr)r4r,r9r<r>Ú __classcell__rrrrrs  rcs0eZdZdZ‡fdd„Zdd„Zdd„Z‡ZS)ÚSimpleWheelCachez+A cache of wheels for future installs. cstt|ƒ ||dh¡dS©Nr)rrDr©rrrrrrr‡s  ÿzSimpleWheelCache.__init__cCs | |¡}tjj|jdf|žŽS)a³Return 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| | |¡|f¡q|sd|S| |t|ƒd¡S)Né)r4r rZ supportedr#Zsupport_index_minr<Úmin)rr'r1r8Z candidatesZ wheel_nameZwheelrrrr9¢s    ÿzSimpleWheelCache.get)r?r@rArBrr,r9rCrrrrrDƒs rDcs(eZdZdZ‡fdd„Zdd„Z‡ZS)ÚEphemWheelCachezGA SimpleWheelCache that creates it's own temporary cache directory cs&tdd�|_tt|ƒ |jj|¡dS)Nzephem-wheel-cache)Zkind)rÚ _temp_dirrrIrr:)rrrrrrÁs   ÿzEphemWheelCache.__init__cCs|j ¡dSr*)rJr>r=rrrr>ÉszEphemWheelCache.cleanup)r?r@rArBrr>rCrrrrrI½s rIcs@eZdZdZ‡fdd„Zdd„Zdd„Zdd „Zd d „Z‡Z S) Ú WheelCachezØWraps 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|ƒ ||dh¡t||ƒ|_t|ƒ|_dSrE)rrKrrDÚ _wheel_cacherIÚ _ephem_cacherFrrrrÕs ÿ zWheelCache.__init__cCs |j |¡Sr*)rLr,r7rrrr,ÝszWheelCache.get_path_for_linkcCs |j |¡Sr*)rMr,r7rrrÚget_ephem_path_for_linkász"WheelCache.get_ephem_path_for_linkcCs0|jj|||d�}||k r|S|jj|||d�S)N)r'r1r8)rLr9rM)rr'r1r8Zretvalrrrr9åsýýzWheelCache.getcCs|j ¡|j ¡dSr*)rLr>rMr=rrrr>ús zWheelCache.cleanup) r?r@rArBrr,rNr9r>rCrrrrrKÎs  rK)%rBr0r%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 getLoggerr?ZloggerÚobjectrrDrIrKrrrrÚs(         f: