3
g;                 @   s  d Z ddlZddlZddlZddlmZmZ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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l$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z, dddgZ-ej.e/Z0ej1j2 Z3e4e	e4ee4 f dddZ5ee4 ee4 dddZ6e4e	ee4 e4ee4 f dddZ7e4e4ddd Z8G d!d" d"Z9e4e9dd#d$Z:d<e4ee
e!e4f  ee; e;eee4ef  e;e;e;e!d&	d'dZ<e4e;d(d)d*Z=e4e4ee4 d+d,d-Z>e4ee4 e9d.d/d0Z?d=e4ee
e4e!f  ee; e;eee4ef  e;ee4 e;e!d1	d2dZ@d>e4ee! e;ee; e;e!d3d4d5ZAd?ee;ee; e;e!d6d7d8ZBee!e!d9d:d;ZCd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)AnyDictOptionalSetTupleUnion)Marker)InvalidRequirementRequirement)	Specifier)RequirementParseErrorparse_requirements)InstallationError)PyPITestPyPI)Link)Wheel)ParsedRequirement)InstallRequirement)is_archive_file)is_installable_dir)get_requirement)path_to_url)is_urlvcsinstall_req_from_editableinstall_req_from_lineparse_editable)pathreturnc             C   s6   t jd| }d }|r*|jd}|jd}n| }||fS )Nz^(.+)(\[[^\]]+\])$      )rematchgroup)r   mextrasZpath_no_extras r'   \/var/www/tester-filtro-web/env/lib/python3.6/site-packages/pip/_internal/req/constructors.py_strip_extras+   s    
r)   )r&   r   c             C   s   | s
t  S td| j  jS )Nplaceholder)setr   lowerr&   )r&   r'   r'   r(   convert_extras7   s    r-   )editable_reqr   c             C   s   | }t |\}}tjj|r$t|}|j jdrdt|j}|rX||t	d|j  j
fS ||t fS x0tD ](}|j j| drj| d| }P qjW t|}|jsdjtj}t|  d| d|j}|stdj| ||t 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file:r*   :+z, zq is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with z).zZCould not detect requirement name for '{}', please specify one with #egg=your_package_name)r)   osr   isdirr   r,   
startswithr   egg_fragmentr   r&   r+   r   is_vcsjoinall_schemesr   format)r.   urlZurl_no_extrasr&   package_nameZversion_controllinkbackendsr'   r'   r(   r   =   s4    

)reqr   c             C   s   d}t jj| rrd}y6t| $}tt|j  |dj| 7 }W dQ R X W q tk
rn   t	j
d| dd Y qX n|d|  d	7 }|S )
zReturns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
     z The path does exist. zThe argument you provided ({}) appears to be a requirements file. If that is the case, use the '-r' flag to install the packages specified within it.Nz&Cannot parse '%s' as requirements fileT)exc_infoz File 'z' does not exist.)r1   r   existsopennextr   readr8   r   loggerdebug)r=   msgfpr'   r'   r(   deduce_helpful_msgt   s    
rH   c               @   s0   e Zd Zee ee ee ee dddZ	dS )RequirementParts)requirementr;   markersr&   c             C   s   || _ || _|| _|| _d S )N)rJ   r;   rK   r&   )selfrJ   r;   rK   r&   r'   r'   r(   __init__   s    zRequirementParts.__init__N)
__name__
__module____qualname__r   r
   r   r   r   strrM   r'   r'   r'   r(   rI      s   rI   c             C   sd   t | \}}}|d k	rJyt|}W qN tk
rF   td| dY qNX nd }t|}t||d |S )NzInvalid requirement: '')r   r
   r	   r   r   rI   )r.   namer9   Zextras_overrider=   r;   r'   r'   r(   parse_req_from_editable   s    rT   F)	r.   
comes_from
use_pep517isolatedoptions
constraintuser_suppliedpermit_editable_wheelsr   c       	      C   s`   t | }t|j||d||j||||r0|jdg ng |rB|jdg ng |rT|jdi ni |jdS )NTinstall_optionsglobal_optionshashes)rU   rZ   editabler[   r;   rY   rV   rW   r\   r]   hash_optionsr&   )rT   r   rJ   r;   getr&   )	r.   rU   rV   rW   rX   rY   rZ   r[   partsr'   r'   r(   r      s    )rS   r   c             C   s>   t jj| krdS t jjdk	r,t jj| kr,dS | jdr:dS dS )ak  Checks whether the string "looks like" a path on the filesystem.

    This does not check whether the target actually exists, only judge from the
    appearance.

    Returns true if any of the following conditions is true:
    * a path separator is found (either os.path.sep or os.path.altsep);
    * a dot is found (which represents the current directory).
    TN.F)r1   r   sepaltsepr3   )rS   r'   r'   r(   _looks_like_path   s    

rf   )r   rS   r   c             C   s   t |r4tjj| r4t| r$t| S td|dt| s@dS tjj| rTt| S |j	dd}t
|dkr~t |d  r~dS tjd| t| S )	aK  
    First, it checks whether a provided path is an installable directory. If it
    is, returns the path.

    If false, check if the path is an archive file (such as a .whl).
    The function checks if the path is a file. If false, if the path has
    an @, it will treat it as a PEP 440 URL requirement and return the path.
    z
Directory zC is not installable. Neither 'setup.py' nor 'pyproject.toml' found.N@r    r!   r   zARequirement %r looks like a filename, but the file does not exist)rf   r1   r   r2   r   r   r   r   isfilesplitlenrD   warning)r   rS   Zurlreq_partsr'   r'   r(   _get_url_from_path   s     	rl   )rS   line_sourcer   c                sn  t | rd}nd}|| krF| j|d\} }|j }|s<d }qJt|}nd }| j } d }tjjtjj| }d }d }t | rt| }n&t	|\}	}t
|	| }
|
d k	rt|
}|r|jdkrtjd|jrtttjjtjj|j}|jrt|j}|j d|j }n|j}n| }t|}ttd fdd	ttd
fdd}|d k	r\||}nd }t||||S )Nz; ;r    filez\.\./z==)textr   c                s    s| S |  d  dS )Nz (from )r'   )rp   )rm   r'   r(   with_source4  s    z(parse_req_from_line.<locals>.with_source)req_as_stringr   c                s   yt  }W n tk
r   tjj kr:d}|t 7 }n*d kr`t fddtD  r`d}nd}d }|r|d| 7 }t|Y n8X x4|j	D ]*}t
|}|jd	rd
| d}t|qW |S )NzIt looks like a path.=c             3   s   | ]}| kV  qd S )Nr'   ).0op)rs   r'   r(   	<genexpr>A  s    zAparse_req_from_line.<locals>._parse_req_string.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?r>   zInvalid requirement: z
Hint: ]zExtras after version 'z'.)r   r	   r1   r   rd   rH   any	operatorsr   	specifierrQ   endswith)rs   r=   Zadd_msgrF   specspec_str)rr   )rs   r(   _parse_req_string9  s(    

z.parse_req_from_line.<locals>._parse_req_string)r   ri   stripr   r1   r   normpathabspathr   r)   rl   schemer"   searchr9   r   is_wheelr   filenamerS   versionr4   r-   rQ   r
   rI   )rS   rm   Z
marker_sepZmarkers_as_stringrK   rs   r   r;   Zextras_as_stringpr9   wheelr&   r   r=   r'   )rm   rr   r(   parse_req_from_line  sH    





r   )	rS   rU   rV   rW   rX   rY   rm   rZ   r   c       	      C   sb   t | |}t|j||j|j|||r.|jdg ng |r@|jdg ng |rR|jdi ni ||j|dS )a  Creates an InstallRequirement from a name, which might be a
    requirement, directory containing 'setup.py', filename, or URL.

    :param line_source: An optional string describing where the line is from,
        for logging purposes in case of an error.
    r\   r]   r^   )
r;   rK   rV   rW   r\   r]   r`   rY   r&   rZ   )r   r   rJ   r;   rK   ra   r&   )	rS   rU   rV   rW   rX   rY   rm   rZ   rb   r'   r'   r(   r   ^  s    
)
req_stringrU   rW   rV   rZ   r   c             C   s~   yt | }W n$ tk
r0   td|  dY nX tjtjg}|jrl|rl|jrl|jj|krltdj	|j
|t|||||dS )NzInvalid requirement: 'rR   zkPackages installed from PyPI cannot depend on packages which are not also hosted on PyPI.
{} depends on {} )rW   rV   rZ   )r   r	   r   r   file_storage_domainr   r9   r;   netlocr8   rS   r   )r   rU   rW   rV   rZ   r=   Zdomains_not_allowedr'   r'   r(   install_req_from_req_string  s&    r   )
parsed_reqrW   rV   rZ   r   c          
   C   sH   | j r"t| j| j|| j||d}n"t| j| j||| j| j| j|d}|S )N)rU   rV   rY   rW   rZ   )rU   rV   rW   rX   rY   rm   rZ   )is_editabler   rJ   rU   rY   r   rX   rm   )r   rW   rV   rZ   r=   r'   r'   r(   #install_req_from_parsed_requirement  s$    
r   )r;   ireqr   c             C   s.   t |j|j|j| |j|j|j|j|j|j	d
S )N)
r=   rU   r_   r;   rK   rV   rW   r\   r]   r`   )
r   r=   rU   r_   rK   rV   rW   r\   r]   r`   )r;   r   r'   r'   r(   install_req_from_link_and_ireq  s    r   )NNFNFFF)NNFNFNF)NFNF)FNF)D__doc__loggingr1   r"   typingr   r   r   r   r   r   Zpip._vendor.packaging.markersr   Z"pip._vendor.packaging.requirementsr	   r
   Z pip._vendor.packaging.specifiersr   pip._vendor.pkg_resourcesr   r   pip._internal.exceptionsr   pip._internal.models.indexr   r   pip._internal.models.linkr   pip._internal.models.wheelr   pip._internal.req.req_filer   pip._internal.req.req_installr   pip._internal.utils.filetypesr   pip._internal.utils.miscr   pip._internal.utils.packagingr   pip._internal.utils.urlsr   pip._internal.vcsr   r   __all__	getLoggerrN   rD   
_operatorskeysrz   rQ   r)   r-   r   rH   rI   rT   boolr   rf   rl   r   r   r   r   r   r'   r'   r'   r(   <module>	   sx    

"7      ."\      2   "  