
@^Yc           @  s   d  d l  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 Z d  d l Z d d l	 m
 Z
 m Z d f  d     YZ d e f d     YZ d	   Z e d
    Z e d    Z d S(   i(   t   with_statementNi   (   t	   DepConfigt   hookimplt   CreationConfigc           B  s2   e  Z d    Z d   Z e d    Z d   Z RS(   c         C  sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   md5t   pythont   versiont   sitepackagest
   usedevelopt
   alwayscopyt   deps(   t   selfR   R   R   R   R   R
   R	   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   __init__   s    						c         C  s   d |  j  |  j f g } | j d |  j |  j |  j |  j f  x" |  j D] } | j d |  qL W| j   | j	 d j
 |   d  S(   Ns   %s %ss   %s %d %d %ds   
(   R   R   t   appendR   R   R   R	   R
   t   ensuret   writet   join(   R   t   patht   linest   dep(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   writeconfig   s    
c         C  s  y | j  d d  } | j d  j d  d  } | \ } } | j d  j d  d  \ } } } }	 t t |   } t t |   } t t |	   }	 g  }
 x9 | D]1 } | j d  d  \ } } |
 j | | f  q Wt | | | | | |
 |	  SWn t k
 rd  SXd  S(   Nt   cri    i   i   (	   t	   readlinest   popt   splitt   Nonet   boolt   intR   R   t	   Exception(   t   clsR   R   t   valueR   R   R   R   R   R	   R
   t   linet	   depstring(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt
   readconfig    s    ' c         C  s   | o |  j  | j  k o |  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j | j k o |  j | j k S(   N(   R   R   R   R   R   R	   R
   (   R   t   other(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   matches2   s    (   t   __name__t
   __module__R   R   t   classmethodR!   R#   (    (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR      s   	
		t
   VirtualEnvc           B  sF  e  Z d d d   Z e d    Z e d    Z e d    Z e d    Z d   Z	 e
 d d  Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d d d  Z e d  Z e d  Z  e
 e d e
 e d  Z! RS(   c         C  s   | |  _  | |  _ d  S(   N(   t	   envconfigt   session(   R   R(   R)   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR   =   s    	c         C  s   |  j  j j j S(   N(   R(   t   configt   pluginmanagert   hook(   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR,   A   s    c         C  s
   |  j  j S(   s    Path to environment base dir. (   R(   t   envdir(   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR   E   s    c         C  s   |  j  j d  S(   Ns   .tox-config1(   R   R   (   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   path_configJ   s    c         C  s
   |  j  j S(   s    test environment name. (   R(   t   envname(   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   nameN   s    c         C  s   d |  j  S(   Ns   <VirtualEnv at %r>(   R   (   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   __repr__S   s    c         C  s   t  |  } t j j |  r" | St j j |  d d k rf | j |  } | j   rf t  |  Sn  | r~ |  j |  } n |  j |  } | d k r t
 j j d | f   n  t  |  S(   s   Return absolute path (str or localpath) for specified command name.

        - If it's a local path we will rewrite it as as a relative path.
        - If venv is True we will check if the command is coming from the venv
          or is whitelisted to come from external.
        i    t   .s   could not find executable %rN(   t   strt   osR   t   isabsR   R   t   checkt)   _venv_lookup_and_check_external_whitelistt   _normal_lookupR   t   toxt	   exceptiont   InvocationError(   R   R0   t   venvt   cwdR   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   getcommandpathV   s    	c         C  sM   |  j  |  } | d  k rI |  j |  } | d  k	 rI |  j |  qI n  | S(   N(   t   _venv_lookupR   R8   t    _check_external_allowed_and_warn(   R   R0   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR7   p   s    c         C  s"   t  j j j | d |  j j g S(   Nt   paths(   t   pyR   t   localt   sysfindR(   t	   envbindir(   R   R0   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR?   x   s    c         C  s   t  j j j |  S(   N(   RB   R   RC   RD   (   R   R0   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR8   {   s    c         C  s9   |  j  |  s5 |  j j j d | |  j j f  n  d  S(   Ns   test command found but not installed in testenv
  cmd: %s
  env: %s
Maybe you forgot to specify a dependency? See also the whitelist_externals envconfig setting.(   t   is_allowed_externalR)   t   reportt   warningR(   R-   (   R   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR@   ~   s    c         C  s   d g } t  j d k r{ | g  t j d j t j  D] } t j j |  ^ q5 7} t j j	 t j j t
 |    } n  x< |  j j D]. } x% | D] } | j | |  r t Sq Wq Wt S(   Nt    t   win32t   PATHEXT(   t   syst   platformR4   t   environR   t   pathsepR   t   normcaseRB   RC   R3   R(   t   whitelist_externalst   fnmatcht   Truet   False(   R   t   pt   tryaddt   xt   add(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyRF      s    	6'c         C  s   d t  |  j j  k S(   Nt   python3(   R3   R(   t
   basepython(   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt
   _ispython3   s    c         C  sW  t  j |  j  } |  j j rT | rT | j |  j    rT | j d |  j j  d S| d k ry | j
 d |  j j  n | j
 d |  j j  y& |  j j d | d |   t |  _ WnC t j j k
 r t j   d St j j k
 r t j   d SXy |  j j d | d |   Wn8 t j j k
 rRt j   d } d |  j j | f SXd S(	   s    return status string for updating actual venv to match configuration.
            if status string is empty, all is ok.
        t   reusingNt   createt   recreatet   actionR<   i   s!   could not install deps %s; v = %r(   R   R!   R.   R(   R^   R#   t   _getliveconfigt   infoR-   R   t   setactivityR,   t   tox_testenv_createRS   t   just_createdR9   R:   t   UnsupportedInterpreterRL   t   exc_infot   InterpreterNotFoundt   tox_testenv_install_depsR;   R
   (   R   R_   t   rconfigt   v(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   update   s*    c   
      C  s   |  j  j j } t |  } t j } |  j  j } |  j  j } |  j  j } g  } x< |  j	   D]. } | j
 }	 t |	  } | j | |	 f  q[ Wt | | | | | | |  S(   N(   R(   t   python_infot
   executablet	   getdigestR9   t   __version__R   R   R	   t   _getresolvedepsR0   R   R   (
   R   R   R   R   R   t   developR	   R
   R   t   raw_dep(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR`      s    		c         C  sv   g  } xi |  j  j D][ } | j d  k ra |  j j | j  } | | j k ra | j |  } qa n  | j |  q W| S(   N(	   R(   R
   t   indexserverR   R)   t   _resolve_pkgR0   t	   __class__R   (   R   t   lR   t   res(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyRp      s    c         C  s   |  j  j   S(   N(   R(   t   getsupportedinterpreter(   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyRx      s    c         C  s   t  j |  j j t j  S(   N(   t   ret   matchR(   RM   RL   (   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   matching_platform   s    c         C  s   |  j    j |  j  d  S(   N(   R`   R   R.   (   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   finish   s    c      
   C  s  | j  d  } | j  d  } |  j j t |  d g } |  j   } | j | d | d t d t d | } | j   } |  j j d d	 g } | j | d t d t d | }	 y t	 j
 |	 j    }
 Wn t k
 r g  }
 n Xd
 j  | d f  } xC t |
  D]1 } t j j |  j  |  } | j   rPqqWt Sx< | | f D]. } | j   rI| j   | j   k rIt SqIWt S(   Ns   setup.pys	   setup.cfgs   --nameR=   t   redirectt	   returnoutt   envs   -cs   import sys; print(sys.path)R2   s   egg-info(   R   R(   t	   envpythonR3   t   _getenvt   popenRT   RS   t   stript   astt   literal_evalt   SyntaxErrort   reversedRB   R   RC   R6   t   mtime(   R   t   setupdirR_   t   setup_pyt	   setup_cfgt   argsR   t   outputR0   t   outt   sys_patht   egg_info_fnamet   dt   egg_infot	   conf_file(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   _needs_reinstall   s.    !
$c         C  s   | d  k	 s t  t |  d t  rG | j d |  |  j   g  } n? |  j | |  sm | j d |  d  S| j d |  d g } | j j j	 r | d d j
 | j j j	  7} n  |  j d | g d	 | d
 | d  S(   NRd   s   develop-insts   develop-inst-noops   develop-inst-nodepss	   --no-depss   [%s]t   ,s   -et	   extraoptsR_   (   R   t   AssertionErrort   getattrRT   Rb   R|   R   R<   R(   t   extrasR   t   _install(   R   R   R_   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt
   developpkg   s    
		#c         C  s   | d  k	 s t  t |  d t  rG | j d |  |  j   g  } n | j d |  d d g } | j j j r | d d j	 | j j j  7} n  |  j
 | g d | d	 | d  S(
   NRd   t   insts   inst-nodepss   -Us	   --no-depss   [%s]R   R   R_   (   R   R   R   RT   Rb   R|   R<   R(   R   R   R   (   R   t	   sdistpathR_   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt
   installpkg  s    
	#c         C  s?   g  } | r | d | g 7} n  |  j  j r; | j d  n  | S(   Ns   -is   --pre(   R(   t   pip_preR   (   R   Rs   Rv   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   _installopts  s    c      	   C  s8  |  j  j } | j d  } | | | | d +d | k rb | j d  } t |  | | | d +n  x! d D] } t j j | d   qi Wd |  j  j k r d t j k r |  j	 j
 j d  t j j d  q n  t j } t j d	  t j  t _ |  j | d
 |  j  j j d | d |  j	 j
 j d k  | t _ d  S(   Ns
   {packages}i   s   {opts}t   PIP_RESPECT_VIRTUALENVt   PIP_REQUIRE_VIRTUALENVt   __PYVENV_LAUNCHER__t
   PYTHONPATHsk   Discarding $PYTHONPATH from environment, to override specify PYTHONPATH in 'passenv' in your configuration.t   utf8R=   R_   R}   i   (   R   R   R   (   R(   t   install_commandt   indext   listR4   RN   R   R   t   passenvR)   RG   RH   RL   t   stdoutt   codecst	   getwritert   _pcallR*   t	   toxinidirt	   verbosity(   R   t   packagesR_   t   optionst   argvt   iRW   t
   old_stdout(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   run_install_command  s&    
	!c   
      C  se  | s
 d  Si  } g  } x | D] } t  | t t j j f  rV t t |  d   } n  t  | t  sq t |   | j d  k r |  j	 j
 j d } n	 | j } | j | g   j | j  | | k r | j |  n  | j d  k s t  | j t  s t  q Wx\ | D]T } | | } |  j | j  }	 | rA|	 j |  n  |  j d | d |	 d |  q	Wd  S(   Nt   defaultR   R   R_   (   t
   isinstanceR3   RB   R   RC   R   R   R   Rs   R(   R*   t
   setdefaultR   R0   t   urlR   t   extendR   (
   R   R
   R   R_   R   Rv   R   t   ixserverR   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR   5  s,    	+
c         C  s   | rI i  } xI |  j  j D]) } | t j k r t j | | | <q q Wn t j j   } | j |  j  j  t |  j  | d <| S(   Nt   VIRTUAL_ENV(	   R(   R   R4   RN   t   copyRk   t   setenvR3   R   (   R   t   testcommandR   R/   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR   O  s    c         C  s8  |  j  j |  d  } | d |  _ |  j  j |  j j  |  j j j d d  |  j j } |  j d t	  } | j
 d d | j d   xt |  j j  D]\ } } d | d	 j g  | D] } t |  ^ q  f } | j
 d |  | d j d
  r:t	 }	 | d d
 k r | d =q@| d j d
  | d <n t }	 y/ |  j | d | d | d | d |	 d t	 Wq t j j k
 r}
 |  j j r|  j  j j d t |
  f  d |  _ q n  |  j  j j t |
   d |  _ |  j j s*Pq*q t k
 r)d |  _ |  j  j j |  j    q Xq WWd  QXd  S(   Nt   runtestsi    t   diri   R   s   PYTHONHASHSEED=%rt   PYTHONHASHSEEDs   commands[%s] | %st    t   -R=   R_   R}   t
   ignore_rets;   command failed but result from testenv is ignored
  cmd: %ss   ignored failed commands   commands failedt   keyboardinterrupt(   R)   t	   newactiont   statust   make_emptydirR(   t	   envtmpdirR   t	   changedirR   RS   Rb   t   gett	   enumeratet   commandsR   R3   t
   startswitht   lstripRT   R   R9   R:   R;   t   ignore_outcomeRG   RH   t   errort   ignore_errorst   KeyboardInterrupt(   R   R}   R_   R=   R   R   R   RW   t   messageR   t   err(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   testa  sH    	&
			c      
   C  s   x! d D] } t  j j | d   q W| j d d  |  j | d | |  | d <|  j d |  }	 t |  j j	  }
 t  j
 j |
 t  j d g  |	 d <} |  j j j d |  | j | d	 | d
 |	 d | d | S(   Nt   VIRTUALENV_PYTHONt   PYTHONDONTWRITEBYTECODER   i   i    R   t   PATHs   setting PATH=%sR=   R   R}   R   (   R   R   (   R4   RN   R   R   R   R>   R   R3   R(   RE   RO   R   R)   RG   t
   verbosity2R   (   R   R   R=   R<   R   R_   R}   R   R0   R   t   bindirRU   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR     s    'N(    ("   R$   R%   R   R   t   propertyR,   R   R.   R0   R1   RS   R>   R7   R?   R8   R@   RF   R[   Rk   R`   Rp   Rx   R{   R|   R   R   R   R   R   R   RT   R   R   R   (    (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyR'   <   s:   					
					
							/c         C  s6   t  j j |   }  |  j d d  s, d d S|  j   S(   Nt   filei   t   0i    (   RB   R   RC   R6   t   computehash(   R   (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyRn     s    c         C  s   |  j    } t j d d g } |  j j r: | j d  n  |  j j rV | j d  n  | j d t |  g  |  j	 j
 |  j  |  j j   } | j d d  | j |  j j  |  j | d t d	 | d
 | t S(   Ns   -mt
   virtualenvs   --system-site-packagess   --always-copys   --pythonR   i   R<   R_   R=   (   Rx   RL   Rm   R(   R   R   R	   R   R3   R)   R   R   t   dirpathR   t   basenameR   RT   RS   (   R<   R_   t   config_interpreterR   t   basepath(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyRc     s    c         C  sX   |  j    } | rT d j t t |   } | j d d |  |  j | d | n  t S(   Ns   , t   installdepss   %sR_   (   Rp   R   t   mapR3   Rb   R   RS   (   R<   R_   R
   t   depinfo(    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyRh     s    (   t
   __future__R    R   R4   RL   Ry   R   RB   R9   R*   R   R   R   t   objectR'   Rn   Rc   Rh   (    (    (    s%   /tmp/pip-build-UnxK1c/tox/tox/venv.pyt   <module>   s   0 d	