U n a.0@s*dZddlZddlZddlZddlZddlmZmZddlm Z ddl m Z ddl m Z ddlmZddlmZmZdd lmZdd lmZerdd lmZmZmZmZmZdd lmZdd lmZe e!Z"ddZ#Gddde$Z%Gddde%Z&Gddde&Z'Gddde$Z(Gddde%Z)dS)zCache Management N)interpreter_nameinterpreter_version)canonicalize_name)InvalidWheelFilename)Link)Wheel) TempDirectory tempdir_kinds)MYPY_CHECK_RUNNING) path_to_url)OptionalSetListAnyDict)Tag) FormatControlcCs&tj|dddd}t|dS)z'Return a stable sha224 of a dictionary.T),:) sort_keys separators ensure_asciiascii)jsondumpshashlibsha224encode hexdigest)dsr!TC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_internal\cache.py _hash_dict sr#csPeZdZdZfddZddZddZdd 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) csXtt||r"tj|s"t|p(d|_||_||_ ddh}|j ||ksTtdS)Nsourcebinary) superr$__init__ospathisabsAssertionError cache_dirformat_controlallowed_formatsunion)selfr-r.r/_valid_formats __class__r!r"r(2s zCache.__init__cCs|jg}|jdk r4|jdk r4|d|j|jgd|}t|}|dd|dd|dd|ddg}|S)zGet parts of part that must be os.path.joined with cache_dir Legacy cache key (pip < 20) for compatibility with older caches. N=#) url_without_fragment hash_namehashappendjoinrrrr)r1link key_partskey_urlhashedpartsr!r!r"_get_cache_path_parts_legacy=s  ,z"Cache._get_cache_path_parts_legacycCsd|ji}|jdk r*|jdk r*|j||j<|jr:|j|d<t|d<t|d<t|}|dd|dd|dd|ddg}|S) zEGet parts of part that must be os.path.joined with cache_dir urlN subdirectoryrrr7r8r9)r:r;r<subdirectory_fragmentrrr#)r1r?r@rBrCr!r!r"_get_cache_path_partsYs     ,zCache._get_cache_path_partsc Cs|j p| p| }|rgS|j|}|j|s8gSg}||}tj|rpt |D]}| ||fq\| |}tj|rt |D]}| ||fq|SN) r-r.get_allowed_formatsr/ intersectionget_path_for_linkr)r*isdirlistdirr=get_path_for_link_legacy) r1r?canonical_package_name can_not_cacheformats candidatesr* candidate legacy_pathr!r!r"_get_candidates|s,     zCache._get_candidatescCs tdSrINotImplementedErrorr1r?r!r!r"rOszCache.get_path_for_link_legacycCs tdS)z>Return a directory to store cached items in for link. NrWrYr!r!r"rLszCache.get_path_for_linkcCs tdS)zaReturns a link to a cached item if it exists, otherwise returns the passed link. NrW)r1r? package_namesupported_tagsr!r!r"gets z Cache.get) __name__ __module__ __qualname____doc__r(rDrHrVrOrLr\ __classcell__r!r!r3r"r$'s #r$cs8eZdZdZfddZddZddZdd ZZS) SimpleWheelCachez+A cache of wheels for future installs. cstt|||dhdSNr&)r'rbr(r1r-r.r3r!r"r(s  zSimpleWheelCache.__init__cCs ||}tjj|jdf|S)Nwheels)rDr)r*r>r-r1r?rCr!r!r"rOs z)SimpleWheelCache.get_path_for_link_legacycCs ||}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. re)rHr)r*r>r-rfr!r!r"rLs z"SimpleWheelCache.get_path_for_linkc Csg}|s |St|}|||D]t\}}z t|}Wntk rLYq YnXt|j|krrtd|||q ||s~q | | |||fq |s|St |\} }}t t tj||S)NzWIgnoring cached wheel {} for {} as it does not match the expected distribution name {}.)rrVrrnameloggerdebugformat supportedr=support_index_minminrr r)r*r>) r1r?rZr[rSrP wheel_name wheel_dirwheel_r!r!r"r\sB    zSimpleWheelCache.get) r]r^r_r`r(rOrLr\rar!r!r3r"rbs  rbcs eZdZdZfddZZS)EphemWheelCachezGA SimpleWheelCache that creates it's own temporary cache directory cs*ttjdd|_tt||jj|dS)NT)kindglobally_managed)rr EPHEM_WHEEL_CACHE _temp_dirr'rrr(r*)r1r.r3r!r"r(s zEphemWheelCache.__init__)r]r^r_r`r(rar!r!r3r"rrsrrc@seZdZddZdS) CacheEntrycCs||_||_dSrI)r? persistent)r1r?rxr!r!r"r(szCacheEntry.__init__N)r]r^r_r(r!r!r!r"rwsrwcsHeZdZdZfddZddZddZdd Zd d Zd d Z Z 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||_dSrc)r'ryr(rb _wheel_cacherr _ephem_cacherdr3r!r"r("s  zWheelCache.__init__cCs |j|SrI)rzrOrYr!r!r"rO*sz#WheelCache.get_path_for_link_legacycCs |j|SrI)rzrLrYr!r!r"rL.szWheelCache.get_path_for_linkcCs |j|SrI)r{rLrYr!r!r"get_ephem_path_for_link2sz"WheelCache.get_ephem_path_for_linkcCs ||||}|dkr|S|jSrI)get_cache_entryr?)r1r?rZr[ cache_entryr!r!r"r\6szWheelCache.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. )r?rZr[T)rxFN)rzr\rwr{)r1r?rZr[retvalr!r!r"r}Bs   zWheelCache.get_cache_entry) r]r^r_r`r(rOrLr|r\r}rar!r!r3r"rys  ry)*r`rrloggingr)pip._vendor.packaging.tagsrrpip._vendor.packaging.utilsrpip._internal.exceptionsrpip._internal.models.linkrpip._internal.models.wheelrpip._internal.utils.temp_dirrr pip._internal.utils.typingr pip._internal.utils.urlsr typingr r rrrr#pip._internal.models.format_controlr getLoggerr]rhr#objectr$rbrrrwryr!r!r!r"s0          R