a
    e0h?                     @   s  d 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 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$ ddl%m&Z&m'Z' e"rddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0 g dZ1e2e3Z4e
j56 Z7dd Z8dd Z9dd Z:dd Z;G dd de<Z=d d! Z>d1d#d$Z?d%d& Z@d'd( ZAd)d* ZBd2d+d,ZCd3d-d.ZDd4d/d0ZEdS )5a~  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)InstallationError)PyPITestPyPI)Link)Wheel)make_pyproject_path)InstallRequirement)
deprecated)is_archive_file)is_installable_dir)MYPY_CHECK_RUNNING)path_to_url)is_urlvcs)AnyDictOptionalSetTupleUnion)ParsedRequirement)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)   L/var/www/auris/lib/python3.9/site-packages/pip/_internal/req/constructors.py_strip_extras0   s    
r+   c                 C   s   | s
t  S td|   jS )Nplaceholder)setr   lowerr'   )r'   r)   r)   r*   convert_extras=   s    r/   c                 C   sh  | }t |\}}tj|rptjtj|dshdtj|}t|}tj	|r`|d7 }t
|t|}| drt|j}|r||td|  jfS ||t fS tD ](}| d|rd||} qqd|vrt
d	| |dd
d  }t|s>ddd tjD }	d| |	}
t
|
t|j}|s\t
d| ||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setup.pyzMFile "setup.py" not found. Directory cannot be installed in editable mode: {}zb
(A "pyproject.toml" file was found, but editable mode currently requires a setup.py based build.)zfile:r,   z{}:z{}+{}+z{} is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with svn+, git+, hg+, or bzr+).r    r   z, c                 S   s   g | ]}|j d  qS )z+URLname).0bendsr)   r)   r*   
<listcomp>       z"parse_editable.<locals>.<listcomp>z2For --editable={}, only {} are currently supportedzZCould not detect requirement name for '{}', please specify one with #egg=your_package_name)r+   osr%   isdirexistsjoinformatabspathr   isfiler   r   r.   
startswithr   egg_fragmentr   r'   r-   r   splitget_backendbackends)editable_requrlurl_no_extrasr'   msgpyproject_pathpackage_nameversion_controlvc_typerB   error_messager)   r)   r*   r   D   s`    


r   c                 C   s   d}t j| rd}zLt| d.}tt|  |d| 7 }W d   n1 sT0    Y  W q ty   t	j
d| dd Y q0 n|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. rzThe 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 '{}' does not exist.)r7   r%   r9   opennextr   readr;   r   loggerdebug)reqrF   fpr)   r)   r*   deduce_helpful_msg   s"    (rV   c                   @   s   e Zd Zdd ZdS )RequirementPartsc                 C   s   || _ || _|| _|| _d S N)requirementlinkmarkersr'   )selfrY   rZ   r[   r'   r)   r)   r*   __init__   s    zRequirementParts.__init__N)__name__
__module____qualname__r]   r)   r)   r)   r*   rW      s   rW   c                 C   s`   t | \}}}|d urFzt|}W qJ tyB   td|Y qJ0 nd }t|}t||d |S )NInvalid requirement: '{}')r   r   r   r   r;   r   rW   )rC   r2   rD   extras_overriderT   rZ   r)   r)   r*   parse_req_from_editable   s    rc   Fc                 C   s^   t | }t|j||d|j||||r.|dg ng |r@|dg ng |rR|di ni |jdS )NTinstall_optionsglobal_optionshashes)
comes_fromuser_suppliededitablerZ   
constraint
use_pep517isolatedrd   re   hash_optionsr'   )rc   r   rY   rZ   getr'   )rC   rg   rk   rl   optionsrj   rh   partsr)   r)   r*   r      s    r   c                 C   s>   t jj| v rdS t jjdur,t jj| v r,dS | 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)r7   r%   sepaltsepr>   r1   r)   r)   r*   _looks_like_path   s    
rt   c                 C   s   t |r:tj| r:t| r$t| S tdjf i t t	| sFdS tj
| rZt| S |dd}t|dkrt |d sdS td| t| S )ad  
    First, it checks whether a provided path is an installable directory
    (e.g. it has a setup.py). 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.
    zUDirectory {name!r} 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)rt   r7   r%   r8   r   r   r   r;   localsr   r=   r@   lenrR   warning)r%   r2   urlreq_partsr)   r)   r*   _get_url_from_path  s(    
rz   c                    s   t | rd}nd}|| v rF| |d\} }| }|s<d }qJt|}nd }|  } d tjtj| }d }d }t | rt| }n&t	|\}}t
|| }	|	d urt|	}|r|jdkrtd|jrtttjtj|j}|jrt|j}
djf i t n|jn| t|} fdd}d urzt}W n ty   tjjv rrd	}|t7 }n,d
v rtfddtD sd}nd}|d}|r|d|7 }t|Y n@0 |jD ]6}t|}| drd|}d}t!||dd qnd }t"||||S )Nz; ;r    filez\.\./z{wheel.name}=={wheel.version}c                    s    s| S d |  S )Nz{} (from {}))r;   )text)line_sourcer)   r*   with_sourceU  s    z(parse_req_from_line.<locals>.with_sourcezIt looks like a path.=c                 3   s   | ]}| v V  qd S rX   r)   )r3   op)req_as_stringr)   r*   	<genexpr>c  r6   z&parse_req_from_line.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?rL   zInvalid requirement: {!r}z	
Hint: {}]zExtras after version '{}'.z+moving the extras before version specifiersz21.0)replacementgone_in)#r   r@   stripr   r7   r%   normpathr<   r   r+   rz   schemer"   searchrD   r   is_wheelr   filenamer;   rv   r?   r/   r   r   rr   rV   any	operatorsr   	specifierstrendswithr   rW   )r2   r~   
marker_sepmarkers_as_stringr[   r%   rZ   extras_as_stringprD   wheelr'   r   rT   add_msgrF   specspec_strreplacer)   )r~   r   r*   parse_req_from_line#  sv    







r   c           	      C   sb   t | |}t|j||j|j|||r.|dg ng |r@|dg ng |rR|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.
    rd   re   rf   )
rZ   r[   rk   rl   rd   re   rm   rj   r'   rh   )r   r   rY   rZ   r[   rn   r'   )	r2   rg   rk   rl   ro   rj   r~   rh   rp   r)   r)   r*   r   ~  s    
r   c                 C   sz   zt | }W n  ty,   td| Y n0 tjtjg}|jrh|rh|jrh|jj	|v rhtd|j
|t|||||dS )Nra   zkPackages installed from PyPI cannot depend on packages which are not also hosted on PyPI.
{} depends on {} )rl   rk   rh   )r   r   r   r;   r	   file_storage_domainr
   rD   rZ   netlocr2   r   )
req_stringrg   rl   rk   rh   rT   domains_not_allowedr)   r)   r*   install_req_from_req_string  s,    
r   c              
   C   sH   | j r"t| j| j|| j||d}n"t| j| j||| j| j| j|d}|S )N)rg   rk   rj   rl   rh   )rg   rk   rl   ro   rj   r~   rh   )is_editabler   rY   rg   rj   r   ro   r~   )
parsed_reqrl   rk   rh   rT   r)   r)   r*   #install_req_from_parsed_requirement  s(    

r   )NNFNFF)NNFNFNF)NFNF)FNF)F__doc__loggingr7   r"   Zpip._vendor.packaging.markersr   "pip._vendor.packaging.requirementsr   r   Z pip._vendor.packaging.specifiersr   Zpip._vendor.pkg_resourcesr   r   pip._internal.exceptionsr   pip._internal.models.indexr	   r
   pip._internal.models.linkr   pip._internal.models.wheelr   pip._internal.pyprojectr   Zpip._internal.req.req_installr   pip._internal.utils.deprecationr   pip._internal.utils.filetypesr   pip._internal.utils.miscr   pip._internal.utils.typingr   pip._internal.utils.urlsr   pip._internal.vcsr   r   typingr   r   r   r   r   r   Zpip._internal.req.req_filer   __all__	getLoggerr^   rR   
_operatorskeysr   r+   r/   r   rV   objectrW   rc   r   rt   rz   r   r   r   r   r)   r)   r)   r*   <module>   st   
 

K      
"]       
!    
%   