σ
έ²k^c           @@ s  d  Z  d d l m Z m Z d d l Z d d l m Z d d l Z d d l Z d d l	 Z	 d d l
 m Z d d l m Z d d l m Z d d	 l m Z e e  Z d
   Z d   Z d   Z d e f d     YZ e d  Z e j d  Z d   Z d e d  Z d S(   sy   
Functions related to core conda functionality that relates to pip

NOTE: This modules used to in conda, as conda/pip.py
i    (   t   absolute_importt   print_functionN(   t	   getLoggeri   (   t   CondaEnvException(   t   any_subprocess(   t   on_win(   t   contextc         C@ sρ   t  r t j j | d  } n t j j | d d  } | d d g |  } t | | d | \ } } } t j r¦ t j r¦ t d  t |  t d  t |  n  | d	 k rη t d
 d t	 j
 t | d t	 j
 t d   n  | | f S(   Ns
   python.exet   bint   pythons   -mt   pipt   cwds"   Ran pip subprocess with arguments:s   Pip subprocess output:i    s   Pip subprocess error:t   files
   Pip failed(   R   t   ost   patht   joinR   R   t   quiett   jsont   printt   syst   stderrR   (   t   argst   prefixR
   t   python_patht   run_argst   stdoutR   t   rc(    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pyt   pip_subprocess   s    


c         C@ s9   t  j d |   } | r1 | j d  j   j   Sd Sd S(   sE   Return the list of pip packages installed based on the command outputs   Successfully installed\ (.*)i   N(   t   ret   searcht   groupt   stript   splitt   None(   R   t   m(    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pyt   get_pip_installed_packages0   s    c         C@ sR   t  d g |   \ } } t j d |  } | s? t d   n | j d  } | S(   Ns   -Vs   pip\ (\d+\.\d+\.\d+)s+   Failed to find pip version string in outputi   (   R   R   R   R   R   (   R   R   R   t   pip_version(    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pyt   get_pip_version9   s    t
   PipPackagec           B@ s   e  Z d    Z RS(   c         C@ s?   d |  k r) d |  d |  d |  d f Sd |  d |  d f S(   NR   s   %s (%s)-%s-<pip>t   namet   versions   %s-%s-<pip>(    (   t   self(    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pyt   __str__D   s    (   t   __name__t
   __module__R)   (    (    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pyR%   C   s   c         c@ s|  t  |   } t | j d d  d  } t j j   } d g } | d k r_ | d d g 7} n t d  | t d	  <y" t | d
 |  d | \ } } Wn. t k
 rΗ | rΓ t	 d d t
 j n  d  SX| d k rkt j |  } x| D]z }	 |	 d j   |	 d <d |	 d k rY|	 d j d d  \ }
 } |
 j d d  }
 |
 |	 d <| |	 d <n  t |	   Vqκ Wnt j d  } xϋ | j   D]ν } | j   } | s₯qn  | j |  } | d  k rζ| rt	 d | d t
 j qqn  | j   \ } }
 | j   } i | d 6|
 d 6}	 d |
 k ri|
 j d  \ }
 } |
 j d d  }
 |	 j i | d 6|
 d 6 n  t |	   VqWd  S(   Nt   .i   i    t   listi	   s   --formatR   t   legacyt
   PIP_FORMATR   t   envs(   # Warning: subprocess call to pip failedR   R&   s   , R'   t   -t    R   s   ([\w.-]+)\s+\((.+)\)s+   Could not extract name and version from: %r(   R$   t   intR   R   t   environt   copyt   strR   t	   ExceptionR   R   R   R   t   loadst   lowert   replaceR%   R   t   compilet
   splitlinesR   t   matchR    t   groupst   update(   R   t   outputR#   t   pip_major_versionR0   R   t
   pip_stdoutR   t   pkgst   kwargsR'   R   t   patt   lineR!   R&   (    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pyt	   installedJ   sZ    	"

	s   [-_.]+c         C@ s   t  j d |   j   S(   NR1   (   t   _canonicalize_regext   subR9   (   R&   (    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pyt   _canonicalize_name   s    c         C@ s   t  | t  r | } n  d   | D } x[ t |  d | D]G } t | d  } | | k rp d | k rp q< n  | j t |   q< Wd  S(   Nc         S@ s   h  |  ] } t  | j   q S(    (   RJ   R&   (   t   .0t   rec(    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pys	   <setcomp>­   s   	 R@   R&   R   (   t
   isinstancet   boolRG   RJ   t   addR6   (   R   t   installed_pkgsR   R@   t   conda_namest   pip_pkgt   pip_name(    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pyt   add_pip_installed’   s    
(    t   __doc__t
   __future__R    R   R   t   loggingR   R   R   R   t
   exceptionsR   t   conda.gateways.subprocessR   t   conda.exportsR   t   conda.base.contextR   R*   t   logR   R"   R$   t   dictR%   t   TrueRG   R;   RH   RJ   R    RT   (    (    (    s1   lib/python2.7/site-packages/conda_env/pip_util.pyt   <module>   s&   				
P	