U
    @vg'                  
   @   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	rqD|||j
< qD| rt }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std||  td qt|j}||kr(||j std|td| |j n||j | qt||  V  ||= ||j | qW 5 Q R X qt |D ]4\}}t|dkrhtd|d!t"t| qhdV  t"|# dd dD ] }|j
|	krt| V  qd 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-gw11q0wt/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@   ,
          
 >