ó
Ð²Ebc           @@  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 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-UPPWic/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-UPPWic/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-UPPWic/pip/pip/_internal/utils/virtualenv.pyt   running_under_virtualenv(   s    c          C@  sc   t  j j t j d ƒ }  y2 t j |  d d ƒ } | j ƒ  j ƒ  SWd QXWn t	 k
 r^ 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.cfgt   encodings   utf-8N(   t   ost   patht   joinR   R   t   iot   opent   readt
   splitlinest   IOErrort   None(   t   pyvenv_cfg_filet   f(    (    s;   /tmp/pip-build-UPPWic/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-UPPWic/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-UPPWic/pip/pip/_internal/utils/virtualenv.pyt#   _no_global_under_regular_virtualenv]   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-UPPWic/pip/pip/_internal/utils/virtualenv.pyt   virtualenv_no_globalk   s
    		(   t
   __future__R    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-UPPWic/pip/pip/_internal/utils/virtualenv.pyt   <module>   s&   				
				