U
    «ÃT_Ä'  ã                
   @   s4  d dl m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 d dlmZmZ d dlmZmZ d dlmZ d d	lmZmZ d d
lmZ e�rd dlmZmZmZmZmZmZm Z m!Z!m"Z" d dl#m$Z$ d dl
m%Z%m&Z& e ee"e'e&f  e(ee' f Z)e *e+¡Z,ddd„Z-dd„ Z.G dd„ de/ƒZ0dS )é    )Úabsolute_importN)Úsix)Úcanonicalize_name)ÚRequirementParseError)Ú
BadCommandÚInstallationError)Úinstall_req_from_editableÚinstall_req_from_line)Ú
COMMENT_RE)Údist_is_editableÚget_installed_distributions)ÚMYPY_CHECK_RUNNING)	ÚIteratorÚOptionalÚListÚ	ContainerÚSetÚDictÚTupleÚIterableÚUnion)Ú
WheelCache)ÚDistributionÚRequirementF© c
                 c   sÞ  |pg }d }
|rt  |¡j}
|D ]}d| V  q i }t|d||d�D ]b}zt |¡}W n8 tk
rŽ } zt d||¡ W Y ¢qDW 5 d }~X Y nX |rœ|j	rœqD|||j
< qD| �r¤tƒ }t t¡}| D �]˜}t|ƒ��„}|D �]v}| ¡ �r| ¡  d¡�s|
�r|
|ƒ�s| d¡�r6| ¡ }||krØ| |¡ |V  qØ| d¡�sN| d¡�r–| d¡�rl|d	d …  ¡ }n|tdƒd …  ¡  d
¡}t|||d�}ntt d|¡ ¡ ||d�}|j�sÖt d|| ¡ ¡ t d¡ qØt|jƒ}||k�r(||j �st d|t d|¡ ¡ |j¡ n||j  |¡ qØt|| ƒ ¡ V  ||= ||j  |¡ qØW 5 Q R X qÂt  |¡D ]4\}}t|ƒdk�rht d|d !t"t|ƒƒ¡¡ �qhdV  t"| #¡ dd„ d�D ] }|j
|	k�r¸t|ƒ ¡ V  �q¸d S )Nz-f %sr   )Ú
local_onlyÚskipÚ	user_onlyÚpathsz6Could not generate requirement for distribution %r: %sú#)z-rz--requirementz-Zz--always-unzipz-fz--find-linksz-iz--index-urlz--prez--trusted-hostz--process-dependency-linksz--extra-index-urlz-ez
--editableé   ú=)ÚisolatedÚwheel_cacheÚ zWSkipping line in requirement file [%s] because it's not clear what it would install: %sz9  (add #egg=PackageName to the URL to avoid this warning)zBRequirement file [%s] contains %s, but package %r is not installedé   z+Requirement %s included multiple times [%s]z, z7## The following requirements were added by pip freeze:c                 S   s
   | j  ¡ S ©N)ÚnameÚlower)Úxr   r   úC/tmp/pip-unpacked-wheel-8u7dkzi1/pip/_internal/operations/freeze.pyÚ<lambda>°   ó    zfreeze.<locals>.<lambda>)Úkey)$ÚreÚcompileÚsearchr   ÚFrozenRequirementÚ	from_distr   ÚloggerÚwarningÚeditableÚcanonical_nameÚsetÚcollectionsÚdefaultdictÚlistÚopenÚstripÚ
startswithÚrstripÚaddÚlenÚlstripr   r	   r
   Úsubr'   Úinfor   ÚappendÚstrr   Ú	iteritemsÚjoinÚsortedÚvalues)ÚrequirementÚ
find_linksr   r   r   Ú
skip_regexr"   r#   Zexclude_editabler   Z
skip_matchÚlinkZinstallationsÚdistÚreqÚexcZemitted_optionsZ	req_filesZreq_file_pathÚreq_fileÚlineZline_reqZline_req_canonical_namer'   ÚfilesZinstallationr   r   r*   Úfreeze+   sÄ    ý
 þ




ÿþþý
ýý ýÿÿ
ûÿ ÿÿ ÿ
rT   c              
   C   sN  t | ƒsddg fS tj tj | j¡¡}ddlm}m} | 	|¡}|dkrv|  
¡ }t d||¡ d |¡g}|d|fS z| || j¡}W n” |k
rÂ   |  
¡ }d t|ƒj|¡g}|d|f Y S  tk
rî   t d	||j¡ ddg f Y S  tk
�r } zt d
|¡ W 5 d}~X Y nX |dk	�r2|dg fS t d|¡ dg}dd|fS )zk
    Compute and return values (req, editable, comments) for use in
    FrozenRequirement.from_dist().
    NFr   )ÚvcsÚRemoteNotFoundErrorz1No VCS found for editable requirement "%s" in: %rz/# Editable install with no version control ({})Tz)# Editable {} install with no remote ({})zPcannot determine version of editable source in %s (%s command not found in path)zYError when trying to get requirement for VCS system %s, falling back to uneditable formatz-Could not determine repository location of %sz-## !! Could not determine repository location)r   ÚosÚpathÚnormcaseÚabspathÚlocationÚpip._internal.vcsrU   rV   Úget_backend_for_dirÚas_requirementr3   ÚdebugÚformatÚget_src_requirementÚproject_nameÚtypeÚ__name__r   r4   r'   r   )rN   r[   rU   rV   Úvcs_backendrO   ÚcommentsrP   r   r   r*   Úget_requirement_infoµ   sZ    

 þÿ
 ÿÿüþ

 ÿrg   c                   @   s*   e Zd Zd	dd„Zedd„ ƒZdd„ ZdS )
r1   r   c                 C   s&   || _ t|ƒ| _|| _|| _|| _d S r&   )r'   r   r6   rO   r5   rf   )Úselfr'   rO   r5   rf   r   r   r*   Ú__init__ô   s
    
zFrozenRequirement.__init__c                 C   s0   t |ƒ\}}}|d kr| ¡ }| |j|||d�S )N)rf   )rg   r^   rb   )ÚclsrN   rO   r5   rf   r   r   r*   r2   ü   s    zFrozenRequirement.from_distc                 C   s2   | j }| jrd| }d t| jƒt|ƒg ¡d S )Nz-e %sÚ
)rO   r5   rG   r:   rf   rE   )rh   rO   r   r   r*   Ú__str__  s    zFrozenRequirement.__str__N)r   )rd   Ú
__module__Ú__qualname__ri   Úclassmethodr2   rl   r   r   r   r*   r1   ó   s   

r1   )
NNNNNNFNFr   )1Ú
__future__r   r8   ÚloggingrW   r.   Úpip._vendorr   Úpip._vendor.packaging.utilsr   Zpip._vendor.pkg_resourcesr   Úpip._internal.exceptionsr   r   Úpip._internal.req.constructorsr   r	   Zpip._internal.req.req_filer
   Úpip._internal.utils.miscr   r   Úpip._internal.utils.typingr   Útypingr   r   r   r   r   r   r   r   r   Úpip._internal.cacher   r   r   rE   ÚboolZRequirementInfoÚ	getLoggerrd   r3   rT   rg   Úobjectr1   r   r   r   r*   Ú<module>   s@   ,
          ö
 >