o g @sddlZddlZddlZddlZddlZddlmZmZee Z e dZ de fddZde fddZde fd d Zdeeefd d Zde fd dZde fddZde fddZdS)N)ListOptionalz8include-system-site-packages\s*=\s*(?Ptrue|false)returncCstjttdtjkS)znChecks if sys.base_prefix and sys.prefix match. This handles PEP 405 compliant virtual environments. base_prefix)sysprefixgetattrr r @/usr/lib/python3/dist-packages/pip/_internal/utils/virtualenv.py_running_under_venvsr cCs ttdS)zmChecks if sys.real_prefix is set. This handles virtual environments created with pypa's virtualenv. real_prefix)hasattrrr r r r !_running_under_regular_virtualenvs rcCs tptS)zBReturn True if we're running inside a virtualenv, False otherwise.)r rr r r r running_under_virtualenvs rcCsftjtjd}z t|dd}|WdWS1s!wYWdSty2YdSw)zReads {sys.prefix}/pyvenv.cfg and returns its contents as list of lines Returns None, if it could not read/access the file. z pyvenv.cfgzutf-8)encodingN) ospathjoinrropenread splitlinesOSError)pyvenv_cfg_filefr r r _get_pyvenv_cfg_lines$s ( rcCsPt}|durtddS|D]}t|}|dur%|ddkr%dSqdS)aZCheck `{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. NzCould not access 'pyvenv.cfg' despite a virtual environment being active. Assuming global site-packages is not accessible in this environment.TvaluefalseF)rloggerwarning#_INCLUDE_SYSTEM_SITE_PACKAGES_REGEXmatchgroup) cfg_linesliner r r r _no_global_under_venv3s  r$cCs0tjtjtj}tj|d}tj|S)zCheck 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. zno-global-site-packages.txt)rrdirnameabspathsite__file__rexists) site_mod_dirno_global_site_packages_filer r r #_no_global_under_regular_virtualenvPs  r,cCstrtStr tSdS)zHReturns a boolean, whether running in venv with no system site-packages.F)r r$rr,r r r r virtualenv_no_global^s r-)loggingrrer'rtypingrr getLogger__name__rcompilerboolr rrstrrr$r,r-r r r r s"