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: