B
    Uvge%                 @   s$  d 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m	Z	 ddl
mZ ddlmZmZ ddlmZmZmZmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" dddgZ#e$e%Z&ej'( Z)dd Z*dd Z+dd Z,dddZ-dddZ.dddZ/dS )a~  Backing implementation for InstallRequirement's various constructors

The idea here is that these formed a major chunk of InstallRequirement's size
so, moving them and support code dedicated to them outside of that class
helps creates for better understandability for the rest of the code.

These are meant to be used elsewhere within pip to create instances of
InstallRequirement.
    N)Marker)InvalidRequirementRequirement)	Specifier)RequirementParseErrorparse_requirements)is_archive_fileis_urlpath_to_urlurl_to_path)InstallationError)PyPITestPyPI)Link)InstallRequirement)is_installable_dir)vcs)Wheelinstall_req_from_editableinstall_req_from_lineparse_editablec             C   s6   t d| }d }|r*|d}|d}n| }||fS )Nz^(.+)(\[[^\]]+\])$      )rematchgroup)pathmextraspath_no_extras r    ?/tmp/pip-install-r_9ig3yj/pip/pip/_internal/req/constructors.py_strip_extras)   s    
r"   c             C   s6  | }t |\}}tj|rFtjtj|ds>td| t|}| 	drt
|j}|rz||td|  jfS ||dfS x,tD ]$}| 	d| rd||f }P qW d|krtd	|  |dd
d  }t|sd|  ddd tjD  d }t|t
|j}|s,td|  ||dfS )a   Parses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]
    zsetup.pyz;Directory %r is not installable. File 'setup.py' not found.zfile:placeholderNz%s:z%s+%s+zb%s should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+r   r   zFor --editable=%s only z, c             S   s   g | ]}|j d  qS )z+URL)name).0backendr    r    r!   
<listcomp>i   s    z"parse_editable.<locals>.<listcomp>z is currently supportedzZCould not detect requirement name for '%s', please specify one with #egg=your_package_name)r"   osr   isdirexistsjoinr   r
   lower
startswithr   egg_fragmentr   r   r   splitget_backendbackends)editable_requrlurl_no_extrasr   package_nameversion_controlvc_typeerror_messager    r    r!   r   5   sD    



c          	   C   s   d}t j| rd}yFt| d2}tt|  |dd|   d d d 7 }W d	Q R X W q tk
r   tj	d
|  dd Y qX n|d|  7 }|S )zReturns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
     z It does exist.rz The argument you provided z(%s) appears to be az" requirements file. If that is thez# case, use the '-r' flag to installz" the packages specified within it.Nz2Cannot parse '%s' as requirements             filer   )exc_infoz File '%s' does not exist.)
r)   r   r+   opennextr   readr   loggerdebug)reqmsgfpr    r    r!   deduce_helpful_msgv   s    rE   Fc             C   s   t | \}}}|dr"t|}	nd }	|d k	r^yt|}
W qb tk
rZ   td| Y qbX nd }
t|
||	dt||||r~|ni ||pdd
S )Nzfile:zInvalid requirement: '%s'Tr    )
source_direditablelink
constraintisolatedoptionswheel_cacher   )r   r.   r   r   r   r   r   r   )r3   
comes_fromrJ   rK   rL   rI   r%   r4   extras_overriderF   rB   r    r    r!   r      s&    


c                s`  t | rd}nd}|| krF| |d\} }| }|s<d}qJt|}nd}|  } d tjtj| }d}	d}
t | rt| }	nt	|\}}
tj
|otjj| kptjjdk	rtjj| kp| d}|rt|std|  tt|}	n0t|r tj|std|  tt|}	|	r|	jdkr`td	|	jr`tttjtj|	j}	|	jrt|	j}d
|j|jf  n|	j n|  |
rtd|
   j!}
nd}
 dk	r<yt  W nv t"k
r:   tjj krd}|t# 7 }n0d krt$ fddt%D sd}nt&' }td |f Y nX t( ||	|||rR|ni |||
d	S )zCreates an InstallRequirement from a name, which might be a
    requirement, directory containing 'setup.py', filename, or URL.
    z; ;r   N.zODirectory %r is not installable. Neither 'setup.py' nor 'pyproject.toml' found.zARequirement %r looks like a filename, but the file does not existfilez\.\./z%s==%sr#   r    zIt looks like a path.=c             3   s   | ]}| kV  qd S )Nr    )r&   op)rB   r    r!   	<genexpr>  s    z(install_req_from_line.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?zInvalid requirement: '%s'
%s)rH   markersrJ   rK   rL   rI   r   ))r	   r0   stripr   r)   r   normpathabspathr   r"   r*   sepaltsepr.   r   r   r
   r   isfiler@   warningschemer   searchr4   is_wheelr   filenamer%   versionr/   r   r-   r   r   rE   any	operators	traceback
format_excr   )r%   rM   rJ   rK   rL   rI   
marker_seprU   r   rH   r   plooks_like_dirwheeladd_msgr    )rB   r!   r      s    





"c             C   sn   yt | } W n  tk
r,   td|  Y nX tjtjg}| jr^|jj|kr^td|j	| f t
| |||dS )NzInvalid requirement: '%s'zkPackages installed from PyPI cannot depend on packages which are not also hosted on PyPI.
%s depends on %s )rJ   rL   )r   r   r   r   file_storage_domainr   r4   rH   netlocr%   r   )rB   rM   rJ   rL   domains_not_allowedr    r    r!   install_req_from_req  s    rn   )NFNNF)NFNNF)NFN)0__doc__loggingr)   r   rd   Zpip._vendor.packaging.markersr   "pip._vendor.packaging.requirementsr   r   Z pip._vendor.packaging.specifiersr   Zpip._vendor.pkg_resourcesr   r   pip._internal.downloadr   r	   r
   r   pip._internal.exceptionsr   pip._internal.models.indexr   r   pip._internal.models.linkr   Zpip._internal.req.req_installr   pip._internal.utils.miscr   pip._internal.vcsr   pip._internal.wheelr   __all__	getLogger__name__r@   
_operatorskeysrc   r"   r   rE   r   r   rn   r    r    r    r!   <module>	   s8   

A 
 
b