U
    Eh'                  
   @   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   E./venv/lib/python3.8/site-packages/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   Z	iteritemsjoinsortedvalues)ZrequirementZ
find_linksr   r   r   Z
skip_regexr"   r#   Zexclude_editabler   Z
skip_matchlinkZinstallationsdistreqexcZemitted_optionsZ	req_filesZreq_file_pathZreq_filelineZline_reqZline_req_canonical_namer'   filesZinstallationr   r   r*   freeze+   s    
 





 
  
rO   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locationZpip._internal.vcsrP   rQ   Zget_backend_for_diras_requirementr3   debugformatZget_src_requirementproject_nametype__name__r   r4   r'   r   )rJ   rV   rP   rQ   Zvcs_backendrK   commentsrL   r   r   r*   get_requirement_info   sZ    

 
 

 r^   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   rK   r5   r]   )selfr'   rK   r5   r]   r   r   r*   __init__   s
    
zFrozenRequirement.__init__c                 C   s0   t |\}}}|d kr| }| |j|||dS )N)r]   )r^   rW   rZ   )clsrJ   rK   r5   r]   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
)rK   r5   rF   r:   r]   rE   )r_   rK   r   r   r*   __str__  s    zFrozenRequirement.__str__N)r   )r\   
__module____qualname__r`   classmethodr2   rc   r   r   r   r*   r1      s   

r1   )
NNNNNNFNFr   )1Z
__future__r   r8   ZloggingrR   r.   Zpip._vendorr   Zpip._vendor.packaging.utilsr   Zpip._vendor.pkg_resourcesr   Zpip._internal.exceptionsr   r   Zpip._internal.req.constructorsr   r	   Zpip._internal.req.req_filer
   Zpip._internal.utils.miscr   r   Zpip._internal.utils.typingr   typingr   r   r   r   r   r   r   r   r   Zpip._internal.cacher   r   r   rE   boolZRequirementInfoZ	getLoggerr\   r3   rO   r^   objectr1   r   r   r   r*   <module>   s@   ,
          
 >