B
    Kkdi$  ã            	   @   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}	x|D ]}
d|
 V  q"W i }x`t|d|dD ]N}yt |¡}W n$ tk
r~   t d|j	¡ wHY nX |rŒ|j
rŒqH|||j< qHW | r¢tƒ }t t¡}x¤| D ]š}t|ƒ†}x||D ]r}| ¡ r| ¡  d¡s|	r|	|ƒs| d¡r0| ¡ }||krÒ| |¡ |V  qÒ| d¡sH| d¡r| d¡rf|d	d …  ¡ }n|tdƒd …  ¡  d
¡}t|||d}ntt d|¡ ¡ ||d}|jsÐt d|| ¡ ¡ t d¡ qÒ|j|kr||j st d|t d|¡ ¡ |j¡ n||j  |¡ qÒt||j ƒ ¡ V  ||j= ||j  |¡ qÒW W d Q R X q¸W xBt |¡D ]4\}}t|ƒdkrdt d|d  t!t|ƒƒ¡¡ qdW dV  x<t!| "¡ dd„ dD ]$}t#|jƒ|kr¸t|ƒ ¡ V  q¸W d S )Nz-f %sr   )Ú
local_onlyÚskipÚ	user_onlyzCould not parse requirement: %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   ú@/tmp/pip-install-gxxfd9b7/pip/pip/_internal/operations/freeze.pyÚ<lambda>Ÿ   ó    zfreeze.<locals>.<lambda>)Úkey)$ÚreÚcompileÚsearchr   ÚFrozenRequirementÚ	from_distr   ÚloggerÚwarningÚproject_nameÚeditabler%   ÚsetÚcollectionsÚdefaultdictÚlistÚopenÚstripÚ
startswithÚrstripÚaddÚlenÚlstripr   r	   r
   ÚsubÚinfoÚappendÚstrr   Ú	iteritemsÚjoinÚsortedÚvaluesr   )ÚrequirementÚ
find_linksr   r   Ú
skip_regexr!   r"   Úexclude_editabler   Ú
skip_matchÚlinkÚinstallationsÚdistÚreqÚemitted_optionsÚ	req_filesÚreq_file_pathÚreq_fileÚlineÚline_reqr%   ÚfilesÚinstallationr   r   r(   Úfreeze%   s’    





"rY   c          
   C   s>  t | ƒsddg fS tj tj | j¡¡}ddlm}m} | 	|¡}|sr|  
¡ }t d||¡ d |¡g}|d|fS y| || j¡}W nˆ |k
r¶   |  
¡ }d |j|¡g}|d|fS  tk
rÞ   t d	||j¡ ddg fS  tk
r } zt d
|¡ W dd}~X Y nX |dk	r"|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ÚRemoteNotFoundErrorz3No VCS found for editable requirement {!r} in: {!r}z/# 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.vcsrZ   r[   Úget_backend_typeÚas_requirementr1   ÚdebugÚformatÚget_src_requirementr3   Ú__name__r   r2   r%   r   )rO   r`   rZ   r[   Úvc_typerP   ÚcommentsÚexcr   r   r(   Úget_requirement_info¤   sF    






rk   c               @   s*   e Zd Zd	dd„Zedd„ ƒZdd„ ZdS )
r/   r   c             C   s   || _ || _|| _|| _d S )N)r%   rP   r4   ri   )Úselfr%   rP   r4   ri   r   r   r(   Ú__init__ã   s    zFrozenRequirement.__init__c             C   s0   t |ƒ\}}}|d kr| ¡ }| |j|||dS )N)ri   )rk   rc   r3   )ÚclsrO   rP   r4   ri   r   r   r(   r0   ê   s    zFrozenRequirement.from_distc             C   s2   | j }| jrd| }d t| jƒt|ƒg ¡d S )Nz-e %sÚ
)rP   r4   rE   r8   ri   rC   )rl   rP   r   r   r(   Ú__str__ó   s    zFrozenRequirement.__str__N)r   )rg   Ú
__module__Ú__qualname__rm   Úclassmethodr0   rp   r   r   r   r(   r/   â   s   
	r/   )	NNNNNFNFr   )1Ú
__future__r   r6   Úloggingr\   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   rC   ÚboolZRequirementInfoÚ	getLoggerrg   r1   rY   rk   Úobjectr/   r   r   r   r(   Ú<module>   s:   ,
        
v>