
0c@_R                 @   s3  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l	 m
 Z
 d  d l m Z e r d  d l m Z d  d l m Z m Z m Z m Z m Z m Z d  d l m Z d  d	 l m Z e j e  Z e j d
 d    Z e j d d    Z Gd d   d e   Z! d S)    )absolute_importN)contextlib2)TempDirectory)MYPY_CHECK_RUNNING)TracebackType)DictIteratorOptionalSetTypeUnion)InstallRequirement)Linkc              k   s   t  j } t   } i  } xU |  j   D]G \ } } y | | | | <Wn t k
 ra | | | <Yn X| | | <q% Wz	 d  VWd  xO | j   D]A \ } } | | k r | | =q t | t  s t  | | | <q WXd  S)N)osenvironobjectitemsKeyError
isinstancestrAssertionError)ZchangestargetZnon_existent_markerZsaved_valuesnameZ	new_valueZoriginal_value r   </tmp/pip-build-jynh7p1z/pip/pip/_internal/req/req_tracker.pyupdate_env_context_manager   s     			
r   c              c   s   t  j j d  }  t j   o } |  d  k rn | j t d d   j }  | j t d |    t	 j
 d |   t |    } | VWd  QRXWd  QRXd  S)NZPIP_REQ_TRACKERkindzreq-trackerz Initialized build tracking at %s)r   r   getr   	ExitStackenter_contextr   pathr   loggerdebugRequirementTracker)rootctxZtrackerr   r   r   get_requirement_tracker2   s    r&   c               @   sy   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z	 e
 j d d    Z d S)r#   c             C   s,   | |  _  t   |  _ t j d |  j   d  S)NzCreated build tracker: %s)_rootset_entriesr!   r"   )selfr$   r   r   r   __init__D   s    	zRequirementTracker.__init__c             C   s   t  j d |  j  |  S)NzEntered build tracker: %s)r!   r"   r'   )r*   r   r   r   	__enter__J   s    zRequirementTracker.__enter__c             C   s   |  j    d  S)N)cleanup)r*   exc_typeexc_valexc_tbr   r   r   __exit__O   s    zRequirementTracker.__exit__c             C   s4   t  j | j j    j   } t j j |  j |  S)N)	hashlibsha224url_without_fragmentencode	hexdigestr   r    joinr'   )r*   linkhashedr   r   r   _entry_pathX   s    zRequirementTracker._entry_pathc             C   s  | j  s t  |  j | j   } y& t |   } | j   } Wd QRXWn: t k
 r } z | j t j k rq   WYd d } ~ Xn" Xd j | j  |  } t	 |   | |  j
 k s t  t | d   } | j t |   Wd QRX|  j
 j |  t j d | |  j  d S)z5Add an InstallRequirement to build tracking.
        Nz{} is already being built: {}wzAdded %s to build tracker %r)r8   r   r:   openreadIOErrorerrnoENOENTformatLookupErrorr)   writer   addr!   r"   r'   )r*   reqZ
entry_pathfpcontentsemessager   r   r   rD   ]   s     zRequirementTracker.addc             C   sR   | j  s t  t j |  j | j    |  j j |  t j d | |  j	  d S)z:Remove an InstallRequirement from build tracking.
        z Removed %s from build tracker %rN)
r8   r   r   unlinkr:   r)   remover!   r"   r'   )r*   rE   r   r   r   rK   ~   s    zRequirementTracker.removec             C   s>   x$ t  |  j  D] } |  j |  q Wt j d |  j  d  S)NzRemoved build tracker: %r)r(   r)   rK   r!   r"   r'   )r*   rE   r   r   r   r-      s    zRequirementTracker.cleanupc             c   s#   |  j  |  d  V|  j |  d  S)N)rD   rK   )r*   rE   r   r   r   track   s    zRequirementTracker.trackN)__name__
__module____qualname__r+   r,   r1   r:   rD   rK   r-   
contextlibcontextmanagerrL   r   r   r   r   r#   B   s   	!r#   )"
__future__r   rP   r?   r2   loggingr   Zpip._vendorr   Zpip._internal.utils.temp_dirr   Zpip._internal.utils.typingr   typesr   Ztypingr   r   r	   r
   r   r   Zpip._internal.req.req_installr   Zpip._internal.models.linkr   	getLoggerrM   r!   rQ   r   r&   r   r#   r   r   r   r   <module>   s"   .