ó
'^c           @@  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 m Z e r{ d  d l	 m
 Z
 m Z n  e j e  Z e j d  Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d S(   i    (   t   absolute_importN(   t   MYPY_CHECK_RUNNING(   t   Listt   Optionals8   include-system-site-packages\s*=\s*(?P<value>true|false)c           C@  s   t  j t t  d t  j  k S(   sn   Checks if sys.base_prefix and sys.prefix match.

    This handles PEP 405 compliant virtual environments.
    t   base_prefix(   t   syst   prefixt   getattr(    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/virtualenv.pyt   _running_under_venv   s    c           C@  s   t  t d  S(   sm   Checks if sys.real_prefix is set.

    This handles virtual environments created with pypa's virtualenv.
    t   real_prefix(   t   hasattrR   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/virtualenv.pyt!   _running_under_regular_virtualenv   s    c           C@  s   t    p t   S(   sG   Return True if we're running inside a virtualenv, False otherwise.
    (   R   R   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/virtualenv.pyt   running_under_virtualenv'   s    c          C@  sZ   t  j j t j d  }  y) t |    } | j   j   SWd QXWn t k
 rU d SXd S(   s   Reads {sys.prefix}/pyvenv.cfg and returns its contents as list of lines

    Returns None, if it could not read/access the file.
    s
   pyvenv.cfgN(
   t   ost   patht   joinR   R   t   opent   readt
   splitlinest   IOErrort   None(   t   pyvenv_cfg_filet   f(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/virtualenv.pyt   _get_pyvenv_cfg_lines.   s    c          C@  so   t    }  |  d k r& t j d  t SxB |  D]: } t j |  } | d k	 r- | j d  d k r- t Sq- Wt S(   sZ  Check `{sys.prefix}/pyvenv.cfg` for system site-packages inclusion

    PEP 405 specifies that when system site-packages are not supposed to be
    visible from a virtual environment, `pyvenv.cfg` must contain the following
    line:

        include-system-site-packages = false

    Additionally, log a warning if accessing the file fails.
    s   Could not access 'pyvenv.cfg' despite a virtual environment being active. Assuming global site-packages is not accessible in this environment.t   valuet   falseN(	   R   R   t   loggert   warningt   Truet#   _INCLUDE_SYSTEM_SITE_PACKAGES_REGEXt   matcht   groupt   False(   t	   cfg_linest   lineR   (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/virtualenv.pyt   _no_global_under_venv<   s    	!c          C@  sF   t  j j t  j j t j   }  t  j j |  d  } t  j j |  S(   sĹ   Check if "no-global-site-packages.txt" exists beside site.py

    This mirrors logic in pypa/virtualenv for determining whether system
    site-packages are visible in the virtual environment.
    s   no-global-site-packages.txt(   R   R   t   dirnamet   abspatht   sitet   __file__R   t   exists(   t   site_mod_dirt   no_global_site_packages_file(    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/virtualenv.pyt#   _no_global_under_regular_virtualenvZ   s    !	c           C@  s$   t    r t   St   r  t   St S(   sM   Returns a boolean, whether running in venv with no system site-packages.
    (   R   R+   R   R#   R    (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/virtualenv.pyt   virtualenv_no_globalh   s
    		(   t
   __future__R    t   loggingR   t   reR&   R   t   pip._internal.utils.typingR   t   typingR   R   t	   getLoggert   __name__R   t   compileR   R   R   R   R   R#   R+   R,   (    (    (    s;   /tmp/pip-build-eiI0Wo/pip/pip/_internal/utils/virtualenv.pyt   <module>   s$   				
				