σ
ΌS]c           @@ s7  d  d l  m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m	 Z	 d e
 f d     YZ d e f d     YZ d   Z d	   Z d d
  Z d d  Z d   Z e j d d g  Z e j d  Z e j d  Z e j d  Z e d0  Z d,   Z d-   Z d.   Z d/   Z d S(1   i    (   t   absolute_importt   print_functionN(   t   logged_subprocesst   PipErrorc           B@ s   e  Z d  Z RS(   s   General pip error.(   t   __name__t
   __module__t   __doc__(    (    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyR      s   t   PipNotInstalledErrorc           B@ s   e  Z d  Z RS(   s-   Pip isn't even installed in this environment.(   R   R   R   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyR      s   c         C@ s€   t  j j |  d d  } t  j j |  d d  } g  | | g D] } t  j j |  r= | ^ q= } t |  d k r t d |    n  | d g } | j |  | S(   Nt   bint   pipt   Scriptss   pip.exei    s4   'pip' command is not installed in the environment %s(   t   ost   patht   joint   existst   lenR   t   extend(   t   prefixt
   extra_argst   unix_pipt   win_pipR	   t   pipst   cmd_list(    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyt   _get_pip_command    s    1c   	      C@ s  t  |  |  } y% t j | d t j d t j } Wn8 t k
 rn } t d d j |  t |  f   n X| j	   \ } } | j
   j   } | j d k rΔ t d d j |  | f   nQ | d k rxB | j d  D]. } t d	 | d | d
 | f d t j qΰ Wn  | S(   Nt   stdoutt   stderrs   failed to run: %r: %rt    i    s   %s: %st    s   
s	   %s %s: %si   t   file(   R   R   t   Popent
   subprocesst   PIPEt   OSErrorR   R   t   reprt   communicatet   decodet   stript
   returncodet   splitt   printt   sysR   (	   R   R   R   t   pt   et   outt   errt   errstrt   line(    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyt	   _call_pip,   s    %)"/c         C@ sY   | s t  | t t f  r0 t d |   n  d d g } | j |  t |  d | S(   s%   Install packages into an environment.sX   must specify a list of one or more packages to install into existing environment, not %rt   installs   --quietR   (   t
   isinstancet   listt   tuplet	   TypeErrorR   R/   (   R   t   pkgst   args(    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyR0   =   s    c         C@ sX   | s t  | t t f  r, t d   n  d d d g } | j |  t |  d | S(   s$   Remove packages from an environment.sO   must specify a list of one or more packages to remove from existing environmentt	   uninstalls   --quiets   --yesR   (   R1   R2   R3   R4   R   R/   (   R   R5   R6   (    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyt   removeI   s
    c         C@ sΡ   t  j j |   s t   Sy4 t |  d d g j d  } | j d d  } Wn t k
 rf d } n Xt j	 d d t j
 } t   } xB | j |  D]1 } | j d	  | j d
  f | | j d	  <q W| S(   s6   Get a dict of package names to (name, version) tuples.R   t   freezes   utf-8s   
s   
R   s   ^(.+)==(.+)$t   flagsi   i   (   R   R   t   isdirt   dictR/   R#   t   replaceR   t   ret   compilet	   MULTILINEt   finditert   group(   R   R+   t   line_ret   resultt   match(    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyt	   installedS   s    
	/t   ParsedPipSpect   names    *([a-zA-Z0-9][-_.a-zA-Z0-9]+)s   [#&]egg=([^&]*)s   ^(.*?)(?:-dev|-\d.*)$t   httpt   httpsR   t   ftpt   gits   git+https	   git+httpss   git+sshs   git+gits   git+filet   hgs   hg+https   hg+httpss   hg+sshs   hg+static-httpbzrs   bzr+https	   bzr+httpss   bzr+sshs   bzr+sftps   bzr+ftps   bzr+lpt   svns   svn+sshs   svn+https	   svn+httpss   svn+svnc         C@ s:   d |  k r2 |  j  d d  d } | j   t k St Sd  S(   Nt   :i   i    (   R&   t   lowert   _url_schemest   False(   t   st   scheme(    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyt   _is_pip_understood_urly   s    c         C@ s0   t  j |   } | d  k	 r( | j d  Sd  Sd  S(   Ni   (   t	   _spec_patRE   t   NoneRB   (   t   spect   m(    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyt   _extract_name   s    c         C@ sv   t  j |   } | d  k	 rn t | j d   } | d  k	 rr t j |  } | d  k	 rd | j d  S| Sqr n d  Sd  S(   Ni   (   t   _egg_fragment_ret   searchRW   RZ   RB   t   _egg_fragment_postfix_re(   t   urlRY   t   fragment(    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyt   _extract_name_from_egg_fragment   s    
c         C@ sH   t  |   r t |   } n t |   } | d k r7 d St d |  Sd S(   sε  Parse a pip spec, right now we only understand the name portion.

    Parsing it exactly as pip would is extremely complicated, and
    we would pretty much have to import the pip code.
    So for now we'll "fail late" when we invoke pip.

    What we understand currently is an url with a "#egg=foo"
    fragment, and a plain package name (possibly with version info
    on it). We don't understand filesystem paths yet.

    Returns:
       ``ParsedPipSpec`` or None on failure

    RH   N(   RU   R`   RZ   RW   RG   (   RX   RH   (    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyt
   parse_spec   s    (   RI   RJ   R   RK   RL   s   git+https	   git+httpss   git+sshs   git+gits   git+fileRM   s   hg+https   hg+httpss   hg+sshs   hg+static-httpbzrs   bzr+https	   bzr+httpss   bzr+sshs   bzr+sftps   bzr+ftps   bzr+lpRN   s   svn+sshs   svn+https	   svn+httpss   svn+svn(   t
   __future__R    R   t   collectionsR   R   R>   R(   t   anaconda_project.internalR   t	   ExceptionR   R   R   R/   RW   R0   R8   RF   t
   namedtupleRG   R?   RV   R[   R]   t   setRQ   RU   RZ   R`   Ra   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/internal/pip_api.pyt   <module>   s2   		
	  				