ó
Ð²Ebc           @   sx  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/ m0 Z0 n  d d d g Z1 e j2 e3 ƒ Z4 e
 j5 j6 ƒ  Z7 d „  Z8 d „  Z9 d „  Z: d „  Z; d e< f d „  ƒ  YZ= d „  Z> d d e@ d e@ e@ d „ ZA d  „  ZB d! „  ZC d" „  ZD d d e@ d e@ d e@ d# „ ZE d e@ d e@ d$ „ ZF e@ d e@ d% „ ZG d S(&   s~  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.
iÿÿÿÿN(   t   Marker(   t   InvalidRequirementt   Requirement(   t	   Specifier(   t   RequirementParseErrort   parse_requirements(   t   InstallationError(   t   PyPIt   TestPyPI(   t   Link(   t   Wheel(   t   make_pyproject_path(   t   InstallRequirement(   t
   deprecated(   t   is_archive_file(   t   is_installable_dir(   t   MYPY_CHECK_RUNNING(   t   path_to_url(   t   is_urlt   vcs(   t   Anyt   Dictt   Optionalt   Sett   Tuplet   Union(   t   ParsedRequirementt   install_req_from_editablet   install_req_from_linet   parse_editablec         C   sO   t  j d |  ƒ } d  } | r? | j d ƒ } | j d ƒ } n |  } | | f S(   Ns   ^(.+)(\[[^\]]+\])$i   i   (   t   ret   matcht   Nonet   group(   t   patht   mt   extrast   path_no_extras(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   _strip_extras0   s    c         C   s$   |  s t  ƒ  St d |  j ƒ  ƒ j S(   Nt   placeholder(   t   setR   t   lowerR$   (   R$   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   convert_extras=   s    c         C   s*  |  } t  | ƒ \ } } t j j | ƒ r¯ t j j t j j | d ƒ ƒ s  d j t j j | ƒ ƒ } t | ƒ } t j j	 | ƒ r‘ | d 7} n  t
 | ƒ ‚ n  t | ƒ } n  | j ƒ  j d ƒ rt | ƒ j } | rù | | t d | j ƒ  ƒ j f S| | t ƒ  f Sn  xB t D]: } | j ƒ  j d j | ƒ ƒ rd j | | ƒ } PqqWd | k rut
 d	 j |  ƒ ƒ ‚ n  | j d d
 ƒ d j ƒ  } t j | ƒ síd j g  t j D] }	 |	 j d ^ q°ƒ }
 d j |  |
 ƒ } t
 | ƒ ‚ n  t | ƒ j } | st
 d j |  ƒ ƒ ‚ n  | | t ƒ  f S(   s   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]
    s   setup.pysM   File "setup.py" not found. Directory cannot be installed in editable mode: {}sb   
(A "pyproject.toml" file was found, but editable mode currently requires a setup.py based build.)s   file:R'   s   {}:s   {}+{}t   +s   {} 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+).i   i    s   , s   +URLs2   For --editable={}, only {} are currently supportedsZ   Could not detect requirement name for '{}', please specify one with #egg=your_package_name(   R&   t   osR"   t   isdirt   existst   joint   formatt   abspathR   t   isfileR   R   R)   t
   startswithR	   t   egg_fragmentR   R$   R(   R   t   splitt   get_backendt   backendst   name(   t   editable_reqt   urlt   url_no_extrasR$   t   msgt   pyproject_patht   package_namet   version_controlt   vc_typet   bendsR7   t   error_message(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyR   D   sN    !
,c         C   s§   d } t  j j |  ƒ r d } yE t |  d ƒ 0 } t t | j ƒ  ƒ ƒ | d j |  ƒ 7} Wd QXWq£ t k
 rŒ t	 j
 d |  d t ƒq£ Xn | d j |  ƒ 7} | S(	   s„   Returns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
    t    s    The path does exist. t   rs•   The 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.Ns&   Cannot parse '%s' as requirements filet   exc_infos    File '{}' does not exist.(   R,   R"   R.   t   opent   nextR   t   readR0   R   t   loggert   debugt   True(   t   reqR<   t   fp(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   deduce_helpful_msg   s    t   RequirementPartsc           B   s   e  Z d  „  Z RS(   c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   requirementt   linkt   markersR$   (   t   selfRP   RQ   RR   R$   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   __init__¯   s    			(   t   __name__t
   __module__RT   (    (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyRO   ®   s   c         C   s‚   t  |  ƒ \ } } } | d  k	 r] y t | ƒ } Wqc t k
 rY t d j | ƒ ƒ ‚ qc Xn d  } t | ƒ } t | | d  | ƒ S(   Ns   Invalid requirement: '{}'(   R   R    R   R   R   R0   R	   RO   (   R9   R8   R:   t   extras_overrideRL   RQ   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   parse_req_from_editable¼   s    c         C   s©   t  |  ƒ } t | j d | d | d t d | j d | d | d | d | r] | j d g  ƒ n g  d	 | r{ | j d	 g  ƒ n g  d
 | r™ | j d i  ƒ n i  d | j ƒS(   Nt
   comes_fromt   user_suppliedt   editableRQ   t
   constraintt
   use_pep517t   isolatedt   install_optionst   global_optionst   hash_optionst   hashesR$   (   RX   R   RP   RK   RQ   t   getR$   (   R9   RY   R]   R^   t   optionsR\   RZ   t   parts(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyR   Ð   s    		c         C   sU   t  j j |  k r t St  j j d k	 r> t  j j |  k r> t S|  j d ƒ rQ t St S(   sk  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).
    t   .N(   R,   R"   t   sepRK   t   altsepR    R3   t   False(   R8   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   _looks_like_pathí   s    $c         C   sÎ   t  | ƒ rO t j j |  ƒ rO t |  ƒ r4 t |  ƒ St d j t ƒ    ƒ ‚ n  t	 |  ƒ s_ d St j j |  ƒ r{ t |  ƒ S| j d d ƒ } t | ƒ d k r´ t  | d ƒ r´ d St j d | ƒ t |  ƒ S(   sd  
    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.
    sU   Directory {name!r} is not installable. Neither 'setup.py' nor 'pyproject.toml' found.t   @i   i   i    sA   Requirement %r looks like a filename, but the file does not existN(   Rj   R,   R"   R-   R   R   R   R0   t   localsR   R    R2   R5   t   lenRI   t   warning(   R"   R8   t   urlreq_parts(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   _get_url_from_path  s"    


#c            sÿ  t  |  ƒ r d } n d } | |  k ri |  j | d ƒ \ }  } | j ƒ  } | sZ d  } qo t | ƒ } n d  } |  j ƒ  }  d  ‰ t j j t j j |  ƒ ƒ } d  } d  } t  |  ƒ rÆ t	 |  ƒ } n< t
 | ƒ \ } } t | |  ƒ }	 |	 d  k	 rt	 |	 ƒ } n  | r•| j d k r\t j d | j ƒ r\t	 t t j j t j j | j ƒ ƒ ƒ ƒ } n  | j r‰t | j ƒ }
 d j t ƒ    ‰ q›| j ‰ n |  ‰ t | ƒ } ‡  f d †  } ˆ d  k	 ræy t ˆ ƒ } Wn± t k
 r…t j j ˆ k rd } | t ˆ ƒ 7} n8 d	 ˆ k r?t ‡ f d
 †  t Dƒ ƒ r?d } n d } | d j ˆ ƒ ƒ } | rv| d j | ƒ 7} n  t | ƒ ‚ qìXxc | j D]O } t  | ƒ } | j! d ƒ rd j | ƒ } d } t" | d | d d ƒqqWn d  } t# | | | | ƒ S(   Ns   ; t   ;i   t   files   \.\./s   {wheel.name}=={wheel.version}c            s   ˆ  s
 |  Sd j  |  ˆ  ƒ S(   Ns   {} (from {})(   R0   (   t   text(   t   line_source(    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   with_sourceU  s    s   It looks like a path.t   =c         3   s   |  ] } | ˆ  k Vq d  S(   N(    (   t   .0t   op(   t   req_as_string(    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pys	   <genexpr>c  s    s,   = is not a valid operator. Did you mean == ?RC   s   Invalid requirement: {!r}s	   
Hint: {}t   ]s   Extras after version '{}'.s+   moving the extras before version specifierst   replacementt   gone_ins   21.0($   R   R5   t   stripR    R    R,   R"   t   normpathR1   R	   R&   Rp   t   schemeR   t   searchR:   R   t   is_wheelR
   t   filenameR0   Rl   R4   R*   R   R   Rg   RN   t   anyt	   operatorsR   t	   specifiert   strt   endswithR   RO   (   R8   Rt   t
   marker_sept   markers_as_stringRR   R"   RQ   t   extras_as_stringt   pR:   t   wheelR$   Ru   RL   t   add_msgR<   t   spect   spec_strt   replace(    (   Rt   Ry   s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   parse_req_from_line#  sp    		$-		 c   	      C   s¬   t  |  | ƒ } t | j | d | j d | j d | d | d | rT | j d g  ƒ n g  d | rr | j d g  ƒ n g  d | r | j d i  ƒ n i  d	 | d
 | j d | ƒ
S(   s  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.
    RQ   RR   R]   R^   R_   R`   Ra   Rb   R\   R$   RZ   (   R‘   R   RP   RQ   RR   Rc   R$   (	   R8   RY   R]   R^   Rd   R\   Rt   RZ   Re   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyR   ~  s    	c      	   C   s²   y t  |  ƒ } Wn& t k
 r8 t d j |  ƒ ƒ ‚ n Xt j t j g } | j r“ | r“ | j r“ | j j	 | k r“ t d j | j
 | ƒ ƒ ‚ n  t | | d | d | d | ƒS(   Ns   Invalid requirement: '{}'sk   Packages installed from PyPI cannot depend on packages which are not also hosted on PyPI.
{} depends on {} R^   R]   RZ   (   R   R   R   R0   R   t   file_storage_domainR   R:   RQ   t   netlocR8   R   (   t
   req_stringRY   R^   R]   RZ   RL   t   domains_not_allowed(    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   install_req_from_req_string  s"    c         C   sˆ   |  j  r? t |  j d |  j d | d |  j d | d | ƒ} nE t |  j d |  j d | d | d |  j d |  j d |  j d | ƒ} | S(   NRY   R]   R\   R^   RZ   Rd   Rt   (   t   is_editableR   RP   RY   R\   R   Rd   Rt   (   t
   parsed_reqR^   R]   RZ   RL   (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt#   install_req_from_parsed_requirementÀ  s$    										(H   t   __doc__t   loggingR,   R   t   pip._vendor.packaging.markersR    t"   pip._vendor.packaging.requirementsR   R   t    pip._vendor.packaging.specifiersR   t   pip._vendor.pkg_resourcesR   R   t   pip._internal.exceptionsR   t   pip._internal.models.indexR   R   t   pip._internal.models.linkR	   t   pip._internal.models.wheelR
   t   pip._internal.pyprojectR   t   pip._internal.req.req_installR   t   pip._internal.utils.deprecationR   t   pip._internal.utils.filetypesR   t   pip._internal.utils.miscR   t   pip._internal.utils.typingR   t   pip._internal.utils.urlsR   t   pip._internal.vcsR   R   t   typingR   R   R   R   R   R   t   pip._internal.req.req_fileR   t   __all__t	   getLoggerRU   RI   t
   _operatorst   keysR„   R&   R*   R   RN   t   objectRO   RX   R    Ri   R   Rj   Rp   R‘   R   R–   R™   (    (    (    s;   /tmp/pip-build-UPPWic/pip/pip/_internal/req/constructors.pyt   <module>	   sn   .				K				"	] 