3 (\@sdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl mZddlmZdd lmZmZerdd lmZmZmZmZdd lmZejeZGd d d eZGdddeZ Gddde Z!GdddeZ"dS)zCache Management N)canonicalize_name) path_to_url)Link) expanduser) TempDirectory)MYPY_CHECK_RUNNING)InvalidWheelFilenameWheel)OptionalSetListAny) FormatControlcsPeZdZdZfddZddZddZdd 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|j|rt|nd|_||_||_ddh}|jj||ksHtdS)Nsourcebinary) superr__init__r cache_dirformat_controlallowed_formatsunionAssertionError)selfrrrZ_valid_formats) __class__f/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/cache.pyr$s zCache.__init__cCs|jg}|jdk r4|jdk r4|jdj|j|jgdj|}tj|jj}|dd|dd|dd|ddg}|S)zEGet parts of part that must be os.path.joined with cache_dir N=#) url_without_fragment hash_namehashappendjoinhashlibsha224encode hexdigest)rlink key_partskey_urlhashedpartsrrr_get_cache_path_parts.s ,zCache._get_cache_path_partscCs|j p| p| }|rgSt|}|jj|}|jj|s@gS|j|}y tj|St k r}z|j t j t j hkr|gSWYdd}~XnXdS)N) rrrZget_allowed_formatsr intersectionget_path_for_linkoslistdirOSErrorerrnoENOENTENOTDIR)rr+ package_nameZ can_not_cachecanonical_nameformatsrooterrrrr_get_candidatesHs"   zCache._get_candidatescCs tdS)z>Return a directory to store cached items in for link. N)NotImplementedError)rr+rrrr2aszCache.get_path_for_linkcCs tdS)zaReturns a link to a cached item if it exists, otherwise returns the passed link. N)r?)rr+r9rrrgetgsz Cache.getcCs$|j|}tjj||}tt|S)N)r2r3pathr&rr)rr+ candidater<rArrr_link_for_candidatens zCache._link_for_candidatecCsdS)Nr)rrrrcleanupusz Cache.cleanup) __name__ __module__ __qualname____doc__rr0r>r2r@rCrD __classcell__rr)rrrs  rcs0eZdZdZfddZddZddZZS)SimpleWheelCachez+A cache of wheels for future installs. cstt|j||dhdS)Nr)rrJr)rrr)rrrr~s zSimpleWheelCache.__init__cCs |j|}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. wheels)r0r3rAr&r)rr+r/rrrr2s z"SimpleWheelCache.get_path_for_linkc Csvg}xT|j||D]D}y t|}Wntk r8wYnX|jsDq|j|j|fqW|sb|S|j|t|dS)N)r>r r supportedr%support_index_minrCmin)rr+r9 candidates wheel_namewheelrrrr@s zSimpleWheelCache.get)rErFrGrHrr2r@rIrr)rrrJzs rJcs(eZdZdZfddZddZZS)EphemWheelCachezGA SimpleWheelCache that creates it's own temporary cache directory cs0tdd|_|jjtt|j|jj|dS)Nzephem-wheel-cache)kind)r _temp_dircreaterrSrrA)rr)rrrrs   zEphemWheelCache.__init__cCs|jjdS)N)rUrD)rrrrrDszEphemWheelCache.cleanup)rErFrGrHrrDrIrr)rrrSs rScs@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|j||dht|||_t||_dS)Nr)rrWrrJ _wheel_cacherS _ephem_cache)rrr)rrrrs   zWheelCache.__init__cCs |jj|S)N)rXr2)rr+rrrr2szWheelCache.get_path_for_linkcCs |jj|S)N)rYr2)rr+rrrget_ephem_path_for_linksz"WheelCache.get_ephem_path_for_linkcCs(|jj||}||kr$|jj||}|S)N)rXr@rY)rr+r9retvalrrrr@szWheelCache.getcCs|jj|jjdS)N)rXrDrY)rrrrrDs zWheelCache.cleanup) rErFrGrHrr2rZr@rDrIrr)rrrWs  rW)#rHr6r'loggingr3pip._vendor.packaging.utilsrZpip._internal.downloadrZpip._internal.models.linkrZpip._internal.utils.compatrZpip._internal.utils.temp_dirrZpip._internal.utils.typingrZpip._internal.wheelrr Ztypingr r r r Zpip._internal.indexr getLoggerrEloggerobjectrrJrSrWrrrrs&        a3